// CSC220F19DemoD_ClassArray Parson's csc120 recap Avatar1 [] av1 = new Avatar1 [57]; // setup() called once at the start of Run void setup() { size(800, 700); // At a minimum set display window size in setup(). frameRate(60); // Must be explicit in newer Macs after setting size. rectMode(CENTER); ellipseMode(CENTER); for (int i = 0 ; i < av1.length ; i++) { av1[i] = new Avatar1(int(random(0,width)), int(random(0, height))); } } // draw() is called in a loop at the frameRate, defaults to once every 60th sec. void draw() { background(255, 255, 0); // screen color, use Tools -> Color Selector, RGB for (int i = 0 ; i < av1.length ; i++) { av1[i].display(); // function call to the display() function to display avatar av1[i].move(); } } class Avatar1 { int elx, ely ; int exspeed, eyspeed ; int ewidth = 75, eheight = 50 ; Avatar1(int initialx, int initialy) { // constructor for a class builds an object of that class elx = initialx ; ely = initialy ; exspeed = round(random(1,10)) ; eyspeed = -3 ; } void display() { pushMatrix(); translate(elx, ely); // display my avatar stroke(0, 0, 255); // Sets stroke around shapes, alternatively noStroke() fill(255, 128, 0); // Sets fill within closed shape, alternatively noFill() ellipse(0, 0, ewidth, eheight); // X, Y, Ewidth, Eheight stroke(0); fill(255); rect(0, 0, ewidth/2, eheight/2); popMatrix(); } void move() { // move my avatar elx = elx + exspeed ; ely += eyspeed ; if (elx > width+ewidth) { // if horizontal loc is off right side of display exspeed = - exspeed ; // reverse direction } else if (elx < 0-ewidth) { // if horizontal loc is off left side of display exspeed = - exspeed ; } if (ely < 0-eheight || ely > height+eheight) { // if vertical off top or bottom eyspeed = - eyspeed ; } } }