Polygon code: Rotating shapes
Base code: Willmott squares
Log in to post a comment.
Canvas.setpenopacity(1);
let num_sides = 4; // min=2, max=25, step=1
let shapes_per_size = 40; //min=10, max=100, step=5
let base_shift = 0; // min=0, max=360, step=10
let cos_scalar = 100; // min=0, max=360, step=10
let freq_scalar = 10; // min=0, max=360, step=10
// You probably want to use 1, 2, or 100 for this. IE L1, L2, and approx Linfinity
let norm = 2; // min=0, max=100, step=2
// Global code will be evaluated once.
const turtle = new Turtle();
turtle.radians();
turtle.penup();
turtle.goto(-50,-20);
turtle.pendown();
const width=195;
const height=195;
const shape_spacing=width/(shapes_per_size);
const shape_size=width/(shapes_per_size);
const minX=-(width)/2 ;
const minY=-(height)/2;
function draw_poly(x,y,t, c, r, a) {
const side = 2*Math.sin(Math.PI/c) * r;
t.penup();
t.goto(x,y);
t.setheading(a);
t.forward(r);
t.setheading(a+Math.PI/2);
t.pendown();
t.right(Math.PI/c);
for (let i=0; i<c; i++) {
t.forward(side);
t.right(Math.PI*2/c);
}
}
// The walk function will be called until it returns false.
function walk(i) {
for(let y=0;y<shapes_per_size;++y) {
for(x=0;x<shapes_per_size;++x) {
x_coord = minX+x*shape_spacing+shape_spacing/2
y_coord = minY+y*shape_spacing+shape_spacing/2
x_norm = Math.pow(x_coord, norm)
y_norm = Math.pow(y_coord, norm)
// Between 0-1 of how far away it is
coord_norm = Math.pow(x_norm+y_norm, 1/norm)/200
angle = base_shift+cos_scalar*Math.cos(coord_norm*freq_scalar)
angle = 2*Math.PI*(angle/360)
draw_poly(x_coord, y_coord, turtle, num_sides, shape_size/1.5, angle)
}
}
return false;
}