Fun Shapes from Pedal Eq.


' Fun shapes from Pedal Eq.bas SmallBASIC 0.12.8 [B+=MGA] 2017-03-30
' inpired by Andy Amaya's screen shots and reference to Superformula
' Here is some experimenting with the pedal equation

randomize timer

func
fx(ra, mx, my, e)
'ra = radian angle
'mx, my multipliers of angle
'e exponent of pedal
'mx, my simple multipliers of the ra
fx = ( ( cos(mx * ra) ) ^ e + ( sin(my * ra) ) ^ e) ^ .5
end

sub
polarPlotter(x, y, ra, rdist, fillTF)
'x, y think of as the origin of the plot
'ra = radian angle
'rdist = radial distance from the "origin"
local l
l.x1 = x + rdist * cos(ra)
l.y1 = y + rdist * sin(ra)
if fillTF then line x, y, l.x1, l.y1 else circle l.x1, l.y1, 1 filled
end

scale = 200 : fillTF = 0
for
e = 2 to 10
for m1 = 1 to 10
for m2 = 1 to 10
if m1 <> m2 then
cls
color 11
'circle xmax/2, ymax/2, scale color 12 'for frame of reference red circle with radius 100
locate 1, 1 : ? "e = ";e;" m1 = ";m1;" m2 = ";m2
if rnd < .1 then
r = rnd ^ 2 : g = rnd ^ 2 : b = rnd ^ 2
for s = 200 to 0 step -1
cc = rgb(127+127*sin(r+cn), 127+127*sin(g*cn), 127+127*sin(b*cn))
cn += .1
color cc
for a = 0 to 2 * pi step .001
d = fx(a, m1, m2, e)
polarPlotter xmax/2, ymax/2, a, s * d, 0
next
showpage
next
else
for a = 0 to 2 * pi step .001
d = fx(a, m1, m2, e)
polarPlotter xmax/2, ymax/2, a, scale * d, fillTF
next
showpage
end if
delay 200
end if
next
next
next

Now with both midInk and Plasma fill methods and lightning fast thick line all shapes are beautifully filled:

' Fun shapes from Pedal Eq 2.bas SmallBASIC 0.12.8 [B+=MGA] 2017-04-06
' inpired by Andy Amaya's screen shots and reference to Superformula
' Here is some experimenting with the pedal equation

'2017-04-06 now using lightning fast thick line and
' 2nd color fill method, midInk along with Plasma method

randomize(timer)
const cx = xmax / 2
const cy = ymax / 2

func
rand(n1, n2)
local hi, lo
if n1 > n2 then hi = n1 : lo = n2 else hi = n2 : lo = n1
rand = (rnd * (hi - lo + 1)) \ 1 + lo
end


'ink the color that is percent between the first color and 2nd color
sub midInk(r1, g1, b1, r2, g2, b2, percent)
dr = (r2 - r1) / 100 : dg = (g2 - g1) / 100 : db = (b2 - b1) / 100
color rgb(r1 + dr * percent, g1 + dg * percent, b1 + db * percent)
end

'new kick butt fast tline!!!
sub tline(x1, y1, x2, y2, thick) 'this draws a little rectangle
local arr, r, dx, dy, perpA1, perpA2
dim arr()
r = thick/2
dx = x2 - x1
dy = y2 - y1
perpA1 = atan2(dy, dx) + pi/2
perpA2 = perpA1 - pi
arr << x1 + r * cos(perpA1) 'corner 1
arr << y1 + r * sin(perpA1)
arr << x2 + r * cos(perpA1) 'corner 2
arr << y2 + r * sin(perpA1)
arr << x2 + r * cos(perpA2) 'corner 3
arr << y2 + r * sin(perpA2)
arr << x1 + r * cos(perpA2) 'corner 4
arr << y1 + r * sin(perpA2)
arr << x1 + r * cos(perpA1) 'back to first corner
arr << y1 + r * sin(perpA1)
drawpoly arr filled
end

func
fx(ra, mx, my, e)
'ra = radian angle
'mx, my multipliers of angle
'e exponent of pedal
'mx, my simple multipliers of the ra
fx = ( ( cos(mx * ra) ) ^ e + ( sin(my * ra) ) ^ e) ^ .5
end

locate 1, 1 : ? "A moment..."
showpage
scale = 200 : fillTF = 0
while 1
e = rand(1, 15) : m1 = rand(1, 15) : m2 = rand(1, 15)
if m1 <> m2 then
cls
if rnd < .5 then 'randomly select fill method
cmode = 1 'plasma mode
r = rnd ^ 2 : g = rnd ^ 2 : b = rnd ^ 2 : cn = .1
ms = "Plasma"
else
cmode = 0 'midInk mode
r1 = rand(0, 255) : g1 = rand(0, 255) : b1 = rand(0, 255)
r2 = rand(0, 255) : g2= rand(0, 255) : b2 = rand(0, 255)
ms = "midInk"
end if
color 11 'label drawing
locate 1, 1 : ? "e = ";e;" m1 = ";m1;" m2 = ";m2;" Fill Method: ";ms
for s = 200 to 0 step -1
if cmode then
cc = rgb(127+127*sin(r*cn), 127+127*sin(g*cn), 127+127*sin(b*cn))
cn += .1
color cc
else
midInk r1, g1, b1, r2, g2, b2, s/2
end if
for a = 0 to 2 * pi+.011 step .01
d = fx(a, m1, m2, e)
x = int(cx + d * s * cos(a))
y = int(cy + d * s * sin(a))
if a = 0 then
lastx = x : lasty = y
else
tline lastx, lasty, x, y, 3 'gets most holes
lastx = x: lasty = y
end if
'showpage 'watch shapes being formed, very s l o w l y
next
next
showpage
'delay 200 'not needed
end if
wend