IonicWind Software

Announcements => User Offerings => Topic started by: zaphod on March 27, 2011, 07:26:59 AM

Title: just another binomial distribution
Post by: zaphod on March 27, 2011, 07:26:59 AM
Hello all,

This is my attempt with the binomial distribution.
161 lines of code for IWB 1.8.
Windows versions.
Source code and image (needed for compile) and exe attached.



'//////////////////
'Binomial Distribution
'by zaphod
'iwb 1.8
'03/27/2011
'//////////////////
enum gadgets
BUTTON_1
timer_1
button_2
edit_1
ENDENUM
'
int plot
plot=loadimage(getstartpath+"plot.bmp",@IMGBITMAP )
'
DIALOG d1
CREATEDIALOG d1,0,0,305,330,@minbox|@sysmenu|@CAPTION,0,"Binomial Distribution",&d1_handler
CONTROL d1,@BUTTON,"GO",30,4,50,20,0x50000000,BUTTON_1
CONTROL d1,@BUTTON,"NEW",100,4,50,20,0x50000000,BUTTON_2
CONTROL d1,@EDIT,"20",173,3,50,20,0x50802000,edit_1
'
int ballx,bally,ox,oy,balls
int bino[8]
ballx=133:bally=30
'
SHOWDIALOG d1
'
WAITUNTIL d1=0
'
DELETEIMAGE plot,@IMGBITMAP
'
END
'
SUB d1_handler
int i
'
SELECT @MESSAGE
CASE @IDCONTROL
SELECT @CONTROLID
CASE BUTTON_1
IF @NOTIFYCODE = 0
/*button clicked*/
if GETCONTROLTEXT(d1,button_1)="GO"
setcontroltext d1,button_1,"STOP"
balls=val(getcontroltext(d1,edit_1))
seedrnd(timer)
STARTTIMER d1, 100, timer_1
else
setcontroltext d1,button_1,"GO"
STOPTIMER d1,timer_1
ENDIF
ENDIF
CASE BUTTON_2
IF @NOTIFYCODE = 0
ballx=133 :bally=30
for i=0 to 6
bino[i]=0
next i
drawfond()
ENDIF
ENDSELECT
'
CASE @IDINITDIALOG
CENTERWINDOW d1
/* Initialize any controls here */
case @IDTIMER
if @code=timer_1 then timerproc()
'
case @IDPAINT
drawfond()
'drawball(ballx,bally)
'
CASE @IDCLOSEWINDOW
stoptimer d1,timer_1
CLOSEDIALOG d1,@IDOK
ENDSELECT
RETURN
ENDSUB

sub drawball(px as int,py as int)
'RASTERMODE d1, @RMCOPYPEN
if ox+oy>0 
ELLIPSE d1,ox,oy,12,12,rgb(255,255,255),rgb(255,255,255)
ENDIF
ELLIPSE d1,px,py,12,12,0,rgb(0,0,255)
ox=px:oy=py
endsub

sub drawfond
int i,j,k,plx,ply
'
RASTERMODE d1, @RMCOPYPEN
rect d1,1,30,300,295,rgb(255,255,255),rgb(255,255,255)
'drawmode  d1,@transparent
'
k=30:plx=30:ply=270
for i=6 to 1 step -1
for j=i to 1 STEP -1
showimage d1,plot,@IMGBITMAP ,plx,ply,30,30
plx+=40
next j
ply-=40
k+=20
plx=k
next i
'
plx=13:ply=300
for i=0 to 6
move d1,plx,ply
print d1,str$(bino[i])
plx+=40
next i
ENDSUB

sub timerproc
float hz
int pz,dz,i
bally+=10
'
if bally>280 then
dz=13
for i=0 to 6
if ballx=dz
bino[i]++
BREAKFOR
ENDIF
dz+=40
next i
'
'drawmode d1,@TRANSPARENT
ballx=13:bally=300
rect d1,1,290,300,30,rgb(255,255,255),rgb(255,255,255)
'
for i=0 to 6
move d1,ballx,bally
print d1,str$(bino[i])
ballx+=40
next i
'
ballx=133:bally=30
balls--
if balls=0 then STOPTIMER d1,timer_1
'
ELSE
'
hz=rnd(1.0)
pz=-20
if hz>=0.5 then pz=20
'
for i=70 to 280 step 40
if bally=i THEN
ballx+=pz
BREAKFOR
ENDIF
NEXT i
'
ENDIF
    '
drawball(ballx,bally)
'
endsub


Title: Re: just another binomial distribution
Post by: whitenite1 on March 27, 2011, 09:16:42 AM
zaphod..
  Very nicely done. I was most impressed with the smooth animation of the ball cascading down. Thanks for sharing..

whitenite1