8000 SAMPLES: updates from mga · chrisws/smallbasic.github.io@b1f7060 · GitHub
[go: up one dir, main page]

Skip to content

Commit b1f7060

Browse files
committed
SAMPLES: updates from mga
1 parent f066536 commit b1f7060

File tree

2 files changed

+56
-88
lines changed

2 files changed

+56
-88
lines changed

samples/node/1396.bas

Lines changed: 33 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,36 @@
1+
'Persian Carpet v2.bas for SmallBASIC 0.12.9 (B+=MGA)
2+
'modified from copy from Retrogamecoding link 2016-02-09
3+
' 2017-09-23 mod for brighter colors and centered
4+
' alas, some blank screens but much brighter!
15

2-
'Persian Carpet.bas for SmallBASIC 0.12.2 [B+=MGA] 2016-02-08
3-
'modified from copy from Retrogamecoding link 2016-02-08
4-
'modified some more for Code Library and On-line Samples
5-
REM BASIC Code: Persian Carpet Designs
6+
' 2017-09-24 eliminate radial symmetry and most blank screens
7+
8+
REM BASIC Code: Persian Carpet Designs
69
REM A modification of original concept from Anne Burns
7-
REM Try colorborder=15, a=3
8-
colorborder=0:a=1
10+
11+
colorborder = 0 : a = 1
12+
xo = (xmax - 512) / 2 : yo = (ymax - 512) / 2
913
while 1
10-
'cls
11-
'INPUT "Enter the border color, 1 - 15 (try 15): ", colorborder
12-
'INPUT "Enter a value (try 3) > ", a
1314
CLS
14-
lft = 1
15-
'rght=1025 'not symmetric
16-
rght = 513
17-
'rght=401
18-
'rght=257
19-
'rght=129
20-
'rght=65
21-
top = 1
22-
'bot= 1025 'not symmetric
23-
bot=513
24-
'bot = 401
25-
'bot= 257
26-
'bot=129
27-
'bot=65
28-
LINE lft,top,rght,top,colorborder
29-
LINE lft,bot,rght,bot,colorborder
30-
LINE lft,top,lft,bot,colorborder
31-
LINE rght,top,rght,bot,colorborder
15+
lft = 1 + xo : rght = 513 + xo : top = 1 + yo: bot = 513 + yo
16+
cb2 = rnd * 16 \ 1
17+
LINE lft, top, rght, top, cb2
18+
LINE lft, bot, rght, bot, cb2
19+
LINE lft, top, lft, bot, colorborder
20+
LINE rght, top, rght, bot, colorborder
3221
DetermineColor lft, rght, top, bot, a
33-
'next line no good for on-line samples
34-
'at 50,600:? "colorboarder = ";colorborder;" a = ";a
22+
at 10, 10 : ? "colorboarder = ";colorborder;" cb 2 = ";cb2;" a = ";a
3523
showpage
36-
delay 1000
37-
a=a+1
38-
if a>=16 then a=1:colorborder+=1
39-
if colorborder>=16 then colorborder=0
40-
wEND
24+
pause
25+
a = a + 1
26+
if a >= 16 then a = 1 : colorborder += 1
27+
if colorborder >= 16 then colorborder = 0
28+
wend
4129

42-
REM Determine the color based on function f
30+
rem Determine the color based on function f
4331
sub DetermineColor(lft, rght, top, bot, a)
44-
local c,middlerow,middlecol
45-
IF (lft < rght - 1) THEN
32+
local c, middlerow, middlecol
33+
IF (lft < rght - 2) THEN
4634
c = f(lft, rght, top, bot, a)
4735
middlecol = int((lft + rght) / 2)
4836
middlerow = int((top + bot) / 2)
@@ -54,14 +42,13 @@ sub DetermineColor(lft, rght, top, bot, a)
5442
DetermineColor middlecol, rght, middlerow, bot, a
5543
else
5644
exit
57-
END IF
58-
END
45+
end if
46+
end
5947

60-
REM When b=4, this function takes an average.
61-
FUNC f(lft, rght, top, bot, a)
62-
local p,b
63-
p = POINT(lft, top) + POINT(rght, top) + POINT(lft, bot) + POINT(rght, bot)
48+
func f(lft, rght, top, bot, a)
49+
local p, b
50+
p = point(lft, top) + POINT(rght, top) + POINT(lft, bot) + POINT(rght, bot)
6451
'Try values of b = 4 or b = 7
65-
b=7
66-
f = (p /b + a) MOD 16
67-
END
52+
b = 60
53+
f = int(p / b + a) mod 9 + 7
54+
end

samples/node/1531.bas

Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
' Another look at Trig functions.bas SmallBASIC 0.12.2 [B+=MGA] 2016-05-01
33
' inspired by PeterMaria's simple code for Atan2 on Aurels' forum BasicPro
4+
' 2017-09-23 Modified to run again on Android
45

56
' Here is another effort in a continuing series to demystify Trig functions:
67

@@ -10,56 +11,42 @@
1011
' angles to the horizontal line, lengths of the sides and hypotenuse of the right
1112
' and the COS, SIN and TAN ratios
1213

13-
sub drawXit
14-
local c, i
15-
'for mouse clicks
16-
'mx > mxborder=xmax-60
17-
'my < myborder=30
18-
c = rgb(190, 0, 0)
19-
rect xmax - 60, 10 step 51, 21, 0 filled
20-
rect xmax - 60, 10 step 50, 20, c filled
21-
for i = 0 to 2
22-
line xmax - 40 + i, 15, xmax - 33 + i, 25, 15
23-
line xmax - 40 + i, 25, xmax - 33 + i, 15, 15
24-
next i
25-
end
26-
2714
sub ThickArc(xCenter, yCenter, arcRadius, dAngleStart, dAngleEnd, rThick)
28-
local rAngle, rAngleStart, rAngleEnd, x1, y1, Stepper
15+
local rAngle, rAngleStart, rAngleEnd, x1, y1, Stepper
2916
'draws an Arc with center at xCenter, yCenter, radius from center is arcRadius
30-
17+
3118
'for SmallBASIC angle 0 degrees is due East and angle increases clockwise towards South
32-
33-
'THIS SUB IS SETUP TO DRAW AN ARC IN CLOCKWISE DIRECTION
34-
19+
20+
'THIS SUB IS SETUP TO DRAW AN ARC IN CLOCKWISE DIRECTION
21+
3522
'dAngleStart is where to start Angle in degrees
3623
' so make the dAngleStart the first ray clockwise from 0 degrees that starts angle drawing clockwise
37-
24+
3825
'dAngleEnd is where the arc ends going clockwise with positive degrees
3926
' so if the arc end goes past 0 degrees clockwise from dAngleStart
4027
' express the end angle as 360 + angle
41-
28+
4229
'rThick is the radius of the many,many tiny circles this will draw to make the arc thick
4330
' so if rThick = 2 the circles will have a radius of 2 pixels and arc will be 4 pixels thick
4431
if arcRadius < 1 then pset xCenter, yCenter : exit func
4532
rAngleStart = rad(dAngleStart) : rAngleEnd = rad(dAngleEnd)
4633
if int(rthick) = 0 then Stepper = 1 / (arcRadius*pi) else Stepper = rThick / (arcRadius * pi / 2)
4734
for rAngle = rAngleStart to rAngleEnd step Stepper
4835
x1 = arcRadius * cos(rAngle) : y1 = arcRadius * sin(rAngle)
49-
if int(rThick) < 1 then
50-
pset xCenter + x1, yCenter + y1
51-
else
36+
if int(rThick) < 1 then
37+
pset xCenter + x1, yCenter + y1
38+
else
5239
circle xCenter + x1, yCenter + y1, rThick filled
5340
fi
5441
next
5542
end
5643

5744
sub ThickLine(x1, y1, x2, y2, rThick)
5845
local length, stepx, stepy, dx, dy, i
59-
46+
6047
'x1,y1 is one endpoint of line
6148
'x2,y2 is the other endpoint of the line
62 10000 -
'rThick is the radius of the tiny circles that will be drawn
49+
'rThick is the radius of the tiny circles that will be drawn
6350
' from one end point to the other to create the thick line
6451
'Yes, the line will then extend beyond the endpoints with circular ends.
6552

@@ -74,7 +61,7 @@ sub ThickLine(x1, y1, x2, y2, rThick)
7461
end if
7562
end
7663

77-
'============================== Main
64+
'============================== Main
7865
const thick = 2
7966
const arc_radius = 100
8067
const hor_color = rgb(30,30,30)
@@ -86,38 +73,32 @@ const white = rgb(255,255,255)
8673
cx = xmax / 2 : cy = ymax / 2
8774

8875
while 1
89-
if asc(inkey) = 27 then end else pen on 'did user press esc to quit?
9076
cls
91-
'draw eXit sign
92-
drawXit
93-
77+
9478
'draw horizontal through center of screen
9579
line 0, cy, xmax, cy, hor_color
96-
80+
9781
'get mouse
9882
mx = pen(4) : my = pen(5) 'get mouse location
99-
100-
'check if eXit was clicked, if so then end
101-
if mx > xmax - 60 and my < 30 and pen(3) then end
102-
103-
'draw our Color Coded Trig Triangle
83+
84+
'draw our Color Coded Trig Triangle
10485
color cos_color
10586
ThickLine cx, cy, mx, cy, thick
10687
color sin_color
10788
ThickLine mx, cy, mx, my, thick
10889
color hyp_color
10990
ThickLine cx, cy, mx, my, thick
110-
91+
11192
stepx = abs(cx - mx) : stepy = abs(cy - my)
11293
hyp = ( (stepx ^ 2 + stepy ^ 2) ^.5 )\1
113-
94+
11495
'to draw angle need to do some math
11596
'dAng = mouse angle to 0 degrees due East
11697
' other Angles: StartA, EndA and reportA are for the Trig Ratios of triangle
11798
dAng = ( deg(atan( (my - cy) / (mx - cx) ) )+.5 ) \ 1
11899
if mx < cx then dAng = dAng + 180
119100
if my < cy and mx > cx then dAng = dAng + 360
120-
if dAng <= 90 then
101+
if dAng <= 90 then
121102
startA = 0 : endA = dAng : reportA = dAng
122103
elif dAng <= 180
123104
startA = dAng : endA = 180 : reportA = 90 - (dAng - 90)
@@ -128,7 +109,7 @@ while 1
128109
fi
129110
color ang_color
130111
ThickArc cx, cy, arc_radius, startA, endA, thick
131-
112+
132113
'report all numbers color coded
133114
color ang_color
134115
locate 0, 0 : ? "yellow Angle (degrees) ~ "; reportA
@@ -167,5 +148,5 @@ while 1
167148
fi
168149
showpage
169150
delay 100
170-
pen off
171151
wend
152+

0 commit comments

Comments
 (0)
0