|
Post by tsh73 on Jan 12, 2023 20:49:13 GMT
Picture: f(x) = -(xxx +x + 1) (0,0) = center color(x,y) = arctan2(x, f(x)) lum(x,y) = sin(hypot(x, f(x))/alpha)
Well, where's the picture? You draw it
(I'll try too, and reveal a sorce - I randomly browsed on ot - in a few days)
|
|
|
Post by tenochtitlanuk on Jan 12, 2023 23:44:10 GMT
Here is a bit of help/explanation of what I think is specified.
'f( x) = 0-( x^3 +x + 1) '( 0, 0) = center of figure, say x -100/100; fx +/-1E6 roughly
'arctan2( x1, x2) is the signed angle in radians between the ray ending at the origin ' and passing through the point (1,0), and the ray ending at the origin and passing ' through the point (x2, x1). (Note the role reversal: the “y-coordinate” is the first ' function parameter, the “x-coordinate” is the second.) ' This function is defined for x2 = +/-0 and for either or both of x1 and x2 = +/-inf. color( x, y) = arctan2( x, f( x)) ?hue 0-360
'hypot returns the square root of the sum of squares of its arguments. lum( x, y) = sin( hypot( x, f( x)) /alpha) ?level 0- 1 ' ?saturation 0- 1
Any hints on value of alpha or range of x?
My attempt simply copied arctan2( from previous code and modifies my HSV code and fails miserably. It's a pretty graphic so I'll try to find time for another attempt...
|
|
|
Post by plus on Jan 13, 2023 1:56:24 GMT
Even better any screen shots?
|
|
|
Post by tsh73 on Jan 13, 2023 6:54:51 GMT
|
|
|
Post by plus on Jan 13, 2023 16:50:00 GMT
|
|
|
Post by tsh73 on Jan 13, 2023 20:52:15 GMT
Well I was not able to get *same* stuff. I used complex numbers library to calculate f(z) on complex numbers I had to divide atan2 to 2pi because I used ready function that reflects [0..1] to color circle, not [0..2pi] And "0/5-" make colors rotate in right direction. And played and played and played... And then I got this And thought it is time to stop ;) You can play with it too. Parameters to tweak are range [x0 x1] [y0 y1] and alpha. nomainwin 'Picture: 'f(x) = -(xxx +x + 1) '(0,0) = center 'color(x,y) = arctan2(x, f(x)) 'lum(x,y) = sin(hypot(x, f(x))/alpha)
'I give up and use complex library
open "test" for graphics_nsb_nf as #gr #gr "home; down; posxy cx cy" #gr "trapclose [quit]" #gr "size 2"
N=100
alpha=1 'play with alpha
pi = acs(-1) pi2 = pi*2
x0 = -2: x1=2: dx = (x1-x0)/N y0 = -2: y1=2: dy = (y1-y0)/N scale = 200/(x1-x0) 'auto scalese to fill 200 pixels wide. Of cource tested with same ranges for x, y for x = x0 to x1 step dx 'print x, f(x) -1..1 -> 0..-2 for y = y0 to y1 step dy SCAN xx = int(cx+x*scale) yy = int(cy+y*scale) z$=compl$(x, y) r$=f$(z$) colr$=rainbow$(0.5-atan2(Im(r$), Re(r$) )/pi2) 'sets global r g b lum = sin(hypot(Re(r$),Im(r$))/alpha) 'apply luminance to global r g b #gr "color ";applyLum$(lum) #gr "set ";xx;" ";yy next next
#gr "flush"
wait
[quit] timer 0 close #gr end
function f$(z$) ' 0-(1+z+z*z*z) f$ = subCompl$("0 0" , addCompl$("1 0", addCompl$(z$, mulCompl$(z$, mulCompl$(z$, z$))))) end function
'not used, complex function above instead function f(x) f = 0-(x*x*x +x + 1) end function
function hypot(x,y) hypot=sqr(x*x+y*y) end function
'--------------------------------------------- global r,g,b
' 0..1 into red-green-blue-red continuous colors function rainbow$(x) hi = int((x*6) mod 6)+ 5*(x<0) 'fixed to 0..5 f = (x*6) mod 1 + (x<0) 'frac, 0..1 q = (1-f) select case hi case 0 r = 1: g = f: b = 0 case 1 r = q: g = 1: b = 0 case 2 r = 0: g = 1: b = f case 3 r = 0: g = q: b = 1 case 4 r = f: g = 0: b = 1 case 5 r = 1: g = 0: b = q end select R = int(r*255) G = int(g*255) B = int(b*255) rainbow$= R;" ";G;" ";B end function
function applyLum$(lum) 'cahnges color in global r g b by scaling on lum -1..1 (actually abs(lum)) factor=abs(lum)*255 R = int(r*factor) G = int(g*factor) B = int(b*factor) applyLum$= R;" ";G;" ";B end function
'--------------------------- function atan2(y,x) pi = acs(-1) 'could be made global to save some ticks if x <> 0 then arctan = atn(y/x)
select case case x > 0 atan2 = arctan
case y>=0 and x<0 atan2 = pi + arctan
case y<0 and x<0 atan2 = arctan - pi
case y>0 and x=0 atan2 = pi / 2
case y<0 and x=0 atan2 = pi / -2 end select end function
'------------------------------------- 'complex library. I jsut was too lazy to multiply complex numbers by hand. function absCompl$(c1$) Re=Re(c1$) Im=Im(c1$) abs=sqr(Re*Re+Im*Im) absCompl$ = str$(abs) end function
'Conjugation function barCompl$(c1$) Re=Re(c1$) Im=0-Im(c1$) barCompl$ = str$(Re)+" "+ str$(Im) end function
function divCompl$(c1$, c2$) '(a + bi)/(c + di): = (ac + bd)/(c^2+d^2) + (bc - ad)/(c^2+d^2)i. a=Re(c1$) b=Im(c1$) c=Re(c2$) d=Im(c2$) dd=c*c+d*d divCompl$ = str$((a*c + b*d)/dd) +" " + str$((b*c - a*d)/dd) end function
function mulCompl$(c1$, c2$) '(a + bi)(c + di): = (ac - bd) + (bc + ad)i. a=Re(c1$) b=Im(c1$) c=Re(c2$) d=Im(c2$) mulCompl$ = str$(a*c - b*d) +" " + str$(b*c + a*d) end function
function subCompl$(c1$, c2$) Re=Re(c1$)-Re(c2$) Im=Im(c1$)-Im(c2$) subCompl$ = str$(Re)+" "+ str$(Im) end function
function addCompl$(c1$, c2$) Re=Re(c1$)+Re(c2$) Im=Im(c1$)+Im(c2$) addCompl$ = str$(Re)+" "+ str$(Im) end function
function formatCompl$(compl$) Re = Re(compl$) Im = Im(compl$) if Re=0 and Im=0 then formatCompl$ = "0": exit function Re$ = word$(compl$,1) if Re =0 then Re$="" 'and no next "+" Im$=str$(Im)+"i" if Im =0 then Im$="" formatCompl$ = Re$+ iif$(Im>0 and Re<>0, "+", "")+ Im$ end function
function Re(compl$) Re = val(word$(compl$,1)) end function
function Im(compl$) Im = val(word$(compl$,2)) end function
function compl$(Re, Im) 'you better inline this, actually compl$= str$(Re)+" "+ str$(Im) end function
'----------------------------------- function iif(test, valYes, valNo) iif = valNo if test then iif = valYes end function
function iif$(test, valYes$, valNo$) iif$ = valNo$ if test then iif$ = valYes$ end function
|
|
|
Post by plus on Jan 14, 2023 17:10:38 GMT
Yes very nice when range above +-2, a mix of Connett circles, and plasma, nice coloring! This is +- 4 range
|
|
|
Post by tenochtitlanuk on Jan 14, 2023 21:45:05 GMT
Fun to see these solutions, Anatoly and 'plus'. Always found the complex operations library useful, and for my versions I've used my HSV code ( on my website) which implements the colour and luminance ( and value) directly. Wikipedia is very good on HSV and HSL and how they differ and also differ from how humans see colours!
|
|
|
Post by triggered on Jan 15, 2023 13:22:03 GMT
Say, why doesn't marshawn show us how to do it right?
|
|
|
Post by tenochtitlanuk on Jan 15, 2023 21:20:52 GMT
Vaguely connected example- if you need a smooth multi-colour range that smoothly repeats without discontinuity you can use Anatoly's 'rainbow' routine or my HSV one. Examples below show the kind of thing I get using my method- you can alter the brightness of a particular colour up to white or down to black. Code below is easily modified to cycle hue and value round a three-cycle circle. Add/remove rems to use Anatoly's instead.
nomainwin
global pi, col$: pi =3.14158265
WindowWidth =468 WindowHeight =488 UpperLeftX =int( ( DisplayWidth -WindowWidth) /2) UpperLeftY =int( ( DisplayHeight -WindowHeight) /2)
graphicBox #w.g, 9, 9, 440, 440
open "Color change /fade demo" for window as #w
#w "trapClose quit"
#w.g "down; fill black" #w.g "size 8"
value = 0.99 radius =100 satn = 0.99
[start] for hue =0 to 3 *360 step 1 call hsv2rgb hue mod 360, satn, value ' hue, saturation, value 'col$ =rainbow$( ( hue mod 360) /360) #w.g "color "; col$ x =220 +radius *cos( hue *pi /180 /3) y =220 +radius *sin( hue *pi /180 /3) #w.g "set "; int( 1 +x); " "; 1 +int( y) scan next hue
radius =radius +4 if satn >0 then satn =satn -0.05: radius =radius +2: goto [start]
#w.g "flush" '#w.g "getbmp scr 1 1 440 440" 'bmpsave "scr", "Tjh" +str$( time$( "seconds")) +".bmp" '#w.g "cls ; drawbmp scr 1 1"
wait
global r, g, b
' 0..1 into red-green-blue-red continuous colors function rainbow$( x) hi = int(( x *6) mod 6)+ 5 *( x <0) 'fixed to 0..5 f = ( x *6) mod 1 + ( x <0) 'frac, 0..1 q = ( 1 -f) select case hi case 0 r = 1: g = f: b = 0 case 1 r = q: g = 1: b = 0 case 2 r = 0: g = 1: b = f case 3 r = 0: g = q: b = 1 case 4 r = f: g = 0: b = 1 case 5 r = 1: g = 0: b = q end select R = int( r *255) G = int( g *255) B = int( b *255) rainbow$ = R; " "; G; " "; B end function
sub hsv2rgb h, s, v ' hue 0-360, saturation 0-1, value 0-1 if h >=360 or s >1 or v >1 then call quit h$ c =v *s ' chroma h =h x =c *( 1 -abs( ( ( h /60) mod 2) -1)) m =v -c ' matching adjustment
select case case h < 60 r = c: g = x: b = 0 case h <120 r = x: g = c: b = 0 case h <180 r = 0: g = c: b = x case h <240 r = 0: g = x: b = c case h <300 r = x: g = 0: b = c case else r = c: g = 0: b = x end select
rd = abs( int( 256 *( r + m))) gn = abs( int( 256 *( g + m))) bu = abs( int( 256 *( b + m))) col$ =right$( " " +str$( rd), 3) +" " +right$( " " +str$( gn), 3) +" " +right$( " " +str$( bu), 3)
end sub
sub quit handle$ close #w end end sub
|
|