xxxxxxxxxx
54
var img1;
var img2;
var bot1;
var bot2;
function preload() {
img1 = loadImage("robot1.svg");
img2 = loadImage("robot2.svg");
}
function setup() {
createCanvas(720, 480);
bot1 = new Robot(img1, 90, 80);
bot2 = new Robot(img2, 440, 30);
}
function draw() {
background(204);
// Update and display first robot
bot1.update();
bot1.display();
// Update and display second robot
bot2.update();
bot2.display();
}
function Robot(img, tempX, tempY) {
// Set initial values for properties
this.xpos = tempX;
this.ypos = tempY;
this.angle = random(0, TWO_PI);
this.botImage = img;
this.yoffset = 0.0;
// Update the properties
this.update = function() {
this.angle += 0.05;
this.yoffset = sin(this.angle) * 20;
}
// Draw the robot to the screen
this.display = function() {
image(this.botImage, this.xpos, this.ypos + this.yoffset);
}
}
// https://editor.p5js.org/jht1493/sketches/8s8si6CU9
// Ex_10_99 Robot Objects
// https://github.com/lmccart/gswp5.js-code/blob/master/Robots/Robot08_Objects.js