Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // import le libraries
- import ddf.minim.*;
- Minim minim;
- AudioPlayer bmusic;
- int w = 1000; // width of window
- int h = 500; // hight of window
- int diagonale = (int) Math.sqrt((w * w) + (h * h));
- int r = 25; // r>4 velikost malega ฤrnega krogca
- int bgRed = 255, bgGreen = 255, bgBlue = 255;
- int circlesVertically = h / (2 * r);
- int circlesHorizontally = w / (2 * r); // variables, number of lattice points needed to fill the drawing area horizontally and vertically
- int mousePressX, mousePressY;
- float k = 0; // counter variable for the animation
- float kIncrement = 0.15f; // how slowly are the black dots turning (i.e. how many waves are there) SPEED
- float dotSize = 25; // size of dots
- // limits of enlarging and shrinking the dots
- int dotSizeMin = 5, dotSizeMax = 2*r;
- float maxRad = PI*2, thisRadiant, thisAngleToTop, thisBackgroundVariant;
- PVector mousePos = new PVector(0, 0);
- float pull = 0;
- void setup(){
- minim = new Minim(this);
- //bmusic = minim.loadFile("rainforest_ambience.wav");
- //bmusic.play();
- size(w, h);
- smooth();
- frameRate(24);
- }
- void draw() {
- background(255);
- for (int i = 0; i < circlesHorizontally; i++) { // i and j are the phases shift of each point
- for (int j = 0; j < circlesVertically; j++) {
- int circleX = (2 * i + 1) * r; // circleX and circleY coordinates of the each circle
- int circleY = (2 * j + 1) * r;
- // white background circles
- fill(bgRed, bgGreen, bgBlue);
- stroke(128, 128, 128);
- ellipse(circleX, circleY, 2*r - 4, 2*r - 4); // you draw these circles
- // calculate this black circle's deviation from it's white background circle
- thisRadiant = radians((i+j+k) * 15);
- if (thisRadiant > maxRad) {
- thisRadiant = thisRadiant % maxRad; // bring the radians back to a maximum of 2*PI
- }
- thisAngleToTop = abs(thisRadiant - PI);
- thisBackgroundVariant = (thisAngleToTop % PI) / PI;
- if (round(thisAngleToTop * 100) == 314) { // check if the deviation is exacly PI (3.14)
- thisBackgroundVariant = 1;
- }
- int blackCircleX = circleX + (int) ((r-2) * sin(thisRadiant));
- int blackCircleY = circleY + (int) ((r-2) * cos(thisRadiant));
- PVector circle = new PVector(blackCircleX, blackCircleY);
- if (mouseX != 0) {
- mousePos = new PVector(mouseX, mouseY);
- // substract the position of the circle from the position of the mouse
- mousePos.sub(circle);
- pull = diagonale / mousePos.mag(); // make the pull dependend on the size of the window
- }
- // the pull might shoot the circle off beyond the cursor position
- if (pull > mousePos.mag()) {
- pull = mousePos.mag();
- }
- mousePos.normalize(); // now make the vector have a length of 1
- blackCircleX += mousePos.x * pull; // multiply the direction from the circle's position to he mouse with the pull
- blackCircleY += mousePos.y * pull;
- fill(255 * thisBackgroundVariant);
- ellipse(blackCircleX, blackCircleY, dotSize, dotSize);
- // debug shizzle
- //fill(255, 0, 0);
- //textSize(20);
- //text(pull, circleX - 15, circleY + 5);
- //println(mousePos.x, mousePos.y);
- //strokeWeight(2);
- //line(blackCircleX + mousePos.x * pull, blackCircleY + mousePos.y * pull, circleX, circleY);
- }
- }
- k+=kIncrement;
- }
- void keyPressed () {
- println("KEY PRESS:", keyCode);
- switch (keyCode) {
- case 521: // + key
- if (dotSize < dotSizeMax && kIncrement > 0.015f) {
- println("bigger");
- dotSize++;
- kIncrement -= 0.01f;
- }
- break;
- case 45: // - key
- if (dotSize > dotSizeMin) {
- println("smaller");
- dotSize--;
- kIncrement += 0.01f;
- }
- break;
- case 32: // space bar
- stop();
- break;
- case LEFT:
- bgRed = 206;
- bgGreen = 175;
- bgBlue = 175;
- break;
- case RIGHT:
- bgRed = 237;
- bgGreen = 225;
- bgBlue = 236;
- break;
- default:
- break;
- }
- }
- void stop() {
- //bmusic.close();
- //minim.stop();
- super.stop();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement