Bouncing blue electric lines (iPad,iPhone)
Posted: Fri Feb 20, 2015 2:08 pm
This is an adaptation of an old Qbasic program. Lines bounce against the walls, flashing to show a forcefield effect. Touch screen to generate new number of lines and speed. .
This program sometimes crashes smart basic when starting. I think it's due to the NOTES command trying to play too many notes at once? It doesn't crash when it is commented out. Touch screen long enough and it will happen. Any ideas?
- Dav
EDIT: There are now two versions, the second one is a new version that adds a spinning background using sprite that creates a better effect.
Original version...
Enhanced version with spinning background..
This program sometimes crashes smart basic when starting. I think it's due to the NOTES command trying to play too many notes at once? It doesn't crash when it is commented out. Touch screen long enough and it will happen. Any ideas?
- Dav
EDIT: There are now two versions, the second one is a new version that adds a spinning background using sprite that creates a better effect.
Original version...
Code: Select all
'Bouncing blue electric lines.
'Adapted from old Qbasic code
graphics
option base 1
draw size 15
main:
lines = 3+rnd(17) 'random # of lines
speed = 10+rnd(30) 'random speed
dim x(lines), y(lines)
dim xd(lines), yd(lines)
dim xs(lines), ys(lines)
sw = screen_width() ! sh = screen_height()
do
refresh off
graphics clear 0,0,64/255
draw color .5,.5,1
draw text "touch screen to respawn" at s,20
s=s+2 ! if s > sw then s=-270
for t = 1 to lines
'right side
if x(t) > sw then
xd(t)=0 ! xs(t)=rnd(speed)
click(sw,0,sw,sh,sw,y(t))
end if
'left side
if x(t) < 1 then
xd(t)= -1 ! xs(t)=rnd(speed)
click(0,0,0,sh,0,y(t))
end if
'bottom
if y(t) > sh then
yd(t)= 0 ! ys(t)=rnd(speed)
click(0,sh,sw,sh,x(t),sh)
end if
'top
if y(t) < 1 then
yd(t) = -1 ! ys(t)=rnd(speed)
click(0,0,sw,0,x(t),0)
end if
if yd(t) then
y(t)=y(t)+ys(t)
else
y(t)=y(t)-ys(t)
end if
if xd(t) then
x(t)=x(t)+xs(t)
else
x(t)=x(t)-xs(t)
end if
next t
c=100-(lines*1.5)
for i = 1 to lines-1
draw color 0,0,c/255
draw line x(i), y(i) to x(i + 1), y(i + 1)
draw color c/255,.1,0
draw circle x(i),y(i) size 10
c=c+12
next i
'connect to 1st line
draw color 0,0,c/255
draw line x(lines), y(lines) to x(1), y(1)
draw color c/255,.1,0
draw circle x(lines),y(lines) size 10
refresh on
if screen_width()<>sw then
sw = screen_width()
sh = screen_height()
end if
if touch_x(0) <>-1 then main
until 0
def click(x1,y1,x2,y2,cx,cy)
draw color 0,0,.4
draw line x1,y1 to x2,y2
draw color 1,1,1
draw circle cx,cy size 7
Notes stop
notes set "112:tc9"
notes play
end def
Code: Select all
'Bluelines v2 by Dav
'Adds spinning background sprite
graphics
option base 1
option sprite pos central
sw=screen_width() ! sh=screen_height()
'draw background
refresh off
draw size 2
for a = 1 to 1975 step 10
x2= cos(a*360) * (sh/2)
y2= sin(a*360) * (sh/2)
r=rnd(255) ! g=rnd(255) ! b=rnd(255)
draw color r/255,g/255,b/255
draw line sw/2,sh/2 to sw/2+x2,sh/2+y2
next a
'grab as sprite
sprite "s" scan 0,0,sw,sh
sprite "s" show
sprite "s" at -2000,-2000
graphics clear 0,0,64/255
refresh on
draw size 15
'----
main:
'----
a=rnd(50000)+2000 'random zoom value
lines = 5+rnd(10) 'random # of lines
speed = 10+rnd(20) 'random speed
dim x(lines), y(lines)
dim xd(lines), yd(lines)
dim xs(lines), ys(lines)
do
refresh off
graphics clear 0,0,64/255 'blu haze
'show background sprite
sprite "s" alpha 12/100
sprite "s" at sw/2,sh/2 scale a/1000 angle a/100
a=a+1
draw color .5,.5,1
draw text "touch screen to respawn" at s,20
s=s+2 ! if s > sw then s=-270
for t = 1 to lines
'right side
if x(t) > sw then
xd(t)=0 ! xs(t)=rnd(speed)
click(sw,0,sw,sh,sw,y(t))
end if
'left side
if x(t) < 1 then
xd(t)= -1 ! xs(t)=rnd(speed)
click(0,0,0,sh,0,y(t))
end if
'bottom
if y(t) > sh then
yd(t)= 0 ! ys(t)=rnd(speed)
click(0,sh,sw,sh,x(t),sh)
end if
'top
if y(t) < 1 then
yd(t) = -1 ! ys(t)=rnd(speed)
click(0,0,sw,0,x(t),0)
end if
if yd(t) then
y(t)=y(t)+ys(t)
else
y(t)=y(t)-ys(t)
end if
if xd(t) then
x(t)=x(t)+xs(t)
else
x(t)=x(t)-xs(t)
end if
next t
c=100-(lines*1.5)
for i = 1 to lines-1
draw color 0,0,c/255
draw line x(i), y(i) to x(i + 1), y(i + 1)
draw color c/255,.1,0
draw circle x(i),y(i) size 10
c=c+12
next i
'connect to 1st line
draw color 0,0,c/255
draw line x(lines), y(lines) to x(1), y(1)
draw color c/255,.1,0
draw circle x(lines),y(lines) size 10
refresh on
if screen_width()<>sw then
sw = screen_width()
sh = screen_height()
end if
if touch_x(0) <>-1 then main
until 0
def click(x1,y1,x2,y2,cx,cy)
draw color 0,0,.4
draw line x1,y1 to x2,y2
draw color 1,1,1
draw circle cx,cy size 7
notes stop
notes set "112:tc9"
notes play
end def