Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////////////////////////////////////////////////////////////
- Helen, feel free to send me a msg (marzinp@free.fr) if you need more help.
- ///////////////////////////////////////////////////////////////////////////
- Ball []myballs;//global objects array
- void setup() {
- size(300, 300);
- myballs=new Ball[4];
- for (int i=0; i<4; i++) {
- myballs[i]=new Ball();//Ball objects instanciation (creation of an object according to the class constructor
- }
- }
- void draw() {// Processing looping method
- background(255);
- for (Ball myball : myballs) {
- myball.display();
- }
- }
- void mouseReleased() {//this method is special, it is fired by mouseReleased system event
- for (Ball myball : myballs) {
- myball.reactToMouse();
- }
- }
- //from here this is my class definition
- class Ball {
- float x, y;
- int diameter=20;
- Ball() {//Constructor
- x=random(width);
- y=random(height);
- }
- void display() {//display method
- ellipse(x, y, diameter, diameter);
- }
- void reactToMouse() {//event answer method cannot be triggered directly, it has to be called from the main program mouseReleased() method
- fill(random(255));
- x=random(width);
- y=random(height);
- display();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement