Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Creative Coding
- * Week 2, 05 - Moving Patterns 1
- * by Indae Hwang and Jon McCormack
- * Copyright (c) 2014 Monash University
- *
- * version edited by Toby Berriman
- *
- * This sketch builds on the previous sketches, drawing shapes based on the
- * current framerate. The movement of individual shapes combine to create a
- * gestalt field of motion. Use the arrow keys on your keyboard to change the
- * frame rate.
- *
- */
- // variable used to store the current frame rate value
- int frame_rate_value;
- void setup() {
- size(500, 500);
- frame_rate_value = 6;
- frameRate(frame_rate_value);
- rectMode(CENTER);
- background(0);
- colorMode(HSB, 100);
- }
- void draw() {
- background(0);
- int num = 20;
- int margin = 0;
- float cellsize = ( width - (2 * margin) * (num - 1) ) / (num - 1);
- int col = 5;
- int circleNumber = 0; // counter
- for (int i=0; i<num; i++) {
- for (int j=0; j<num; j++) {
- circleNumber = (i * num) + j; // different way to calculate the circle number from w2_04
- float tx = margin + cellsize * i;
- float ty = margin + cellsize * j;
- movingCircle(tx, ty, cellsize, circleNumber, col);
- }
- col = (col+3) % 100;
- }
- } //end of draw
- void movingCircle(float x, float y, float size, int circleNum, int col) {
- float finalAngle;
- finalAngle = frameCount + circleNum;
- //the rotating angle for each tempX and tempY postion is affected by frameRate and angle;
- float tempX = x + (2.5 * size) * sin(PI / frame_rate_value * finalAngle);
- float tempX2 = x - (2.5 * size) * sin(PI / frame_rate_value * finalAngle);
- noFill();
- stroke(col,70,100);
- strokeWeight(2);
- beginShape();
- vertex(x,y);
- bezierVertex(tempX, y+(size/2), tempX2,y+(size/2),x,y+size);
- endShape();
- }
- /*
- * keyReleased function
- *
- * called automatically by Processing when a keyboard key is released
- */
- void keyReleased() {
- // right arrow -- increase frame_rate_value
- if (keyCode == RIGHT && frame_rate_value < 60) {
- frame_rate_value++;
- // set the frameRate and print current value on the screen
- frameRate(frame_rate_value);
- println("Current frame Rate is: " + frame_rate_value);
- }
- // left arrow -- decrease frame_rate_value
- if ( keyCode == LEFT && frame_rate_value > 1) {
- frame_rate_value--;
- // set the frameRate and print current value on the screen
- frameRate(frame_rate_value);
- println("Current frame Rate is: " + frame_rate_value);
- }
- if ( key == 's') {
- saveFrame("curvyThing-###.jpg");
- println("Screenshot saved.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment