/*Jeremy Turner (JOT) Assignment A2-13 #200024742 Program your moving elements from A2-09 but use classes to represent the two visual elements.*/ //Thanks to Pooya and Veronika for helping me figure out this assignment. //Please give Veronika bonus points for showing me how to organize a class properly... //I think I finally figured it out. float i = (PI/2); //GLOBAL VARIABLES float j = random(536.0); //had to convert from ints to float numbers to randomize. float pos1 = (33); //I have used these 2 ints to be randomized... //I learned about the use of these int and float declarations... //..from both the previous assignment steps and Pooya's //..after-class lecture. float pos2 = (300); //I figure out that I can use the float positions... //...as the fields where I can insert the random movement... //one moves at float pos3 = random(PI); float pos4 =random(PI); float sc = random(88); void setup() //now that the properties are contained in classes { //...I can start with void setup instead of int/float //...declarations.. size(536, 333); strokeWeight(8); frameRate(11); smooth(); } class myTrickyEllipse { //I am going to follow Veronika's suggestion... //of custom naming all my class objects with "my" in front it... //...to help me remember that I am dealing with a class. float sc = random(88); //These are my fields/properties for this class (word means the same thing?...) float pos1 = (33); float i = (PI/2); float j = random(536.0); float ang1 = radians(i); // convert degrees to radians float ang2 = radians(j); // convert degrees to radians float pos4 = width/random(PI) + (sc * cos(ang1)); //fortunately, my Ellipse happens to include all of my messy float declarations. void drawMyTrickyEllipse() //I am adding the full title to this //method call since "drawMe" confuses me and I will mix up //different shape classes if I called every class drawing function "drawMe". { //the content that is usually filled in the generic void draw return call is now here... fill(random(255),7,66); ellipse(pos1,pos4,pos4, pos1); } } class myCyberTriangle { //this is the class for my fancy named triangle float sc = random(88); float i = (PI/2); float j = random(536.0); float pos3 =random(PI); //pos 1 & 2 are removed from pasting the code for the Ellipse class as the Triangle only uses pos3 float ang1 = radians(i); // convert degrees to radians float ang2 = radians(j); // convert degrees to radians //Originally pos 4 would be here without classes but I never drew the triangle //..with pos4 so it has been removed from my properties/fields segment of the class... void drawMyCyberTriangle () //this draw up my triangle with its fill colour... { float pos3 = height/random(2) + (sc * sin(ang1)); fill(random(255), 66, 44); triangle(pos3, 200, pos3, 330, 360, 400); } } void draw () //back to the regular drawing function to draw both the ellipse and triangle... { background (59, 17,152); //background in draw to remove shape tracers now that the shapes have been isolated into their respective classes. myTrickyEllipse ellipse1=new myTrickyEllipse(); //this renaming allows me to only type "ellipse" instead of "myTrickyEllipse" //this saves me some keystrokes. //this is the most confusing part of classes //...and might take me a week after this is done... //to absorb this syntax intuitively. myCyberTriangle triangle1=new myCyberTriangle(); // now "cybertriangle1" is my shortcut title. ellipse1.drawMyTrickyEllipse(); //this is telling the draw function to draw a single ellipse from this custom class. triangle1.drawMyCyberTriangle(); //this is telling the draw function to draw a single triangle from this custom class. } //NOTE ABOUT BELOW: I now realize that these are junk variables but I only can see this clearly now that everything... //is in its own class..now I understand why I need to make discrete classes. //i += 33; //j -= PI/4; //if(i > 536) { //i = 500; //j = 88; // } //I changed the numbers of the if statement above to ensure that ... //I was still within the numerical limits of "i"