papydall
Number of posts : 39 Age : 73 Localisation : TUNISIA Registration date : 2013-03-16
| Subject: Draw a forest Fri Oct 18, 2013 12:37 pm | |
| Hello everybody. Here is a small code to draw a forest. Good entertainment! - Code:
-
' ********************************* ' * * ' * FOREST.BAS BY PAPYDALL ' ** English version ' * * ' ********************************* init() sun(xsun%,ysun%,rsun%) go() end ' ******************************************************************************
SUB init() dim ss% : ss% = 20 dim sang,sang1(ss%),xx(ss%),yy(ss%) dim rad : rad = 3.141592653579793/180 dim compteur% : compteur% = 0 dim xpos%,ypos% : xpos% = 320 : ypos% = 500 dim xp,yp,xp1,yp1,x,y,x1,y1,ran1,ran2,s2,zx,zy dim a$,a0$,a1$,b$,st,gen%,k%,s,ang,ang1,an,j%,cl,i% dim xsun%,ysun%, rsun% : xsun% = int(rnd(800)+100) : ysun% = 50 : rsun% = 20 dim titre$ : titre$ = " *** <CLICK> TO STOP" titre$ = titre$ + " *** BUT YOU WILL LOSE NOTHING IF YOU WAIT A FEW MINUTES !!!" width 0,1000 : height 0, 700 : color 0,10,100,150 : cls
END_SUB ' ****************************************************************************** SUB sun(x%,y%,r%) 2d_circle x%,y%,r% : 2d_flood x%,y%,255,255,0 END_SUB ' ******************************************************************************
SUB go() dim_local cr%,cv%,cb%, exit% exit%=0 repeat cr% = int(rnd(160)) : cv% = int(rnd(140)) : cb%=int(rnd(255)) xpos% = int(rnd(800) +100) B$ = "" : A$ = "" : A0$ = "" : A1$ = "" st = 0 : gen% = mod(compteur%,13)+1 : compteur% = compteur% + 1 caption 0,"FOREST BY PAPYDALL : NUMBER OF DRAWN PLANTATIONS : " + str$(compteur%) + string$(5," ") + titre$ select gen% case 1 k% = 6 : s = 1.5 : ang1 = int(rnd(80)+8 ) A$ = "0" : A1$ = "11" : A0$ = "1##10!+0!-0" case 2 k% = 5 : s = 3 : ang1 = int(rnd(20)+16) A$ = "1" : A1$ = "11-#-1+0+0!+#+1-0-0!" : A0$ = "0" case 3 k% = 6 : s = 1.5 : ang1 = int(rnd(45)+8 ) A$ = "0" : A1$ = "11" : A0$ = "1#+0!1#-0!0" case 4 k% = 5 : s = 3 : ang1 = int(rnd(10)+10) A$ = "1" : A1$ = "1#+0!#=0!1#+1+-0!#-1-+0!" : A0$ = "0-0++0" case 5 k% = 5 : s = 3 : ang1 = int(rnd(16)+16) A$ = "1" : A1$ = "11-#-1+0+0!+#+1-0-0!" : A0$ = "#0-0++0!" case 6 k% = 4 : s = 2.5 : ang1 = int(rnd(10)+10) A$ = "1" : A1$ = "1#+10!1#-10!1" : A0$ = "#0-0++0!" case 7 k% = 4 : s = 1.75 : ang1 = int(rnd(30)+10) A$ = "1" : A1$ = "1#+1-10!1#-1+10!10" : A0$ = "#0-0++0!" case 8 k% = 4 : s = 3 : ang1 = int(rnd(15)+10) A$ = "1" : A1$ = "11#+1-1+10!#-1+1-10!" : A0$ = "#0-0++0!" case 9 k% = 4 : s = 3.5 : ang1 = 10 A$ = "1" : A1$ = "11#+1+1-#0-0++0!!0#-1-1+#0-0++0!!" : A0$ = "#0-0++0!" case 10 k% = 4 : s = 3.6 : ang1 = int(rnd(5)+10) A$ = "#+1-1!#-1+1!" : A1$ = "1#-1+0!1#+1-0!0" : A0$ = "#0-0++0!" case 11 k% = 3 : s = 2.75 : ang1 = int(rnd(3)+8 ) A$ = "1" : A1$ = "11#+10-10+10-10!1#-10+10-10+10!0" : A0$ = "0" case 12 k% = 3 : s = 4 : ang1 = int(rnd(60)+20) A$ = "1" : A1$ = "1#-10-10-10!1#+10+10+10!1#10!" : A0$ = "0" case 13 k% = 4 : s = 2 : ang1 = int(rnd(8 )+10) A$ = "0" : A1$ = "111" : A0$ = "11#+0!#++0!#+++0!#-0!#--0!#---0!0" end_select
for j% = 1 to k% cl = len(A$) for i% = 1 to cl if mid$(A$,i%,1) = "1" B$ = B$ + A1$ else if mid$(A$,i%,1)="0" B$ = B$ + A0$ else B$ = B$ + mid$(A$,i%,1) end_if end_if next i% A$ = B$ : B$ = "" ang = 360.0/ang1 : x = 0 : y = 0 : an = 0 : cl = len(A$) for i% = 1 to cl if mid$(A$,i%,1) = "1" ran1 = rnd(1) : ran2 = rnd(1) : s2 = s + 0.5 *(ran1-ran2)* s ran1 = rnd(1) : ran2 = rnd(1) : an = an + 5.0 *(ran1-ran2) sang = an : x1 = s2 * sin(an*rad)+ x : y1 = s2 * cos(an*rad)+ y xp = 2 * x + xpos% : yp = ypos% - 2 * y xp1 = 2 * x1 + xpos% : yp1 = ypos% - 2 * y1 2d_pen_color 0,90+cv%,0 : 2d_line xp,yp , xp1,yp1 x = x1 : y = y1 else if mid$(A$,i%,1) = "0" zx = sin(an*rad): zy = cos(an*rad) x1 = zx * s + x : y1 = zy * s + y xp = 2 * x + xpos% : yp = ypos% - 2 * y xp1 = 2 * x1 + xpos% : yp1 = ypos% - 2 * y1 2d_pen_color 90+cr%,65 + cv%,cb% : 2d_line xp,yp , xp1,yp1 x1 = 0.25 * zx * s + x : y1 = 0.25 * zy * s + y xp1 = 2 * x1 + xpos% : yp1 = ypos% - 2 * y1 2d_pen_color 255,0,0 : 2d_line xp,yp , xp1,yp1 else if mid$(A$,i%,1) = "-" ran1 = rnd(1) : ran2 = rnd(1) an = an - ang - 10 *(ran1-ran2) : sang = an else if mid$(A$,i%,1)="+" ran1 = rnd(1) : ran2 = rnd(1) an = an + ang + 10 *(ran1-ran2) : sang=an else if mid$(A$,i%,1)="#" st = st + 1 : sang1(st) = sang xx(st) = x : yy(st) = y else if mid$(A$,i%,1)="!" x = xx(st) : y = yy(st) an = sang1(st) : sang = an : st = st-1 end_if end_if end_if end_if end_if end_if if scancode<>0 then exit% = 1: exit_for next i% if exit%=1 then exit_for next j% until exit% = 1 END_SUB ' **************** E N D ***************
| |
|
froggy one
Number of posts : 1 Registration date : 2013-10-19
| Subject: Re Sat Oct 19, 2013 6:43 pm | |
| Papydall, I've just discovered your program on the british forum, that's beautiful, looks like fern. I'm still learning programmation with your exercises. I do like your style, leading us to further questions and trials. See you back on the french side, bye ! | |
|
papydall
Number of posts : 39 Age : 73 Localisation : TUNISIA Registration date : 2013-03-16
| Subject: Re: Draw a forest Sat Oct 19, 2013 7:54 pm | |
| Thank you Froggy One. This program was already posted on the French forum for some time. | |
|
Sponsored content
| Subject: Re: Draw a forest | |
| |
|