shiv379

Creative Coding wk2_05

Aug 17th, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.58 KB | None | 0 0
  1. /*
  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.  * version edited by Toby Berriman
  8.  *
  9.  * This sketch builds on the previous sketches, drawing shapes based on the
  10.  * current framerate. The movement of individual shapes combine to create a
  11.  * gestalt field of motion. Use the arrow keys on your keyboard to change the
  12.  * frame rate.
  13.  *
  14.  */
  15.  
  16. // variable used to store the current frame rate value
  17. int frame_rate_value;
  18.  
  19. void setup() {
  20.   size(500, 500);
  21.  
  22.   frame_rate_value = 6;
  23.   frameRate(frame_rate_value);
  24.   rectMode(CENTER);
  25.   background(0);
  26.   colorMode(HSB, 100);
  27. }
  28.  
  29.  
  30. void draw() {
  31.  
  32.   background(0);
  33.  
  34.   int num = 20;
  35.   int margin = 0;
  36.   float cellsize = ( width - (2 * margin) * (num - 1) ) / (num - 1);
  37.   int col = 5;
  38.      
  39.   int circleNumber = 0; // counter
  40.   for (int i=0; i<num; i++) {
  41.     for (int j=0; j<num; j++) {
  42.       circleNumber = (i * num) + j; // different way to calculate the circle number from w2_04
  43.  
  44.       float tx = margin + cellsize * i;
  45.       float ty = margin + cellsize * j;
  46.      
  47.       movingCircle(tx, ty, cellsize, circleNumber, col);
  48.     }
  49.   col = (col+3) % 100;
  50.   }
  51. } //end of draw
  52.  
  53.  
  54. void movingCircle(float x, float y, float size, int circleNum, int col) {
  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 + (2.5 * size) * sin(PI / frame_rate_value * finalAngle);
  61.   float tempX2 = x - (2.5 * size) * sin(PI / frame_rate_value * finalAngle);
  62.  
  63.  
  64.   noFill();
  65.   stroke(col,70,100);
  66.   strokeWeight(2);
  67.   beginShape();
  68.     vertex(x,y);
  69.     bezierVertex(tempX, y+(size/2), tempX2,y+(size/2),x,y+size);
  70.   endShape();
  71.  
  72. }
  73.  
  74.  
  75. /*
  76.  * keyReleased function
  77.  *
  78.  * called automatically by Processing when a keyboard key is released
  79.  */
  80. void keyReleased() {
  81.  
  82.   // right arrow -- increase frame_rate_value
  83.   if (keyCode == RIGHT && frame_rate_value < 60) {
  84.     frame_rate_value++;
  85.       // set the frameRate and print current value on the screen
  86.   frameRate(frame_rate_value);
  87.   println("Current frame Rate is: " + frame_rate_value);
  88.   }
  89.  
  90.   // left arrow -- decrease frame_rate_value
  91.   if ( keyCode == LEFT && frame_rate_value > 1) {
  92.     frame_rate_value--;
  93.       // set the frameRate and print current value on the screen
  94.   frameRate(frame_rate_value);
  95.   println("Current frame Rate is: " + frame_rate_value);
  96.   }
  97.  
  98.  if ( key == 's') {
  99.    saveFrame("curvyThing-###.jpg");
  100.    println("Screenshot saved.");
  101.  }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment