Advertisement
Guest User

w02_05

a guest
Jun 5th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.46 KB | None | 0 0
  1. /* (my variation, original from:)
  2.  * Creative Coding
  3.  * Week 2, 05 - Moving Patterns 1
  4.  * by Indae Hwang and Jon McCormack
  5.  * Copyright (c) 2014 Monash University
  6.  *
  7.  * This sketch builds on the previous sketches, drawing shapes based on the
  8.  * current framerate. The movement of individual shapes combine to create a
  9.  * gestalt field of motion. Use the arrow keys on your keyboard to change the
  10.  * frame rate.
  11.  *
  12.  */
  13.  
  14. // variable used to store the current frame rate value
  15. int frame_rate_value;
  16.  
  17. void setup() {
  18.   size(500, 500);
  19.  
  20.   frame_rate_value = 6;
  21.   frameRate(frame_rate_value);
  22.   rectMode(CENTER);
  23.   colorMode(HSB,255,100,100);
  24.   frame_rate_value = 14;
  25. }
  26.  
  27.  
  28. void draw() {
  29.  
  30.   background(#202020);
  31.  
  32.   int num = 30;
  33.   int margin = 0;
  34.   float gutter = 0; //distance between each cell
  35.   float cellsize = ( width - (2 * margin) - gutter * (num - 1) ) / (num - 1);
  36.  
  37.   int circleNumber = 0; // counter
  38.   for (int i=0; i<num; i++) {
  39.     for (int j=0; j<num; j++) {
  40.       circleNumber = (i * num) + j; // different way to calculate the circle number from w2_04
  41.  
  42.       float tx = margin + cellsize * i + gutter * i;
  43.       float ty = margin + cellsize * j + gutter * j;
  44.  
  45.       movingCircle(tx, ty, cellsize, circleNumber);
  46.     }
  47.   }
  48.  
  49.   //if (frameCount<29) saveFrame("image-###.gif");
  50.  
  51.  } //end of draw
  52.  
  53.  
  54. void movingCircle(float x, float y, float size, int circleNum) {
  55.  
  56.   float finalAngle;
  57.   finalAngle = frameCount + circleNum;
  58.  
  59.   //the rotating angle for each tempX and tempY postion is affected by frameRate and angle;  
  60.   float tempX = x + (size / 2) * sin(PI / frame_rate_value * finalAngle);
  61.   float tempY = y + (size / 2) * cos(PI / frame_rate_value * finalAngle);
  62.   int f = (int) map(tempY, 0, height, 0, 255);
  63.  
  64.   noStroke();
  65.   fill(f, 90, 90);
  66.   ellipse(tempX, tempY, size/5, size/5);
  67.   ellipse(tempX, tempY, 5, size*5);
  68. }
  69.  
  70.  
  71. /*
  72.  * keyReleased function
  73.  *
  74.  * called automatically by Processing when a keyboard key is released
  75.  */
  76. void keyReleased() {
  77.  
  78.   // right arrow -- increase frame_rate_value
  79.   if (keyCode == RIGHT && frame_rate_value < 60) {
  80.     frame_rate_value++;
  81.   }
  82.  
  83.   // left arrow -- decrease frame_rate_value
  84.   if ( keyCode == LEFT && frame_rate_value > 1) {
  85.     frame_rate_value--;
  86.   }
  87.  
  88.   // set the frameRate and print current value on the screen
  89.   frameRate(frame_rate_value);
  90.   println("Current frame Rate is: " + frame_rate_value);
  91. }
  92.  
  93. void mouseReleased() {
  94.   saveFrame("image-###.jpg");
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement