Bouncing Triangle

16 views
Skip to first unread message

Yossi Kadosh

unread,
Apr 16, 2010, 4:32:56 AM4/16/10
to CellularBasicPro
Reported by j...@privat.dk, Apr 07, 2010
Great program

I found it a couple of days ago, and tried it. It works beautifully,
and
fast too.
I think you should create a tab, where users could share their
programs.

I would like to be the first with this one. It shows a color changing
triangle that bounces around on the screen. You stop it by pressing
any
key on the keypad on your phone.
The subroutine ft at the end of the program is actually the function
sgn,
which seems to be missing.

Sub main
Clearcolor(0,0,0):CLS
p2=pi*2
for n=1 to 3
rgb(n)=rnd
rgbt(n)=rnd/25
x(n)=width*rnd
y(n)=height*rnd
dx(n)=(rnd*3+1)*ft(rnd-0.5)
dy(n)=(rnd*3+1)*ft(rnd-0.5)
next n
do
cls
for n=1 to 3
t=x(n)+dx(n)
if t<0 or t>width then
dx(n)=ft(-dx(n))*(3*rnd+1)
end if
t=y(n)+dy(n)
if t<0 or t>height then
dy(n)=ft(-dy(n))*(3*rnd+1)
end if
x(n)=x(n)+dx(n)
y(n)=y(n)+dy(n)
rgb(n)=rgb(n)+rgbt(n)
if rgb(n)>p2 then
rgb(n)=rgb(n)-p2
end if
next n
r2=(sin(rgb(1))+1)*127
g2=(sin(rgb(2))+1)*127
b2=(sin(rgb(3))+1)*127
Color(r2,g2,b2)
fillon
triangle(x(1),y(1),x(2),y(2),x(3),y(3))
updatescreen
loop while getkey=-1
end sub
sub ft(a)
if a=0 then
ft=0:break:end if
ft=a/abs(a)
end sub


--
Subscription settings: http://groups.google.com/group/cellularbasicpro/subscribe?hl=en
Reply all
Reply to author
Forward
0 new messages