8000 SAMPLES: added 2 new samples · chrisws/smallbasic.github.io@1ef249c · GitHub
[go: up one dir, main page]

Skip to content {"props":{"docsUrl":"https://docs.github.com/get-started/accessibility/keyboard-shortcuts"}}

Commit 1ef249c

Browse files
committed
SAMPLES: added 2 new samples
1 parent 84b4647 commit 1ef249c

File tree

4 files changed

+209
-1
lines changed

4 files changed

+209
-1
lines changed

samples/graphics 1/plasma.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
cls
3-
const PI= 3.141593
3+
'const PI= 3.141593
44

55
dim cols(2,255)
66

samples/index.bas

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ color 15,0
1616
print cat(3) + "SmallBASIC featured samples" + cat(0)
1717

1818
dim frm
19+
frm.inputs << bn("5000", "[Android] Stopit")
20+
frm.inputs << bn("5001", "[Android] Silly words")
1921
frm.inputs << bn("1407", "3d rotating cube with message [harixxx]") 'nice one harixxx!
2022
frm.inputs << bn("1613", "NIM [jsalai]")
2123
frm.inputs << bn("1409", "Mastermind [MGA & Johnno]")

samples/node/5000.bas

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
option predef load modules
2+
import android
3+
4+
dim lights(11)
5+
6+
sub init
7+
local i
8+
for i = 0 to len(lights) - 1
9+
lights[i] = false
10+
next i
11+
end
12+
13+
func orange(vr)
14+
return rgb(0x9f, 128 - 5 * vr, 0)
15+
end
16+
17+
func green(vr)
18+
return rgb(0, 128 - 4 * vr, 0)
19+
end
20+
21+
func blue(vr)
22+
return rgb(0, 0, 255 - 5 * vr)
23+
end
24+
25+
sub ball(x, y, size, lit, fn)
26+
local r, c, vr
27+
local nstep = size / 25
28+
29+
for r = size to 1 step - nstep
30+
vr = r * 25 / size
31+
if (lit) then
32+
c = call(fn, vr)
33+
else
34+
c = 255 - 4 * vr
35+
c = rgb(c, c, c)
36+
endif
37+
circle x, y, r, 1, c filled
38+
next
39+
end
40+
41+
' outer : orange
42+
' inner : green
43+
' center: blue
44+
sub show
45+
local x = xmax / 2
46+
local y = ymax / 2
47+
local s1 = xmax / 15
48+
local s2 = s1 * .7
49+
local s3 = s2 * .7
50+
local i
51+
52+
ball(x, y, s1, lights[5], @blue)
53+
x -= s1 * 2
54+
ball(x, y, s2, lights[4], @green)
55+
x -= s2 * 2
56+
for i = 3 to 0 step - 1
57+
ball(x, y, s3, lights[i], @orange)
58+
x -= s1 * 1.1
59+
next i
60+
61+
x = xmax / 2 + s1 * 2
62+
ball(x, y, s2, lights[6], @green)
63+
x += s2 * 2
64+
for i = 7 to 10
65+
ball(x, y, s3, lights[i], @orange)
66+
x += s1 * 1.1
67+
next i
68+
end
69+
70+
sub go()
71+
local i = 0
72+
local j = 0
73+
74+
lights[j] = true
75+
76+
android.sensor_on(0)
77+
android.tts_pitch(0.8)
78+
score=0
79+
while 1
80+
s=android.sensor
81+
m= sqr(s.x*s.x + s.y*s.y + s.z*s.z)
82+
if m >9.8 then
83+
if j == 6 then
84+
android.tts_pitch(2)
85+
android.speak("you killed it")
86+
score +=10
87+
android.tts_pitch(2.3)
88+
android.speak(score + " points")
89+
else if j== 5 or j== 7 then
90+
android.tts_pitch(.4)
91+
android.speak("that, wasnt so bad")
92+
else
93+
android.tts_pitch(.8)
94+
android.speak("pull your self together laddie")
95+
endif
96+
pause 2.5
97+
endif
98+
cls
99+
show()
100+
showpage
101+
102+
lights[j] = false
103+
j = (j + 1) mod 11
104+
lights[j] = true
105+
wend
106+
end
107+
108+
init()
109+
go()

samples/node/5001.bas

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
option predef load modules
2+
import android
3+
w = window():w.setFont(2,"em",true,false)
4+
const pop=35
5+
const c1=97
6+
const c2=122
7+
const xm = xmax - txtw("z")*2
8+
const ym = ymax - txth("z")*2
9+
const vowel=["a","e","i","o","u"]
10+
const words =["anyway", "well", "what", "hello", "hmmmm", "today"]
11+
def mkatr = 10 + int(rnd * 140)
12+
func mk_char()
13+
local r
14+
if (rnd < .2) then
15+
r.ch = vowel[rnd*len(vowel)]
16+
else
17+
r.ch = chr(c1 + ((rnd*1000) % (c2-c1)))
18+
endif
19+
r.x = int(rnd * xmax)
20+
r.y = int(rnd * ymax)
21+
r.c = 1 + int(rnd * 14)
22+
r.atr = mkatr()
23+
mk_char=r
24+
end
25+
sub create(byref d, size)
26+
local i
27+
for i = 0 to size
28+
d[i] = mk_char()
29+
next i
30+
end
31+
func update(byref d, size, xo, yo)
32+
local i,x_chg,y_chg
33+
local rtn=""
34+
for i = 0 to size
35+
if (xo != 0) then d[i].x += (xo * d[i].atr)
36+
if (yo != 0) then d[i].y += (yo * d[i].atr)
37+
x_chg = true: y_chg = true
38+
if d[i].x < 0 then
39+
d[i].x = 0
40+
elif d[i].x > xm then
41+
d[i].x = xm
42+
else
43+
x_chg = false
44+
endif
45+
if d[i].y < 0 then
46+
d[i].y = 0
47+
elif d[i].y > ym then
48+
d[i].y = ym
49+
else
50+
y_chg = false
51+
endif
52+
if (x_chg or y_chg) then
53+
d[i].atr = mkatr()
54+
endif
55+
if ((d[i].y == 0 or d[i].y == ym) and d[i].x > 5) then rtn += d[i].ch
56+
next i
57+
update = rtn
58+
end
59+
sub show(byref d, size)
60+
local i
61+
for i = 0 to size
62+
at d[i].x, d[i].y
63+
color d[i].c
64+
print d[i].ch
65+
next i
66+
end
67+
android.sensor_on(0)
68+
randomize timer:cls
69+
dim d(pop)
70+
create(d, pop)
71+
show(d, pop)
72+
spk = ""
73+
android.tts_pitch(2)
74+
android.speak("tilt the screen")
75+
android.tts_pitch(.1)
76+
android.speak("DO It !")
77+
landscape=xmax>ymax
78+
while 1
79+
s=android.sensor
80+
xo = iff(s.x < -1 or s.x > 1, s.x, 0)
81+
yo = iff(s.y < -1 or s.y > 1, s.y, 0)
82+
if (landscape) then swap xo,yo
83+
if (xo != 0 or yo != 0) then
84+
nspk = update(d, pop, xo, yo)
85+
if (nspk != spk) then
86+
spk = nspk
87+
android.tts_pitch(.5 + 1 * rnd)
88+
if (rnd < .2) then
89+
android.speak(words[rnd*len(words)])
90+
else
91+
android.speak(spk)
92+
endif
93+
endif
94+
endif
95+
cls:show(d, pop)
96+
showpage:delay 50
97+
wend

0 commit comments

Comments
 (0)
0