xxxxxxxxxx
63
let egg;
function setup() {
createCanvas(320, 360);
noLoop();
// frameRate(4);
}
function draw() {
egg = new PerlinEgg();
translate(20, 30);
background(255);
fill(0);
noStroke();
let factor = 1;
let posJit = {
x: width/30,
y: height/30
}
for(let i = 0; i < 4; i++) {
for(let j = 0; j < 4; j++) {
let xadj = map(noise(j * factor, i * factor),
0, 1, -posJit.x, posJit.x);
let yadj = map(noise(i * factor, j * factor),
0, 1, -posJit.y, posJit.y);
let posX = {
x: (j * 78 + 30) + xadj,
y: (i * 83 + 30) + yadj
}
egg.draw(posX);
}
}
save("petlja.jpg");
}
class PerlinEgg {
constructor() {
this.zoff = 0;
this.noiseMax = random(0.5, 0.8);
this.size = {w: 2, h: 70};
}
draw(pos) {
beginShape();
for(let a = 0; a < TWO_PI; a += 0.05) {
let xoff = map(cos(a), -1, 1, 0, this.noiseMax);
let yoff = map(sin(a), -1, 1, 0, this.noiseMax);
let r = map(noise(xoff, yoff, this.zoff),
0, 1, this.size.w, this.size.h);
let x = pos.x + 0.8 * r * cos(a);
let y = pos.y + r * sin(a);
vertex(x, y);
}
endShape(CLOSE);
this.zoff += 0.5;
}
}