xxxxxxxxxx
63
/*
* Perlin noise walker
*/
// dot
var x;
var y;
var speed = 5;
// to use with Perlin noise
var xT;
var yT;
// Higher values give jerkier movement
// because we're moving thru perlin noise in bigger jumps
var timeSpeed = 0.005;
function setup() {
createCanvas(400, 400);
colorMode(HSB, 360, 100, 100);
background(0,0,0);
noStroke();
x = width/2;
y = height/2;
xT = random(0,100);
yT = random(0,100);
}
function draw() {
background(0, 0, 0, 0.05);
strokeWeight(10);
// Adjust x and y positions using perlin noise
x += map(noise(xT), 0, 1, -speed, speed);
y += map(noise(yT), 0, 1, -speed, speed);
// Increment perlin noise parameters so we get different values next frame
xT += timeSpeed;
yT += timeSpeed;
loopAround();
fill(270, 50, 100);
ellipse(x, y, 10, 10);
}
function loopAround(){
if (x > width){
x = 0;
}
if (x < 0){
x = width;
}
if (y > height){
y = 0;
}
if (y < 0){
y = height;
}
}