I'm using P5.js and the Perlin noise()
function to try and draw a circle with Perlin noise generated x
and y
coordinates. I don't get any error messages but nothing is drawn on the canvas. What am I doing wrong?
let width;
let height;
function setup() {
createCanvas(windowWidth, windowHeight);
width = windowWidth;
height = windowHeight;
}
var Circle = function () {
this.x = width / 2;
this.y = height / 2;
this.tx = 0;
this.ty = 0;
};
Circle.prototype.display = function () {
stroke(0);
ellipse(this.x, this.y, 200, 200);
};
Circle.prototype.walk = function () {
this.x = map(noise(this.x), 0, 1, 0, width);
this.y = map(noise(this.y), 0, 1, 0, height);
this.tx += 0.01;
this.ty += 0.01;
};
var c = new Circle();
function draw() {
c.walk();
c.display();
}
<html>
<head>
<meta charset="UTF-8">
<script language="javascript" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/p5.js"></script>
<script language="javascript" type="text/javascript" src="sketch.js"></script>
<style>
body {
padding: 0;
margin: 0;
}
</style>
</head>
</html>