Advertisement
xeromino

rectcirc

Jun 13th, 2014
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.64 KB | None | 0 0
  1. /*
  2.  * Creative Coding
  3.  * Week 2, 04 - The Clocks
  4.  * by Indae Hwang and Jon McCormack
  5.  * Copyright (c) 2014 Monash University
  6.  *
  7.  * This program draws a grid of circular "clocks", whose hands move according to the elasped time.
  8.  * The higher the clock number the faster it moves, the first clock takes 1 min to go all the way around.
  9.  * The function "movingCircle" is used to draw each clock. It is passed the position, size and hand angle
  10.  * as arguments.
  11.  *
  12.  */
  13.  
  14. void setup() {
  15.   size(600, 600);
  16.   background(180);
  17.   rectMode(CENTER);
  18.   noStroke();
  19. }
  20.  
  21.  
  22. void draw() {
  23.   background(180);
  24.   noStroke();
  25.  
  26.   int num = 5;
  27.   int margin = 80;
  28.  
  29.   float gutter = 0; //distance between each cell
  30.   float cellsize = ( width - (2 * margin) - gutter * (num - 1) ) / (num - 1);
  31.  
  32.   int circleNumber = 0; // counter
  33.  
  34.   for (int i=0; i<num; i++) {
  35.     for (int j=0; j<num; j++) {
  36.       ++circleNumber;
  37.       //}
  38.       // {
  39.       float tx = margin + cellsize * i + gutter * i;
  40.       float ty = margin + cellsize * j + gutter * j;
  41.       boolean circ = true;  
  42.       if (i%2!=0) circ=false;
  43.       movingCircle(tx, ty, cellsize, circleNumber * TWO_PI * millis() / 60000.0, circ);
  44.     }
  45.   }
  46. }//end of draw
  47.  
  48. void movingCircle(float x, float y, float size, float angle, boolean circ) {
  49.  
  50.   // calculate endpoint of the line
  51.   float tempX = x + (size / 2) * sin(angle);
  52.   float tempY = y + (size / 2) * cos(angle);
  53.  
  54.   stroke(0);
  55.   strokeWeight(1);
  56.   fill(140, 180);
  57.   if (circ) {
  58.     ellipse(x, y, size, size); // circle
  59.   } else {
  60.     rect(x, y, size, size); // circle
  61.   }
  62.   stroke(255, 0, 0);
  63.   line(x, y, tempX, tempY); // red line
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement