Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* (my variation, original from:)
- * Creative Coding
- * Week 2, 05 - Moving Patterns 1
- * by Indae Hwang and Jon McCormack
- * Copyright (c) 2014 Monash University
- *
- * 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);
- colorMode(HSB,255,100,100);
- frame_rate_value = 14;
- }
- void draw() {
- background(#202020);
- int num = 30;
- int margin = 0;
- float gutter = 0; //distance between each cell
- float cellsize = ( width - (2 * margin) - gutter * (num - 1) ) / (num - 1);
- 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 + gutter * i;
- float ty = margin + cellsize * j + gutter * j;
- movingCircle(tx, ty, cellsize, circleNumber);
- }
- }
- //if (frameCount<29) saveFrame("image-###.gif");
- } //end of draw
- void movingCircle(float x, float y, float size, int circleNum) {
- float finalAngle;
- finalAngle = frameCount + circleNum;
- //the rotating angle for each tempX and tempY postion is affected by frameRate and angle;
- float tempX = x + (size / 2) * sin(PI / frame_rate_value * finalAngle);
- float tempY = y + (size / 2) * cos(PI / frame_rate_value * finalAngle);
- int f = (int) map(tempY, 0, height, 0, 255);
- noStroke();
- fill(f, 90, 90);
- ellipse(tempX, tempY, size/5, size/5);
- ellipse(tempX, tempY, 5, size*5);
- }
- /*
- * 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++;
- }
- // 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);
- }
- void mouseReleased() {
- saveFrame("image-###.jpg");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement