Flower (a Processing sketch)

Not much to see here, just an ever-blooming flower in Processing.

Here is a screenshot, in case you can't see the Java applet below.

float thetaSpeed = 0.01;
ArrayList circles = new ArrayList();

class Circle {
  private float theta;
  private float radius;
  private float distance;
  private color col;

  public Circle( float theta, float radius, float distance, color col ) {
    this.theta = theta;
    this.radius = radius;
    this.distance = distance;
    this.col = col;
  }

  private float x() {
    return width / 2 + cos(theta) * distance;
  }

  private float y() {
    return height / 2 + sin(theta) * distance;
  }

  public boolean dead() {
    return x() + radius < 0 || x() - radius > width ||
           y() + radius < 0 || y() - radius > height;
  }

  public void update() {
    distance += 2;
    radius += .8;
    theta += thetaSpeed;
  }

  public void draw() {
    fill(col);
    ellipse( width / 2 + cos(theta) * distance,
             height / 2 + sin(theta) * distance,
             radius * 2,
             radius * 2 );
  }
}

void makeWave() {
  int count = 7;

  float thetaOffset = random( TWO_PI );
  for( int i = 0; i < count; i++ ) {
    circles.add( 0, new Circle( thetaOffset + i * TWO_PI / count, 0, 0, color( random(255), random(255), random(255) ) ) );
  }
}

void setup() {
  size( 1300, 700 );
  makeWave();
}

void draw() {
  noStroke();

  if( frameCount % 40 == 0 )
    makeWave();

  thetaSpeed = sin( frameCount / 400.0 ) * 0.01;

  for( int i = circles.size() - 1; i >= 0; i-- ) {
    Circle circle = (Circle) circles.get( i );

    if( circle.dead() ) {
      circles.remove( i );
    } else {
      circle.update();
      circle.draw();
    }
  }

  fill( #ffffff );
  ellipse( width / 2, height / 2, 40, 40 );
}

Did I level up with this post?


Comments

Click here to view the comments on this post, or just send me an e-mail.