Skip to content

Instantly share code, notes, and snippets.

@XiaohanYa
Created March 3, 2017 02:48
Show Gist options
  • Save XiaohanYa/18c43b16251b493c558dabe458f651a6 to your computer and use it in GitHub Desktop.
Save XiaohanYa/18c43b16251b493c558dabe458f651a6 to your computer and use it in GitHub Desktop.
Nature of code
var x;
var y = 1;
var xspeed, yspeed;
var gravity;
var mouseForce;
var randomSize;
var randomColor;
function setup() {
createCanvas(500, 600);
background(255);
x = width / 2;
y = height / 2;
gravity = 3;
//wallForce = 0.05;
xspeed = 3;
yspeed = 10;
//yspeed = gravity*y;
}
function draw() {
background(255);
if (mouseIsPressed) {
mouseForce = random(1, 10);
randomSize= random(50,100);
randomColor= random(0,255);
} else {
mouseForce = 0;
randomSize=50;
randomColor= 0;
}
if (y >= height || y <= 0) {
yspeed = yspeed * -1;
}
if (x >= width || x <= 0) {
xspeed = xspeed * -1;
}
yspeed = yspeed + gravity;
//xspeed = xspeed + wallForce;
x = x + xspeed + mouseForce;
y = y + yspeed - mouseForce;
if (y >= height) {
y = height;
}
if (x >= width) {
x = width;
}
noStroke();
fill(random(randomColor,255),random(randomColor,255),255-randomColor,200);
ellipse(x, y, randomSize, randomSize);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment