Showing posts with label path. Show all posts
Showing posts with label path. Show all posts

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;



 



Thursday, August 24, 2017

Tennis ball curve function.

Tennis ball curve function. Returns a single point at (i) far along a curve in the shape of  the seam on a tennis ball.

function Tennis_ball_Curve(i)=let( 
b=360*i-sin(360*i*4)*25 ,
a=sin(360*i*2)*65)
[cos(a)*sin(b),cos(a)*cos(b),sin(a)] ;

for(i=[0:1/180:1]){
translate(Tennis_ball_Curve(i))sphere(0.02,$fn=30);
} 

Tuesday, August 22, 2017

Log spiral function

Log spiral function. Returns a single point at (a) far along a spiral curve defined by radius  number of turns and exponent for falloff. Both turns and exponent can be negative to positive numbers.


function L_Spiral (a,radius = 50,heigth,turns =  4,xpnt=0.685,start_angle=45)
= let( fx = xpnt<0?
pow(max(0,1-a),1/abs(min(-1,xpnt-1) )): pow(max(0,1-a),max(1,xpnt+1))   ) 
[(radius * fx ) * cos(start_angle+ a* turns*360*sign(turns)),
 (radius * fx ) * sin(start_angle+ a* turns*360*sign(turns)),a*heigth];

for(j=[0:1/60:1]){hull(){
 translate(L_Spiral (j, 50,-150,  4, 1.685, 0 ))sphere();
 translate(L_Spiral (j+1/60, 50,-150, 4, 1.685, 0 ))sphere();
}}
 
 

Thursday, June 8, 2017

Square / Rectangle Path

Generates a path in the shape of a rectangle .
Steps are rounded to evens for obvious reasons
Usage:


function figureL7(x=40,y=20,step=52)=
let(total=(x+x+y+y),steps_x=round(step/total*x),steps_y=round(step/total*y))
concat(
[for(t=[0:steps_x-1])[(-x/2+(x/steps_x)*t),y/2]],
[for(t=[0:steps_y-1])[x/2,y/2-((y/steps_y)*t)]],
[for(t=[0:steps_x-1])[x/2-((x/steps_x)*t),-y/2]],
[for(t=[0:steps_y-1])[-x/2,-y/2+(y/steps_y)*t]]);

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


polyline(close(figureL7()));
 
 

Circle Path

Generates a path in the shape of a circle

 
function circle(r=100,steps=100)=
[ for(t=[0:1/steps:1])
let(  x =r* sin(t*360),   y =r*cos(t*360)  )
[x,y] ];
// function close adds a last point equal yo the first
function close(p)= concat(p,[p[0]]);

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); } } polyline(close(circle()));

Wednesday, June 7, 2017

Figure Eight Path

Generates a path in the shape of figure eight


function figure8(m=100)=[for(t=[0:1:360])
let(scale = 2 / (3 - cos(2*t)),x =m* scale * cos(t),y =m* scale * sin(2*t) / 2)
[x,y]];

function close(p)= concat(p,[p[0]]);

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);
    }
}


polyline(close(figure8(50)));