xxxxxxxxxx
88
// thanks dan s for teaching me about random walkers in coding challange 52
// there are a bunch of functions that i can use to take a floating point
//number and convert it into a interger so take 3.4 for example
// if i use floor() it will turn it into 3
// if i use ceil() it will make it 4
// if i use the round () it will make it 3
// floor will just lop off the decimals and just leave you with the whole
//number
// ceil will go up to the nearest interger
// round will take the decimal into account and will actually round it
// a swtich statement is a kind of conditional statement liek an if statement
//but its more condensed
var x;
var y;
var img0;
var img1;
var bg;
var img_mask;
function preload(){
img0= loadImage("cross.png");
img1 = loadImage("pirouettehorse2 .jpg");
}
function setup() {
createCanvas(400, 400);
bg = loadImage('pirouettehorse2 .jpg');
img_mask = createImage(720, 400);
img_mask.loadPixels();
for (let x = 0; x < img_mask.width; x++) {
for (let y = 0; y < img_mask.height; y++) {
img_mask.set(x, y, [0, 0, 0, 255]);
}
}
img_mask.updatePixels();
}
//background (img1);
x = 200;
y = 200;
//}
function draw() {
background(bg);
// image(img0, x,y);
for (let x = img0; img< 400; x++) {
for (let y =img0; img0 < 400; y++) {
img_mask.set(x,y, [0, 0, 0, 0]);
}
}
image(img_mask, 0, 0)
image(img0, x,y);
var r = floor(random(4));
switch (r) {
case 0:
x= x+1;
break;
case 1:
x = x-1;
break;
case 2:
y= y+1;
break;
case 3:
y=y-1;
break;
}
}