Page 1 of 1

"Rectangular" coding by a sloppy programmer

Posted: Fri Jan 30, 2015 9:03 am
by Henko
Bad practice, but sB allows it. 8-)

Code: Select all

graphics ! graphics clear .8,.8,.8 ! draw color 0,0,0 'xx
option angle degrees ! option screenlock off ! randomize 
sw=screen_width() ! cx=sw/2 ! sh=screen_height() !cy=sh/2
xo=cx ! yo=cy ! s=4 ! mc=1 ! shadow on 'xxxxxxxxxxxxxxxx
anew: draw to xo,yo ! draw color rnd(mc),rnd(mc),rnd(mc)
loop: ang=rnd(360) ! x=xo+s*cos(ang) ! y=yo+s*sin(ang) 'x
if x<0 or x>sw then ! xo=cx ! goto anew ! end if 'xxxxxxx
if y<0 or y>sh then ! yo=cy ! goto anew ! end if 'xxxxxxx
draw line to x,y ! xo=x ! yo=y ! goto loop ! end 'xxxxxxx

Re: "Rectangular" coding by a sloppy programmer

Posted: Fri Jan 30, 2015 9:25 am
by Mr. Kibernetik
The same but 1 line shorter:

Code: Select all

graphics ! graphics clear 0.8,0.8,0.8 ! draw color 0,0,0
option angle degrees ! option screenlock off ! randomize 
sw=screen_width() ! cx=sw/2! sh=screen_height()! cy=sh/2
xo=cx ! yo=cy ! s=4 ! mc=1 ! shadow on ! 1 draw to xo,yo
draw color rnd(mc), rnd(mc), rnd(mc)! loop: ang=rnd(360)
x=xo+s*cos(ang)! y=yo+s*sin(ang) ! if x< 0 or x> sw then
xo=cx ! goto 1 ! end if ! if y < 0 or y> sh then ! yo=cy
goto 1! end if ! draw line to x,y! xo=x! yo=y! goto loop