xxxxxxxxxx
70
amp = 40; //amplitude of wave
let xoff = 0; //variable for noise() function
let x; //x position
let y; //y position
let period = 20; //period of sin wave
function setup() {
createCanvas(600, 600);
}
function draw() {
randomSeed(5);
// background(255);
noFill();
frameRate(10);
//orient the canvas about the origin width/2, height/2
translate(width/2, height/2);
//draw the shape 5 times at random x, y positions
for (let e = 0; e < 5; e++){
x = random(-250, 250);
y = random(-250, 250);
squiggles(x,y);
}
// noLoop(); //maintains a still image
}
function squiggles(x, y) {
stroke(205, 32, 1);
strokeWeight(0.75);
translate(x, y);
//draw 16 waves that each rotate about point (x, y)
for (let j = 0; j < 16; j++) {
beginShape();
rotate(PI/8); //rotate by PI/8 in each iteration
//draws one wave
for (let i = -800; i < 800; i++) {
//calculates the y position of each point on the sin wave
y= noise(xoff) * amp * sin(i/(period));
//draws for every point on the curve
vertex(i, y);
//increment after each point is drawn so we get different noise values (larger increment = faster movement)
xoff+=0.00001;
}
endShape();
}
//same as above with slightly different rotation
//second "layer" adds dimension and some overlapping lines
for (let j = 0; j < 12; j++) {
beginShape()
rotate(PI/12);
for (let i = -800; i < 800; i++) {
y= noise(xoff) * amp * sin(i/(period));
vertex(i, y);
xoff+=0.00001;
}
endShape();
}
}