import objectdraw.*;
import java.awt.*;

/*
 * 
 * Example FallingSnow: the cloud class which is responsible for
 * creating a bunch of snowflakes, but this time using
 * for loop for counting.
 *
 * Jim Teresco, Siena College, CSIS 120, Fall 2011
 * Based on example from CSCI 134, Williams College
 *
 * $Id: Cloud.java 1576 2011-03-24 04:32:40Z terescoj $
 */

public class Cloud extends ActiveObject {

    // total number of snowflakes
    private static final int MAX_SNOW = 150;
    // time between flakes
    private static final int FLAKE_INTERVAL = 900;

    // the canvas
    private DrawingCanvas canvas;

    // picture of a snowflake
    private Image snowPic;

    // used to generate random speeds and positions for snowflakes
    private RandomIntGenerator snowGen;

    public Cloud(Image aSnowPic, DrawingCanvas aCanvas) {

        // save the parameters for the "run" method
        canvas = aCanvas;
        snowPic = aSnowPic;
 
        snowGen = new RandomIntGenerator(0, canvas.getWidth());

        start();
    }

    public void run()
    {
        // continue creating snow until the maximum amount
        // has been created
        for (int snowCount = 0; snowCount < MAX_SNOW; snowCount++) {

            new FallingSnow(canvas, snowPic,
                            snowGen.nextValue(),   // x coordinate
                            snowGen.nextValue()*2/canvas.getWidth()+2); // y speed
            pause(FLAKE_INTERVAL);
        }
    }
}
