xxxxxxxxxx
61
let myScale = 0.01,
radius = 100.0;
nSteps = 150;
myLoopingNoiseArray = [];
var offscreenImg;
function setup() {
createCanvas(300, 400);
makeOffscreenImg();
}
function draw() {
background(0);
image(offscreenImg, 0, 0);
currStep = frameCount % nSteps;
var t = map(currStep, 0, nSteps, 0, TWO_PI);
var px = width/2.0 + radius * cos(t);
var py = width/2.0 + radius * sin(t);
noStroke();
fill(255);
ellipse(px, py, 7, 7);
noiseAtLoc = height - 100.0*noise(myScale*px, myScale*py);
myLoopingNoiseArray[currStep] = noiseAtLoc;
noFill();
stroke(255);
beginShape();
for (i=0; i<nSteps; i++) {
nx = map(i, 0, nSteps-1, 0, width);
ny = myLoopingNoiseArray[i];
vertex(nx, ny);
}
endShape();
noStroke();
fill(255);
ex = map(currStep, 0, nSteps-1, 0, width);
ellipse(ex, noiseAtLoc, 7, 7);
// Save frames for the purpose of
// making an animated GIF loop,
// e.g. with http://gifmaker.me/
// if ((frameCount >= nSteps) && (frameCount < (nSteps*2))) {
// saveFrame( "save/"+ nf(currStep, 3)+ ".jpg");
// }
}
// Stash an image of the noise field.
// Doing so is faster than recomputing it every frame.
function makeOffscreenImg() {
offscreenImg = createGraphics(width, width);
// offscreenImg.beginDraw();
for (x = 0; x<width; x++) {
for (y = 0; y<width; y++) {
offscreenImg.stroke(255.0*noise(myScale*x, myScale*y));
offscreenImg.point(x, y);
}
}
}