Created
January 27, 2015 13:06
-
-
Save CSchoel/c202d2fc2a8217f19b49 to your computer and use it in GitHub Desktop.
Use the mouse to catch the circle.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Musterlösung zu OOP Aufgabenblatt 1, Aufgabe 3 (WS 14/15) | |
//Autor: Christopher Schölzel | |
float x,y; //position | |
float r; //radius | |
void setup() { | |
size(300,300); | |
background(0); | |
x = width/2; | |
y = height/2; | |
r = 30; | |
noStroke(); | |
fill(255); | |
ellipse(x,y,r,r); | |
} | |
void draw() {} //nötig um Mausevents zu empfangen | |
//bestimmt ob ein Punkt im aktuellen Kreis liegt | |
boolean inCircle(float px, float py) { | |
float distance = sqrt(pow(x-px,2)+pow(y-py,2)); | |
return distance < r; | |
} | |
//bewegt den Kreis an eine zufällige Position | |
//und hinterlässt einen magentafarbenen Abdruck | |
void moveCircle() { | |
fill(255,0,255); | |
ellipse(x,y,r,r); | |
x = random(r,width-r); | |
y = random(r,height-r); | |
fill(255); | |
ellipse(x,y,r,r); | |
} | |
//wird ausgeführt, sobald die Maus sich bewegt | |
void mouseMoved() { | |
if(inCircle(mouseX,mouseY)) moveCircle(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment