xxxxxxxxxx
183
let phi;
function setup() {
createCanvas(700, 700);
angleMode(DEGREES);
phi = (1+sqrt(5))/2;
}
function penrose(r,d=0,s=[],t=[1,2,3,4,5]) {
if (d < 0) {
return;
} else if (d == 0) {
beginShape();
for (let i = 0; i < 5; i++) {
let x = r * cos(72*i);
let y = r * sin(72*i);
vertex(x,y);
}
endShape(CLOSE);
} else {
for (let i of s) {
push();
rotate(72*i);
translate(-r/phi,0);
rotate(180);
penrose(r/phi, d-1, [1,4], [0]);
pop();
}
for (let i of t) {
push();
rotate(72*i);
translate(r/phi,0);
penrose(r/phi**2, d-2, [0], [0,1,4]);
pop();
}
push();
rotate(180);
penrose(r/phi**2, d-2, [], [0,1,2,3,4]);
pop();
}
}
function ammann(r,d=0,s=[],t=[1,2,3,4,5]) {
if (d < 0) {
return;
} else if (d == 0) {
r /= 1.23; // ?
beginShape();
for (let i = 0; i < 5; i++) {
if (s.indexOf(i) >= 0)
continue;
let x1 = r * cos(72*i+108);
let y1 = r * sin(72*i+108);
vertex(x1,y1,true);
let x2 = r * cos(72*i-108);
let y2 = r * sin(72*i-108);
vertex(x2,y2,false);
}
endShape();
} else {
for (let i of s) {
push();
rotate(72*i);
translate(-r/phi,0);
rotate(180);
ammann(r/phi, d-1, [1,4], [0]);
pop();
}
for (let i of t) {
push();
rotate(72*i);
translate(r/phi,0);
ammann(r/phi**2, d-2, [0], [0,1,4]);
pop();
}
push();
rotate(180);
ammann(r/phi**2, d-2, [], [0,1,2,3,4]);
pop();
}
}
function ammann2(r,d=0,s=[],t=[1,2,3,4,5]) {
if (d < 0) {
return;
} else if (d == 0) {
r /= 1.23; // ?
beginShape();
for (let i = 0; i < 5; i++) {
// if (s.indexOf(i) >= 0)
// continue;
let x1 = r * cos(72*i+36);
let y1 = r * sin(72*i+36);
vertex(x1,y1,true);
let x2 = r * cos(72*i+72+36);
let y2 = r * sin(72*i+72+36);
vertex(x2,y2,false);
}
endShape();
} else {
for (let i of s) {
push();
rotate(72*i);
translate(-r/phi,0);
rotate(180);
ammann2(r/phi, d-1, [1,4], [0]);
pop();
}
for (let i of t) {
push();
rotate(72*i);
translate(r/phi,0);
ammann2(r/phi**2, d-2, [0], [0,1,4]);
pop();
}
push();
rotate(180);
ammann2(r/phi**2, d-2, [], [0,1,2,3,4]);
pop();
}
}
function draw() {
let r = width*150/400;
translate(width/2, height/2);
rotate(-90);
strokeWeight(2.5);
background(255);
let d = 6;
fill(255,255,255);
penrose(r,d-1);
for (let i of [0,1,2,3,4]) {
push();
rotate(72*i);
translate(-r,0);
penrose(r/phi, d-2, [1,4], [0]);
pop();
}
d -= 1;
push();
d--;
noFill();
stroke('orange');
// stroke('thistle');
strokeWeight(3);
ammann2(r,d-1);
for (let i of [0,1,2,3,4]) {
push();
rotate(72*i);
translate(-r,0);
ammann2(r/phi, d-2, [1,4], [0]);
pop();
}
d++;
pop();
push();
noFill();
stroke('orange');
strokeWeight(3);
ammann(r,d);
for (let i of [0,1,2,3,4]) {
push();
rotate(72*i);
translate(-r,0);
ammann(r/phi, d-1, [1,4], [0]);
pop();
}
pop();
noLoop();
}