xxxxxxxxxx
110
class Head {
constructor(w, h, numPoints = 10, sizeFactor = 0.08,
noiseMax = 0.8, showPoints = false) {
this.numPoints = numPoints;
this.noiseMax = noiseMax;
this.showPoints = showPoints;
this.inc = TWO_PI / numPoints;
this.zoff = random(100);
this.sizeMin = w * sizeFactor;
this.sizeMax = this.sizeMin * 3;
this.points = [];
this.x = random(this.sizeMax, width - this.sizeMax);
this.y = random(this.sizeMax, height - this.sizeMax);
this.rotation = random(0, TWO_PI);
}
drawing() {
let a = 0;
push();
translate(this.x, this.y);
rotate(this.rotation);
beginShape();
for (let i = 0; i < this.numPoints + 3; i++) {
a += this.inc;
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.sizeMin, this.sizeMax);
let x = r * cos(a);
let y = r * sin(a);
curveVertex(x, y);
this.points.push({"x": x, "y": y});
if (this.showPoints) {
strokeWeight(5);
point(x, y);
strokeWeight(1.5);
}
}
endShape();
pop();
}
drawLine() {
let p = random(this.points);
push();
translate(head.x + p.x, head.y + p.y);
beginShape();
curveVertex(0, 0);
let xoff = random(100);
let yoff = random(100);
let length = this.sizeMin;
for(let i = 0; i < 5; i++) {
let x = noise(xoff++) * length;
let y = noise(yoff++) * length;
curveVertex(x, y);
}
endShape();
pop();
}
}
let head;
function setup() {
createCanvas(170, 350, SVG);
head = new Head(width, height);
}
function draw() {
background(240);
stroke(0);
strokeWeight(1.5);
noFill();
frameRate(1);
// drawHead();
head.drawing();
// head.drawLine();
}
function keyPressed() {
if (key === 'p') {
head.showPoints = !head.showPoints;
}
if (key === 'r') {
head = new Head(width, height);
}
if (key === 's') {
save("test.svg");
}
}