.

 

Red Rotator

Left, right, up, down, click.

  
/* Draws a pile of candycane-colored squares that
spin above one another. Mouse moves the squares
off the center; clicking turns the squares into
circles. By Paul Ford, ford@ftrain.com, who is
learning. GPL copyright 2003. */

float b;
int press=0;
int squareno=12;

void setup() {
  size(200, 200);
  background(0);
  rectMode(CENTER_DIAMETER);
  ellipseMode(CENTER_DIAMETER);
}

void loop() {
  // Normalize mouse coordinates to be
  // the absolute value of the mouse's
  // distance from the center of the grid
  float normalX=abs(width/2-mouseX);
  float normalY=abs(height/2-mouseY);

  // And make 0,0 the same location
  translate(width/2,height/2,0);

  //Draw squareno's worth of squares
  for (int i=0;i<=width;i+=width/squareno){
    //Set up an incrementer called b that 
    //is used to se the angle of rotation.
    b+=0.00002;
    if(b >= PI*4) {
      b=0;
    }
    //Normalize the fill color.
    int fill=int(255 * i/width);
    smooth();
    noStroke();
    push();
    //Rotate each square by its place
    //in the stack of squares (i)
    //and by the status of the rotator (b).
    rotateZ(i*b*2);

    //Move things around according
    //to the mouse, and set the increasing Z axis
    //of each square.
    translate(normalX/4,normalY/4,i/10);

    // Draw a rectangle if the mouse is up, an
    // ellipse if it's down.
    if (press==0) {
      fill(fill);
      rect(0,0,width+width/20-i,width+width/20-i);
      fill(fill-20,0,0);
      rect(0,0,width-i,width-i);
    }
    else {
      fill(fill);
      ellipse(0,0,width+width/20-i,width+width/20-i);
      fill(fill-20,0,0);
      ellipse(0,0,width-i,width-i);
    }
    pop();
  }
}

void mousePressed() {
  press=1;
}
void mouseReleased() {
  press=0;
}

Built with Processing.


[Top]

Ftrain.com

PEEK

Ftrain.com is the website of Paul Ford and his pseudonyms.

There is a Facebook group.

And six-words-only Twitter posts.

See also: Gary Benchley, Rock Star, a novel; Harper's Magazine; NPR's All Things Considered; The Morning News.

POKE


Syndicate: RSS1.0, RSS2.0
Links: RSS1.0, RSS2.0

Contact

© 1974-2007 Paul Ford

Recent

I'm on a Panel at SxSW. (March 8)

Elsewhere: Just Like Heaven. (January 11)

But melts just like a little girl. (August 26)

Panel/Unicode table for you. (August 21)

Been a while. (February 16)

Learning to Fear the Semantic Web, by Paul Ford. (October 15)

Fixed. (September 18)

NYU. (September 18)

Also. (September 11)

Steering Wheel. (September 11)

I never told you because I was kind of out of it for a while there but. (April 1)

Sasquatch. (March 26)

Over There. (March 24)

Signs. (March 21)

Eloquence Personified. (March 20)

Note. I wonder what the poor folks are doing tonight. (March 20)

The Wind Chest, by Paul Ford. (March 18)

Six-Word Reviews of 763 SXSW Mp3s. (March 13)

This Is Just To Say. (March 3)

Clouds. (February 27)

More...
Tables of Contents