Friday, June 22, 2018

Flower Shape Path / Spirograph

Generates a path in the shape of a Spirograph flower.
Compounding rotations. 
Self intersecting path for most values.
Usage:



function flower(r1=100,r2,r3,v1,v2 ,steps=200)=
[ for(t=[0:1/steps:1])

let(
x =r1* sin(t*360) +r2* sin(t*v1*360)+r3* sin(t*v2*360),  
y =r1*cos(t*360) +r2*cos(t*v1*360)  +r3*cos(t*v2*360)   )
[x,y] ];
// function close adds a last point equal yo the first

function close(p)= concat(p,[p[0]]);
 
function rnd(a = 1, b = 0, s = []) = s == [] ? 
(rands(min(a, b), max(
  a, b), 1)[0]) : (rands(min(a, b), max(a, b), 1, s)[0]);
function un(v) = v / max(1e-15, norm(v));
 
color(un([round(rnd(3)) ,round(rnd(3))  *0.75 ,round(rnd(3))  ])) {
paramas=[
70,rnd(30),rnd(15),
round(rnd(3,17))*(round(rnd(-1,1))==1?1:-1),
round(rnd(3,20)*(round(rnd(-1,1))==1?1:-1))  ,300];
echo(paramas);
p=close(flower(paramas[0],paramas[1],paramas[2],
paramas[3],paramas[4],paramas[5],paramas[6]));
  
polygon(p);
}
 

Wednesday, June 13, 2018

Flower Shape Path / Fourier series

Generates a path 
in the shape of a Fourier series flower.
Compounding random amplifications for each octave.
random number of octaves and repeating symmetries 
Non Self intersecting path for any values. 


Usage:


function FlowerF(r=100,isteps=5,w,a,h=2,h2)=
let(steps=min(isteps*w,300))
[  for(t=[0:1/steps:1])
let( r2= r*1.05+vsum([
for (k = [h2:h:max(9,22-w)])     a[k]*(sin(k*t*w*360)/k)*r] ),
  x =r2* sin(t*360), 
 y =r2* cos(t*360)  )
[x,y] ];




module polyline(p) {for(i=[0:max(0,len(p)-2)])line(p[i],p[i+1]);}
module line(p1, p2 ,width=0.5) 
{
    hull() {
        translate(p1) sphere(width);
        translate(p2) sphere(width);
    }
}

a=concat([rnd(0.5),rnd(0.75)],[for (k = [0:1:30])rnd(1)]);
p= (FlowerF(100,200,
    round(rnd(0,3))*2+1,a,
     min(2,round(rnd(1,3))),min(2,round(rnd(1,3)))));
 
polygon(p); 
//polyline(p); 
// function close adds a last point equal yo the first function close(p)= concat(p,[p[0]]); function rnd(a = 1, b = 0, s = []) = s == [] ? (rands(min(a, b), max( a, b), 1)[0]) : (rands(min(a, b), max(a, b), 1, s)[0]); function vsum(l) = len(l) > 0 ? [ for(li=l) 1 ] * l : undef;