xxxxxxxxxx
35
let bug;
function setup() {
createCanvas(480, 120);
background(204);
// Create object and pass in parameters
bug = new JitterBug(width/2, height/2, 20);
}
function draw() {
bug.move();
bug.display();
}
function JitterBug(tempX, tempY, tempDiameter) {
this.x = tempX;
this.y = tempY;
this.diameter = tempDiameter;
this.speed = 2.5;
this.move = function() {
this.x += random(-this.speed, this.speed);
this.y += random(-this.speed, this.speed);
}
this.display = function() {
ellipse(this.x, this.y, this.diameter, this.diameter);
}
}
// https://editor.p5js.org/jht1493/sketches/ls9cxovWM
// Ex_10_01 Make an Object
// https://github.com/lmccart/gswp5.js-code/blob/master/10_Objects/Ex_10_01.js