Skip to content

Instantly share code, notes, and snippets.

@hanneshier
Last active August 29, 2015 14:15
Show Gist options
  • Save hanneshier/07f15f57ddc1b65d649d to your computer and use it in GitHub Desktop.
Save hanneshier/07f15f57ddc1b65d649d to your computer and use it in GitHub Desktop.
changeableBall
boolean directionX; // true = rechts; false = links
boolean pause; // true = pause; false = ingame
int speedX = 3;
int ballSize = 100;
int positionX = ballSize;
int colourR = round(random(255));
int colourG = round(random(255));
int colourB = round(random(255));
void setup() {
size(displayWidth, displayHeight);
frame.setResizable(true);
noStroke();
ellipseMode(CENTER);
textSize(12);
}
void draw() {
background(1);
fill(colourR, colourG, colourB);
ellipse(positionX, height/2, ballSize, ballSize);
if (directionX) {
positionX += speedX;
} else {
positionX -= speedX;
}
if (positionX+ballSize/2 > width || positionX-ballSize/2 < 0) {
directionX = !directionX;
println(directionX);
}
text("Speed "+speedX, 40, 40);
text("Size "+ballSize, 40, 60);
}
void mouseClicked() {
if (mouseButton == LEFT) {
speedX += (speedX < 0) ? -1 : 1;
}
println (speedX);
if (mouseButton == RIGHT) {
speedX += (speedX > 0) ? -1 : 1;
}
}
void mouseWheel (MouseEvent event) {
float e = event.getCount();
ballSize += e;
ballSize = min(ballSize, height);
ballSize = max(ballSize, 10);
println(ballSize, e);
}
void keyPressed() {
if(key == 'c') {
colourR = round(random(255));
colourG = round(random(255));
colourB = round(random(255));
}
if(key == 'p') {
if (pause) {
loop();
} else {
noLoop();
}
pause = !pause;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment