"Rectangular" coding by a sloppy programmer

Post Reply
Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

"Rectangular" coding by a sloppy programmer

Post 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

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: "Rectangular" coding by a sloppy programmer

Post 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

Post Reply