|
Post by tsh73 on Nov 20, 2021 20:34:33 GMT
Have nothing to do? Have a go at repeating this pattern in JB (I was looking at student practicing graphic stuff, repeating chessboard from example. Then I thight "It might be cool if I start with big squares, then divide them in half keeping then alternating, and continue till it get 1 pixel") So after coming home (and finishing that other big program I just posted) I quickly draw this. It fits to description but surprised me looking that fractalish. It supposed to be 512x512 so it fits 1376x768 screen and divides nicely. How small program could you get? I will post my solution later (give folks time to show their own ideas :) )
|
|
|
Post by tenochtitlanuk on Nov 21, 2021 16:40:18 GMT
That was fun! I tried swapping the alternating fill on each line for aesthetic reasons, and using circles ( needed a fiddle-factor to make them touch.)
|
|
|
Post by tsh73 on Nov 22, 2021 18:36:56 GMT
I hope I did give enough time to ponder on it;) First I did one version (surpisingly last one), then I made two others...
Approach #1. Draw squares down - in a loop - alternating color (rather draw/not draw) - to bottom. Then shrink square 2x, move right, repeat until size comes to 1 (happened that you can't draw BOX of single pixel size)
'rectangle version nomainwin
N=9 desiredWidth = 2^N desiredHeight = 2^N
gosub [ajustWindow] 'now, center window UpperLeftX = (DisplayWidth - WindowWidth)/2 UpperLeftY = (DisplayHeight - WindowHeight)/2
'now, open your window with desired size 'with menu if you wish 'MENU #gr, "File", "Exit", [quit] open "Shrinking chess pattern" for graphics_nsb_nf as #gr ' graphics ' graphics_nsb ' graphics_nsb_nf
#gr, "trapclose [quit]" #gr, "down" #gr "backcolor black" s=2^(N-1) x=0 do for y = 1 to 2^N-1 step s if i mod 2 then if s>1 then #gr "place ";x;" ";y #gr "boxfilled ";x+s;" ";y+s else #gr "set ";x;" ";y 'there no single-pixel box end if end if i=i+1 next x=x+s s=int(s/2) loop while s>0 #gr "flush"
wait
'----------------------- [quit] timer 0 close #gr end
'------------------------------------------------- [ajustWindow] UpperLeftX = 20 UpperLeftY = 20 WindowWidth = 200 '100 seems to be too much - works different WindowHeight = 100 'MENU #gr, "dummy" open "Ajusting..." for graphics_nsb_nf as #gr ' graphics ' graphics_nsb ' graphics_nsb_nf
#gr, "home ; down ; posxy x y" 'x, y give us width, height width = 2*x : height = 2*y close #gr
slackX = 200-width slackY = 100-height
WindowWidth = desiredWidth + slackX WindowHeight = desiredHeight + slackY
return
Part that sets window is boilerplate, I will not repeat that.
Approach #2. Take a square; fill lower bottom quarter; call it recursively on top right, bottom right. Recursion ends then square gets too small. Recursive code is neat! ;) Only inner drawing part:
#gr "backcolor black" call draw 0, 0, 2^N #gr "flush"
wait
sub draw x, y, s s=s/2 if s>1 then #gr "place ";x;" ";y+s #gr "boxfilled ";x+s;" ";y+2*s call draw x+s, y, s call draw x+s, y+s, s else #gr "set ";x;" ";y 'there no single-pixel box end if end sub
Approach #3. After some thinking - it occured to me that each line in resulting picture corresponds to binary representation of one number from 0 to 2^N-1, where "1" is black, and line segment length is binary digit weight (that is, 2^i) It get somewhat mangled since I imagined it with upper digit left - and it got showing backwards, so I end with 2^(10-i) and 512-x. But I still think it's neat. Needs bin$() custom function.
for y = 0 to 2^N b$=right$("000000000"+bin$(y), 9) for i = 1 to 9 if mid$(b$,i,1)="1" then x=2^(10-i) #gr "line ";512-x/2;" ";y;" ";512-x;" ";y end if next next #gr "flush"
wait
'----------------------------- function bin$(n) while n bin$=(n mod 2);bin$ n=int(n/2) wend if bin$="" then bin$="0" end function
|
|
|
Post by tenochtitlanuk on Nov 22, 2021 19:25:58 GMT
I'll add a page to my site with my variations. Interesting seeing you working around ideas --> code, Anatoly. Meanwhile here's one for everyone- the 'Tree of Circles'. Here's an animation of my current approach to this one!
|
|
|
Post by tenochtitlanuk on Nov 24, 2021 22:31:35 GMT
..and now ... ( suppressing the 'inward' directions. And leaving space... EDIT or without the spaces... .. and my favourite ...
|
|
|
Post by tsh73 on Nov 28, 2021 8:38:37 GMT
Snowy one looks really nice, too And nice thing about patterns - then you fail to reproduce sought pattern you might get another pretty one (it this case I did not step from parent circle at all)
|
|
|
Post by tenochtitlanuk on Nov 28, 2021 19:25:38 GMT
Next one I want to try is this.. wonder what I'll end with?
|
|
|
Post by tenochtitlanuk on Dec 2, 2021 17:25:32 GMT
So I got . . . Will be putting a page on my site soon with the code.
|
|
|
Post by tsh73 on Dec 2, 2021 18:02:21 GMT
looks like some celestial mechanic ;) (just imagine it spin!) I wonder if you make circles stay apart as 1/number of incoming lines?
|
|
|
Post by tsh73 on Dec 2, 2021 21:04:09 GMT
Got more on the floral side, I think :) 'along JohnFisher (tenochtitlanuk) picture nomainwin
global pi, cx, cy, shrink pi = acs(-1)
WindowWidth = 600 WindowHeight = 600
open "test" for graphics_nsb_nf as #gr #gr "home; down; posxy cx cy" #gr "trapclose [quit]"
shrink = 2 call draw cx,cy,a,0,256,0
#gr "flush"
wait
[quit] timer 0 close #gr end
sub draw x,y,a,totLen, length, level SCAN 'if level >5 then exit sub if length <1 then exit sub x1=cx+cos(a)*totLen y1=cy+sin(a)*totLen if level >0 then #gr "place ";x;" ";y #gr "goto ";x1;" ";y1 end if
if a = 0 and totLen>0 then #gr "place ";cx;" ";cy #gr "circle ";totLen end if
N=3^(level+1) da=2*pi/N length=length/shrink call draw x1,y1,a-da,totLen+length,length, level+1 call draw x1,y1,a,totLen+length,length, level+1 call draw x1,y1,a+da,totLen+length,length, level+1 end sub
|
|
|
Post by tenochtitlanuk on Dec 2, 2021 21:57:47 GMT
Nice one! It repays the experimentally-minded programmer. And recursion is definitely the better way.. I've re-created the original version, overlayed on the Orion constellation. Details are on a page at Diga-Me
|
|
|
Post by tenochtitlanuk on Dec 3, 2021 11:28:43 GMT
For amusement I threw random colours at all white areas. This needs to be run in LB for the dll. A few seconds and 10000 throws later I got
|
|