Built with blockbuilder.org
forked from Utopiah's block: P5JS with color testing
Built with blockbuilder.org
forked from Utopiah's block: P5JS with color testing
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | |
<html> | |
<head> | |
<title>p5js Template</title> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.4.13/p5.js"></script> | |
<script> | |
var x, y, xSpeed, ySpeed; | |
function setup() { | |
createCanvas(886,348); | |
x = random(width); | |
y = random(height); | |
xSpeed = 3; | |
ySpeed = 3; | |
} | |
function draw() { | |
background(100); | |
stroke(color('#f00')); | |
strokeWeight(4); | |
noFill(); | |
ellipse(x,y,20,20); | |
if(x < 0 || x > width){ | |
xSpeed *= -1; | |
} | |
if(y < 0 || y > height){ | |
ySpeed *= -1; | |
} | |
x = x + xSpeed; | |
y = y + ySpeed; | |
} | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |