|
Post by tsh73 on Feb 27, 2020 2:54:31 GMT -5
Thanks John So you fixed the sub hsv2rgb h, s, v
But putting it in a program makes picture with red background - not blue one as in Perl screenshot example though central parts do fade to black, as in Perl screenshot example
|
|
|
Post by Rod on Feb 27, 2020 4:58:17 GMT -5
You can get the blue by inverting I I do that in this simplistic color routine. It throws some crazy numbers at the #1 set color r, g, b point but Liberty does not seem to mind. So this is too simplistic for the RC demo but it draws a nice color range.
nomainwin
gr=3 prompt "Select granularity (1 [very fine] - 20 [very course])";gr gr=abs(int(gr)) if gr<3 then confirm "This will take a LONG time. Proceed?";ans$ if ans$="no" then [start] end if
[setupWindow] UpperLeftX=1 UpperLeftY=1 WindowWidth=900 WindowHeight=800 open "Julia Set" for graphics_nf_nsb as #1 #1 "trapclose [q];fill black;flush;down;color white;size ";gr
w = 850 h = 750 zoom = 1 maxiter = 255 moveX = 0 moveY = 0 cX = -0.7 cY = 0.27015
global zx, zy, tmp, i, rd, gn, bu global col$, lastCol$ t0=time$("ms") w2=int(w/2) h2=int(h/2)
zw=0.5*zoom*w zh=0.5*zoom*h
for x = 0-w2 to 0 step gr for y = 0-h2 to h2 step gr zx=1.5*x/zw'+moveX zy=y/zh'+moveY i=maxiter li=maxiter while zx*zx+zy*zy<4 and i>1 scan tmp = zx * zx - zy * zy + cX zy = 2.0 * zx * zy + cY zx = tmp i=i-1 wend i=255-i if i<>li then #1 "color ";i;" ";i*i;" ";i*i*i :li=i #1 "set ";x+w2;" ";y+h2 #1 "set ";w2-x;" ";h2-y next y next x #1 "flush" t1=time$("ms") notice "Complete ";t1-t0 wait
[q] close #1 end
|
|
|
Post by tsh73 on Feb 27, 2020 7:36:06 GMT -5
I feel this is cheating. It doesn't work as it should - but Liberty let it slip. But is someone will try to translate it to another language it'll likely break. AND WE KNOW THAT ALL ALONG ) Yeah. As pretty program for pretty picture - OK, really nice. But for Rosetta Code - I feel, no. (did someone exactly investigated how LB behaves on color values exceeding 255?)
|
|
|
Post by Rod on Feb 27, 2020 9:50:43 GMT -5
I agree, my code is not for RC. But it leaves a question mark for me. If we "correct" the color code and stick with 255 iterations we get the pixel detail but we don't get the color detail. Its lost, compacted into 255 colors. What we need is a much wider spread of colors. 360o wheel wont cut it either, when I look online most examples are using 1k colors or more. It seems you can create any color table/spread you like.
I have no idea how the original code posted managed to get so much color detail with 255 iterations. Perhaps like my code it was generating thousands of semi random / cycling colors.
There are so many really nice examples online I think we should persevere a bit more. Johns code produced too dull an image for me again with lost color detail.
|
|
|
Post by tsh73 on Feb 28, 2020 1:52:40 GMT -5
Ok I gave it a few tries it looks like it just took lower byte something along (x mod 256) anything dividable by 256 just discards 80 mades same impact as 80+256*20 or 80+256*4000 or -176 or -176-256*100 (-176 is 80-256) so if green is over 255 (or under 0), it does not spill from green to red or blue
|
|
|
Post by Rod on Feb 28, 2020 6:51:57 GMT -5
Well, the number of iterations to reach the trigger point determines how far away a pixel is and what its color should be. So if we want black to be far away and white to be close in we should have a smooth color table from black to white or whatever color transition is desired.
Problem is we have 255 iterations so only 255 possible colors. Yet David's initial graphic looked great. The semi random nature of my flawed code for color change produced some nice graphics as well precisely because the colors were in nice tight color bands. Not completely random but enough banding to pull out nice highlights.
If we create a smooth color transition we get really bland graphics and lose detail in the image. So this is a compromise.
Here is the color banding.
nomainwin global zx, zy, tmp, i, rd, gn, bu global col$, lastCol$ pi = acs(-1) dim col(2,255) for i = 0 to 255 col(0,i)= abs(INT(128 - 127 * SIN(i * pi / 32))) col(1,i)= abs(INT(128 - 127 * SIN(i * pi / 64))) col(2,i)= abs(INT(128 - 127 * SIN(i * pi / 128))) next
open "Julia Set" for graphics_nf_nsb as #1 #1 "trapclose [q];fill black;flush;down;color white;size ";10
maxiter = 255 for i = maxiter to 0 step -1 a = i/maxiter*2*pi #1 "color ";col(0,i);" ";col(1,i);" ";col(2,1) #1 "set ";150+120*cos(a);" ";150+120*sin(a) next
wait
[q] close #1 end
And here it is applied to the most recent code.
nomainwin
[color] 'create color spread pi = acs(-1) dim col(2,255) for i = 0 to 255 col(0,i)= abs(INT(128 - 127 * SIN(i * pi / 32))) col(1,i)= abs(INT(128 - 127 * SIN(i * pi / 64))) col(2,i)= abs(INT(128 - 127 * SIN(i * pi / 128))) next
gr=5 '1=slow, higher is faster and grainier
[setupWindow] UpperLeftX=1 UpperLeftY=1 WindowWidth=900 WindowHeight=800 open "Julia Set" for graphics_nf_nsb as #1 #1 "trapclose [q];fill black;flush;down;color white;size ";gr
w = 850 h = 750 zoom = 1 maxiter = 255 moveX = 0 moveY = 0 cX = -0.7 cY = 0.27015
global zx, zy, tmp, i, rd, gn, bu global col$, lastCol$
w2=int(w/2) h2=int(h/2)
zw=0.5*zoom*w zh=0.5*zoom*h
for x = 0-w2 to 0 step gr for y = 0-h2 to h2 step gr zx=1.5*x/zw'+moveX zy=y/zh'+moveY i=maxiter while zx*zx+zy*zy<4 and i>1 scan tmp = zx * zx - zy * zy + cX zy = 2.0 * zx * zy + cY zx = tmp i=i-1 wend 'i=255-i if i<>lasti then #1 "color ";col(0,i);" ";col(1,i);" ";col(2,1):lasti=i #1 "set ";x+w2;" ";y+h2 #1 "set ";w2-x;" ";h2-y next y next x #1 "flush"
notice "Complete " wait
[q] close #1 end
I don't think we need worry about errors or crashes, it runs fine on my machine.
|
|
|
Post by Rod on Feb 28, 2020 6:59:07 GMT -5
And this is the color banding my flawed code was producing thanks to Liberty's tolerance. Just trying to explain why it all worked.
nomainwin global zx, zy, tmp, i, rd, gn, bu global col$, lastCol$ pi = acs(-1) open "Julia Set" for graphics_nf_nsb as #1 #1 "trapclose [q];fill black;flush;down;color white;size ";10
maxiter = 255 for i = maxiter to 0 step -1 a = i/maxiter*2*pi #1 "color ";i;" ";i*i;" ";i*i*i #1 "set ";150+120*cos(a);" ";150+120*sin(a) next
wait
[q] close #1 end
|
|
|
Post by tenochtitlanuk on Mar 1, 2020 13:42:09 GMT -5
Colour fun is my favourite computer graphic activity. With its three variables my colour choice gave all the following when used with slightly different parameters on the RC XOR-pattern we had fun with some time back. rosettacode.org/wiki/Munching_squares
|
|