-
Notifications
You must be signed in to change notification settings - Fork 8
Home
Forrest Oliphant edited this page Sep 29, 2015
·
11 revisions
// Draw a recursive space-filling curve:
var segmentLength = 15;
function unit(iteration) {
if (iteration > 0) {
unit(iteration - 1);
r(0.25);
unit(iteration - 1);
f(segmentLength);
unit(iteration - 1);
r(0.25);
unit(iteration - 1);
}
}
moveTo(30, 20);
turnTo(3/8);
unit(6);
f(segmentLength);
unit(6);
// golden spiral by 1/4 circle arcs
var PHI = (1 + Math.sqrt(5)) / 2;
function golden(scale){
var i = 0;
//moveTo(20, 20);
while( scale > 1 ){
var step = 0;
while (step < scale) {
f(1);
l(1/scale * 1/4);
step++;
}
scale = scale / PHI;
}
}
moveTo(300, 150);
for (var i=0; i<24; i++) {
golden(350);
r(3/4);
}
var swirl = function(steps, fac) {
for (var i=0; i<steps; i++) {
turnLeft(1/steps + i/steps*fac);
moveForward(5);
}
};
moveTo(200, 300);
// multiples of 3 are cool
swirl(9999, 666);
var swirl = function(steps, sides) {
for (var i=0; i<steps; i++) {
f(i);
l(1/sides + 0.0005);
}
};
swirl(1500, 5);
for(var i=0; i<10000; i++) {
turnLeft(0.1-Math.random()*0.2);
moveForward(1);
if (_position.x > 500) {
moveBy(-500, 0);
}
if (_position.y > 500) {
moveBy(0, -500);
}
if (_position.x < 0) {
moveBy(500, 0);
}
if (_position.y < 0) {
moveBy(0, 500);
}
}
Path doesn't overlap
var sides = 3;
var size = 300;
var thick = 60;
var colors = ['red', 'blue', 'green'];
for (var i=0; i<sides; i++) {
color(colors[i]);
f(size-thick*3);
l(1/sides);
f(size-thick);
l(1/sides);
f(size);
l(1/sides/2);
f(thick);
penUp();
l(1/sides);
f(size-thick);
r(1/sides);
f(size-thick*3);
l(1/2);
penDown();
}