Dark Bit Factory & Gravity

PROGRAMMING => Other languages => Yabasic => Topic started by: bikemadness on July 29, 2007

Title: LOTTO!
Post by: bikemadness on July 29, 2007
I have tried random number picking once before, but I've come up with something else.
A bit more realistic to what I really wanted.

X to activate

Code: [Select]
open window 640,512
br=15
grd=450
ball=40
dim bx(ball),by(ball),drop(ball)
dim bm(ball),dir(ball),sp(ball)
for a=1 to ball
dir(a)=int(ran(2))
if dir(a)=0 sp(a)=-4
if dir(a)=1 sp(a)=4
bx(a)=int(ran(600))+20
by(a)=br
' drop(a)=ran(.1)+.1
bm(a)=0
next a
repeat
setdispbuf vm
vm=1-vm
setdrawbuf vm
clear window
c=peek("port1")   
setrgb 1,200,200,0
fill rectangle 0,0 to 640,512
setrgb 1,0,0,0
line 0,grd to 300,grd
line 0,grd+1 to 300,grd+1
line 340,grd to 640,grd
line 340,grd+1 to 640,grd+1
for a=1 to ball
if and(c,16384)>0 then
dir(a)=int(ran(2))
if dir(a)=0 sp(a)=-4
if dir(a)=1 sp(a)=4
bx(a)=int(ran(600))+20
by(a)=br
drop(a)=ran(.1)+.1
bm(a)=0
hold=0
endif
bx(a)=bx(a)+sp(a)
if bx(a)<15 or bx(a)>625 sp(a)=-sp(a)
bm(a)=bm(a)+drop(a)
by(a)=by(a)+bm(a)
if bx(a)>0 and bx(a)<300 and by(a)>grd-br then
bm(a)=-bm(a)*.95
by(a)=grd-br
endif
if bx(a)>340 and bx(a)<640 and by(a)>grd-br then
bm(a)=-bm(a)*.95
by(a)=grd-br
endif
if by(a)>480 then
      hold=hold+1
      bx(a)=hold*(br*2)-br
      by(a)=480
      sp(a)=0
      bm(a)=0
    endif
setrgb 1,0,250,0
fill circle bx(a),by(a),br
setrgb 1,0,0,0
circle bx(a),by(a),br
text bx(a)-10,by(a)+2,str$(a)
next a
until (1=0)

The holding pattern doesn't quite work.

A curious thing I've noticed.
I know that text and rectangles are drawn faster than circles.
But when I put text inside my circles, it goes back to full speed.



Title: Re: LOTTO!
Post by: Jim on July 29, 2007
I like that idea - it's like a real lottery machine :)

Jim
Title: Re: LOTTO!
Post by: Clanky on July 30, 2007
Nice piece of code. I tried a lotto sim, but not like yours! lol. Mine was a game... but it wasn't as styalised as yours.
Title: Re: LOTTO!
Post by: rain_storm on August 07, 2007
Thats news to me i never heard that trick to speed up circles :P nice find man