Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** Your header comments go here to describe the class */
- class Snowflake {
- // the object's x-coordinate
- int x;
- // the object's y-coordinate
- // a parameter for tracking the ellapsed lifetime of the object, which can be used for animating it
- int t;
- /** Constructor
- * @param xCoordinate the initial x coordinate of the object
- * @param yCoordinate the initial y coordinate of the object
- */
- Snowflake (int xCoordinate) {
- x = xCoordinate;
- t = 0;
- }
- /** Draw the object.
- * This function should be called every iteration of draw() to display the object.
- */
- void draw() {
- // drawing code for your object, with an animation based on t
- //background(#EB74AC);
- fill(#A0FFC5);
- ellipse(x,t/2,5,5);
- step();
- }
- /** Advance the object's animation.
- * This function should be called every iteration of draw() to advance it's animation.
- */
- void step() {
- // increment the time counter
- t++;
- }
- }
- // The maximum number of objects that can be displayed at once
- int MAX_NUM_OBJECTS = 100;
- // An array of all the created objects
- Snowflake[] myObjects = new Snowflake[MAX_NUM_OBJECTS];
- // An index into the myObjects array to show where to save the next new object.
- // Note that this index cannot ever be allowed to exceed MAX_NUM_OBJECTS;
- // instead it should cycle from 0 to MAX_NUM_OBJECTS and then be reset to begin again at 0.
- int idxMyObjects = 0;
- /** Processing's setup function */
- void setup() {
- size(800,600);
- }
- /** The main drawing loop for Processing */
- void draw() {
- background(#A0FFC5); // NOTE: you are welcome to change this background
- // use a for loop to display all of the objects and advance their animations
- // NOTE: When writing this loop, you will need to test each element
- // of the myObjects array to see if it is an object or is empty.
- // Use the following code to test for an object:
- // if (myObjects[i] != null) { ... }
- // This example uses i as the loop variable; your implementation may
- // use something different.
- for(int i = 0; i < MAX_NUM_OBJECTS; i++)
- {
- if(myObjects[i] != null)
- {
- myObjects[i].draw();
- }
- }
- }
- void mousePressed() {
- // create a new object based on the location clicked
- // and store it into myObjects[idxMyObjects]
- myObjects[idxMyObjects] = new Snowflake(mouseX);
- // increment the index into myObjects, keeping it in the range 0...MAX_NUM_OBJECTS
- // NOTE: Make sure you understand how this line of code works!
- // It is complete as-is. You don't need to do anything else
- // to make the idxMyObjects counter work correctly.
- idxMyObjects = (idxMyObjects+1) % MAX_NUM_OBJECTS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement