jsbasic/samples/sample.coloredserpinski.txt

22 lines
741 B
Plaintext
Raw Normal View History

2020-02-10 16:06:56 +00:00
100 REM COLORED SERPINSKI TRIANGLES
110 CLEAR:HGR:POKE 49234,0
120 seed=RND(-PEEK(78)-PEEK(79)*256)
130 REM SCREEN SIZE AND MAIN TRIANGLE VERTICES
140 w=279:w2=139:h=192:h2=96:DIM x(2),y(2)
150 x(0)=0:y(0)=h:x(1)=w2:y(1)=0:x(2)=w:y(2)=h
160 REM ARRAY OF RANDOM HI-RES COLOURS
170 DIM c(3):c(0)=1:c(1)=2:c(2)=5:c(3)=6
180 FOR i=0 TO 3:j=INT(RND(1)*4)
190 t=c(i):c(i)=c(j):c(j)=t:NEXT
200 REM START POINT AND NUMBER OF DOTS
210 x=0:y=191:dots=40000
220 REM PLOT POINTS HALFWAY TOWARDS RANDOM VERTICES
230 FOR i=0 to dots
240 v=rnd(1)*3:x=(x+x(v))/2:y=(y+y(v))/2
250 IF y =>h THEN y=191
260 REM PICK COLOR FOR EACH TRIANGLE
270 HCOLOR=c(0):IF y>h2 THEN HCOLOR=c(1)
280 IF y>h2 AND x>w2 THEN HCOLOR=c(2)
290 HPLOT x,y:NEXT
300 PRINT CHR$(7):END