|
Post by tenochtitlanuk on Nov 3, 2022 17:15:38 GMT -5
Happened on this on Wolfram Mathworld and just had to code it in LB! Code'll be on my website if you can't code polar coordinates!
|
|
|
Post by tsh73 on Nov 4, 2022 8:21:43 GMT -5
Well, not a couple of lines sure I just reused old program drawing Cat Curve libertybasiccom.proboards.com/thread/796/cat-curvewith a formulas found elsewhere tex.stackexchange.com/questions/348089/how-to-draw-a-maple-leaf-in-tikzand got - this edit - filled red version global width, minX, maxX, height, minY, maxY
nomainwin open "Maple Leaf" for graphics as #grFunc print #grFunc, "trapclose [trapcloseLabel]" print #grFunc, "home ; down ; posxy x y" 'x, y give us width, height width = 2*x : height = 2*y
pi = acs(-1)
'parametric plot t0=0 tk=1*pi n=100'00
' n = 300 'nPoints give FloatUnderflowException n = 333 'nPoints h = (tk-t0)/n
'get x, y bounds a = 1e10 b = -1e10 minY = 1e10 maxY = -1e10 for t = t0 to tk step h x = x(t) if x< a then a = x if x> b then b = x y = y(t) if y< minY then minY = y if y> maxY then maxY = y next minX = a : maxX = b
'print "ymin, ymax ", minY, maxY
'axes xxmin = sx(a) : xxmax = sx(b) : y0 = sy(0) print #grFunc, "line ";xxmin;" ";y0;" "; xxmax;" ";y0 'horiz from A to B print #grFunc, "place ";xxmax-15;" ";y0-5 print #grFunc, "\X" yymin = sy(minY) : yymax = sy(maxY) : x0 = sx(0) print #grFunc, "line ";x0;" ";yymin;" "; x0;" ";yymax 'vert ymin to ymax print #grFunc, "place ";x0-15;" ";yymax+15 print #grFunc, "\Y"
x = sx(x(t0)) y = sy(y(t0)) print #grFunc, "place ";x;" ";y
y00 = sy(0) x00 = sx(0)
#grFunc "color red" for t = t0 to tk step h/11 y = sy(y(t)) xx = sx(x(t)) 'print #grFunc, "goto "; xx; " "; y #grFunc, "line "; x00; " "; y00;" "; xx; " "; y next
print #grFunc, "flush" wait end
[trapcloseLabel] close #grFunc end
'****************************************** 'sample function function x(t) 'x = 100*cos(t) x = (1+cos(6*t)^2 +1/5*(cos(6*t)*cos(24*t))^10 + _ (1/4*cos(30*t)^2+1/9*cos(30*t)^12) *(1-sin(6*t)^10) _ ) *sin(2*t)*(1-cos(t)^4)* _ (1-cos(t)^10*cos(3*t)^2 ) +1/70*cos(t)^9
end function
function y(t) 'y = 130*sin(3*t) y = 0-21/20*cos(2*t)*(1-cos(t)^4+1/2*(cos(t)*cos(3*t))^10) * _ (1+cos(6*t)^2+1/5*(cos(6*t)*cos(18*t))^10 + _ (1/4*cos(30*t)^4 +1/10 * cos(30*t)^12 ) * _ (1-cos(t)^10*cos(3*t)^2 ) *(1-sin(6*t)^10) _ ) end function
'conversions (logical coords to screen) function sx(x) 'screen X. Depends on width, minX, maxX sx = (x- minX)/(maxX-minX) * width end function
function sy(y) 'screen Y. Depends on height, minY, maxY. Upside down. sy = (1-(y- minY)/(maxY-minY)) * height end function
|
|
|
Post by tenochtitlanuk on Nov 4, 2022 18:25:08 GMT -5
Makes a nice demo of color filling to call the floodfill dll after drawing te outline. Redrawing as radii is too slow to make this effective.
You need to run the code below to see it draw the shape, surround it with black then go through a cycle of HSV colours...
nomainwin
WindowWidth =800 WindowHeight =800
open "Polar graphics" for graphics_nsb as #wg
#wg "trapclose quit"
hw =hwnd( #wg) calldll #user32, "GetDC", hw as ulong, hdc as ulong
pi = 3.14159265 a =150
n = 9
global col$
#wg "down ; fill darkblue ; backcolor darkblue ; color 0 255 255 ; up ; size 1"
for theta =0 to 2 *pi step 0.001 r =a *( 1 +0.9 *cos( 8 *theta))_ *( 1 +0.1 *cos( 24 *theta))_ *( 0.9 +0.1 *cos( 200 *theta))_ *( 1 +sin( theta)) if theta >0 then #wg "down" call plot r, theta print r, theta scan next theta
#wg "backcolor 0 0 0" ' this is colour to fill WITH targetcolor = 0 +255 *2^8 +255 *2^16 ' bu *2^16 +gn *2^8 this is colour to fill out TO ie desired border
x =1 y =1
calldll #gdi32, "ExtFloodFill", hdc as ulong,_ x as long, y as long,_ targetcolor as long,_ _FLOODFILLBORDER as long, result as long ' ie fill out with black 'til cyan is met.. so black surrounds.
call delay 1000
for i =0 to 999 CC =int( 360 *rnd( 1)) call hsv2rgb i /1000 *359, 0.99, 0.99 ' hue 0-359, saturation 0-0.99, value 0-0.99 ' alters global col$ #wg "backcolor "; col$ ' this is colour to fill WITH targetcolor = 0 +255 *2^8 +255 *2^16 ' bu *2^16 +gn *2^8 this is colour to fill out TO ie desired border
x =int( 1 +600 *rnd( 1)) y =int( 1 +600 *rnd( 1))
calldll #gdi32, "GetPixel", hdc as ulong, x as long, y as long, pixcol as ulong
if pixcol <>0 then calldll #gdi32, "ExtFloodFill", hdc as ulong,_ x as long, y as long,_ targetcolor as long,_ _FLOODFILLBORDER as long, result as long ' ie fill out 'til this colour is met.. scan end if
call delay 20 next i
#wg "getbmp scr 0 0 800 800" bmpsave "scr", "hash.bmp"
wait
sub plot r, theta #wg "goto "; 400 +r *cos( theta); " "; 660 -r *sin( theta) end sub
sub quit h$ calldll #user32, "ReleaseDC", hw as ulong, hdc as ulong, ret as void 'release the DCclose #h$ close #h$ end end sub
sub delay sleeptime calldll #kernel32, "Sleep", sleeptime as long, ret as void scan end sub
sub hsv2rgb h, s, v ' hue 0-360, saturation 0-1, value 0-1 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
function cosRad( t) cosRad =cos( t *pi /180) end function
function sinRad( t) sinRad =sin( t *pi /180) end function
|
|
|
Post by tsh73 on Nov 6, 2022 3:55:55 GMT -5
Now some ingenious application of color by B+ parametric plot -> polar plot (by atan2, sqr(x^2)+y^2) next, polar plot is scaled down to 0 while smoothly changing color to reddish one. These reddish srteaks looks very natural to me. EDIT now I remember seeing some stars colored in similar fashion. But I cannot remember keyword to find them
|
|