//dorobit: //curveVertex //P5control na rychlost (do kazdeho for cyklu premenna speed) //prepojenie kazdeho vertexu s kazdym //moznost bodu nad vertexom //hrubka ciar //3D (moznost s 26 premennymi) //dalsi obrazec //za predpokladu nejakeho zglobalizovania kodu kontrola poctu bodov //"ucesanie shapu" //blendMode pri viacerych farbach alebo generovani farib v nejakej postupnosti import processing.pdf.*; import java.util.Calendar; import controlP5.*; ControlP5 cp5; boolean savePDF = false; int NORTH = 0; int NORTHEAST = 1; int EAST = 2; int SOUTHEAST = 3; int SOUTH = 4; int SOUTHWEST = 5; int WEST = 6; int NORTHWEST= 7; float stepSize = 1; int colorValue = 0; int saturationValue = 100; int brightnessValue = 100; float colorStepSize = random (-5, 5); float saturationStepSize = random (-2, 2); float brightnessStepSize = random (-2, 2); //int direction,direction1,direction2,direction3,direction4,direction5,direction6,direction7; //float posXControl, posYControl,posX1, posY1,posX2,posY2,posX3, posY3,posX4, posY4,posX5, posY5,posX6, posY6,posX7, posY7; Shape shape; int mode = 0; int speed = 60; void changeColor(){ if(colorValue > 360){ colorValue =0; } colorValue += colorStepSize; } void changeSaturation(){ if(saturationValue > 100){ saturationValue = 0; } saturationValue += saturationStepSize; } void changeBrightness(){ if(brightnessValue > 100){ brightnessValue = 0; } brightnessValue += brightnessStepSize; } class Point { Point(float posX, float posY) { this.posX = posX; this.posY = posY; } float posX; float posY; void drawPoint() { vertex(posX, posY); } void drawCurvePoint(){ curveVertex(posX, posY); } void drawDot(){ point(posX, posY); } void drawRectangle(){ rectMode(CENTER); rect(posX,posY, 100,100); } void shakePoint() { int direction = (int) random(0, 8); if (direction == NORTH) { posY -= stepSize; } else if (direction == NORTHEAST) { posX += stepSize; posY -= stepSize; } else if (direction == EAST) { posX += stepSize; } else if (direction == SOUTHEAST) { posX += stepSize; posY += stepSize; } else if (direction == SOUTH) { posY += stepSize; } else if (direction == SOUTHWEST) { posX -= stepSize; posY += stepSize; } else if (direction == WEST) { posX -= stepSize; } else if (direction == NORTHWEST) { posX -= stepSize; posY -= stepSize; } if (posX > width) posX = 0; if (posX < 0) posX = width; if (posY < 0) posY = height; if (posY > height) posY = 0; } } //Point foo = new Point(3.5, 4.8); class Shape { ArrayList points = new ArrayList(); int numberOfPoints = 0; Shape(int numberOfPoints) { this.numberOfPoints = numberOfPoints; for (int i = 0; i < numberOfPoints; i++) { Point newPoint = new Point( width/2, height/2); points.add(newPoint); } } void shakeShape() { for (int i = 0; i < numberOfPoints; i++) { Point point = (Point) points.get(i); point.shakePoint(); } } void drawShape() { beginShape(); for (int i = 0; i < numberOfPoints; i++) { Point point = (Point) points.get(i); point.drawPoint(); } ((Point) points.get(0)).drawPoint(); endShape(); } void drawCurvedShape() { beginShape(); for (int i = 0; i < numberOfPoints; i++) { Point point = (Point) points.get(i); point.drawCurvePoint(); } ((Point) points.get(0)).drawCurvePoint(); endShape(); } void drawDots() { for (int i = 0; i < numberOfPoints; i++) { Point point = (Point) points.get(i); point.drawDot(); } } void drawRectangles(){ for (int i = 0; i < numberOfPoints; i++) { Point point = (Point) points.get(i); point.drawRectangle(); } } } void setup() { colorMode(HSB,360,100,100,100); frameRate(25); size(800, 800); background(0,0,100); smooth(); shape = new Shape(8); cp5 = new ControlP5(this); cp5.begin(100, 100); cp5.addSlider("speed", 1, 800); cp5.addSlider("colorValue", 0, 360); cp5.addSlider("saturationValue", 0, 100); cp5.addSlider("brightnessValue",0, 100); //cp5.addButton("mode") //.setValue(4); cp5.end(); } //void shake() void draw() { if(frameCount %7 == 0){ changeColor(); changeSaturation(); changeBrightness(); } if (mode == 0) { fill(colorValue, 0, 0, 14); noStroke(); for (int j = 0; j < speed; j++) { shape.shakeShape(); shape.drawShape(); } } if (mode == 1) { stroke(colorValue, 0, 0, 40); for (int j = 0; j < speed; j++) { shape.shakeShape(); shape.drawShape(); } } if (mode== 2){ fill(colorValue, 0, 0, 14); noStroke(); for (int j = 0; j < speed; j++) { shape.shakeShape(); shape.drawCurvedShape(); } } if (mode == 3){ //meniace sa farby, normalny vertex fill(colorValue, saturationValue, brightnessValue, 14); noStroke(); for (int j = 0; j < speed; j++) { shape.shakeShape(); shape.drawShape(); } } if(mode == 4){ // meniace sa farby, linka, normal vertex stroke(colorValue, saturationValue,brightnessValue, 15); for (int j = 0; j < speed; j++) { shape.shakeShape(); shape.drawShape(); } } if (mode == 5){ //meniace sa farby, curved vertex fill(colorValue, saturationValue, brightnessValue, 14); noStroke(); for (int j = 0; j < speed; j++) { shape.shakeShape(); shape.drawCurvedShape(); } } if (mode == 6){ //meniace sa farby, linka, curved vertex stroke(colorValue, saturationValue,brightnessValue, 15); for (int j = 0; j < speed; j++) { shape.shakeShape(); shape.drawCurvedShape(); } } if (mode == 7){ strokeWeight(3); stroke(colorValue, saturationValue,brightnessValue, 15); for (int j = 0; j < speed; j++) { shape.shakeShape(); shape.drawDots(); } } if (mode == 8){ fill(colorValue, saturationValue, brightnessValue, 14); noStroke(); for (int j = 0; j < speed; j++) { shape.shakeShape(); shape.drawRectangles(); } } fill(0,0,100, 10); rect(0, 0, width, height); } void keyReleased() { if (key == DELETE || key == BACKSPACE) background(255); if (key == 's' || key == 'S') saveFrame(timestamp()+"_##.png"); if (key == '1') mode = 0; if (key == '2') mode = 1; if (key == '3') mode = 2; if (key == '4') mode = 3; if (key == '5') mode = 4; if (key == '6') mode = 5; if (key == '7') mode = 6; if (key == '8') mode = 7; if (key == '9') mode = 8; if (key =='r' || key =='R') { if (savePDF == false) { beginRecord(PDF, timestamp()+".pdf"); println("recording started"); savePDF = true; //stroke(0, 50); } } else if (key == 'e' || key =='E') { if (savePDF) { println("recording stopped"); endRecord(); savePDF = false; background(0,0,100); } } } // timestamp String timestamp() { Calendar now = Calendar.getInstance(); return String.format("%1$ty%1$tm%1$td_%1$tH%1$tM%1$tS", now); }