Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Marzhan Kengessova
- Physical Computing
- Tutorial #3
- Part B
- February 9, 2016
- Animation is made of multiple lines forms circled animation with different
- bright colors. If you press mouse, background will change, if you press
- mouse again, background will change. I took animation code from previous my project
- from another course, so, right know I don't remember from where I took my baseic code,
- but it was modified.
- */
- float num, pathR, pathG, pathB;
- int backgroundColor = 0;
- boolean doOnce = true;
- void setup() {
- size(640, 640); //size of the canvas
- }
- void draw() {
- background(backgroundColor);
- translate(width/2, height/2); //mapping where to translate
- for (int i = 0; i < 360; i+=30) {
- float x = sin(radians(i+frameCount)) * 70; //radius of that circle x axis
- float y = cos(radians(i+frameCount)) * 90; //radius of that in y axis
- pushMatrix();
- translate(x, y);
- rotate(radians(-i)); //movement and rotation
- branch(75, i);
- popMatrix();
- }
- num+=0.05; //fastness of the animation
- }
- void branch(int l, int i) {
- float theta = sin(num)*110;
- ellipse(0, 0, 0, l); //line
- translate(0, l); //its mapping
- l *= 0.66;
- pathR = (((float)165/width)*mouseX+theta)+325*sin(i+num*2);
- pathG = (20+theta)+85*sin(i+num*6);
- pathB = (((float)35/height)*mouseY+theta)+8425*sin(i+num*7); //colors
- if (l > 3) { //fastness
- stroke(pathR, pathG, pathB); //stroke color
- pushMatrix();
- rotate(radians(theta)); //what to rotate
- branch(l, i);
- popMatrix();
- stroke(pathR, pathG, pathB); //stroke colors
- pushMatrix();
- rotate(-radians(theta)); //rotate in opposite way
- branch(l, i);
- popMatrix();
- } else {
- noStroke();
- fill(pathR, pathG, pathB); //else color and
- line(0, 0, 5, 5);
- }
- }
- void mousePressed() { //if mouse pressed, background will change
- if (doOnce && backgroundColor == 255) {
- backgroundColor = 0;
- doOnce = false;
- }
- if (doOnce && backgroundColor == 0) { //if mouse is pressed again, background change
- backgroundColor = 255;
- doOnce = false;
- }
- }
- void mouseReleased() {
- doOnce = true; //mouse released
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement