"Dayrose"-patterngenerator
in
Share your Work
•
9 months ago
Hello,
this is a beginners work - one of the first sketches I made during an education-project. I thougt I shared the fruits of my labors with you.
The goal was to create a pattern-generator at any kind. Mine creates a radial pattern based on the time when you start the sketch up. When done it shows so with a green checkmark - if you like the pattern you can leftclick the screen and it will be stored as a screenshot and a CNC-file which can be used to mill the pattern. Size and depth need to be changed at the beginning of the code.
Have fun!
- //importing CP5
- //import controlP5.*;
- //ControlP5 cp5;
- //Textlabel myTextlabel;
- // REMEMBER NEWY AND NEWY DURING FIRST FRAME
- float firstx;
- float firsty;
- float firstxmin;
- float firstxmax;
- float firstymin;
- float firstymax;
- int tolerance = 1; //AUTO-END & FLUSH NOT WORKING? INCREASE THE DETECTIONTOLERANCE
- //MECHANIC
- int rot = 0;
- int rotinc = 1;
- int radius = 50;
- float tiefe = -0.1;
- int arbeitsgeschwindigkeit = 400;
- //Zusammenfassungen
- float newx;
- float newy;
- float oldx;
- float oldy;
- //B-B-BOOOOLEANS
- boolean firstframe = true;
- boolean play = true;
- //TIME-VARIABLES
- float h = 1* hour();
- float m = 1* minute();
- float s = 1* second();
- float mapH = map(h, 0, 24, 0, 240); // MAPS HOURS TO A RANGE OF 0-240
- //COUNTER
- float counterstartwert = mapH; // THE HIGHER THE NUMBER THE SHARPER IT GETS
- float counter = counterstartwert; //INITIALIZING COUNTER
- //PRINTWRITER
- PrintWriter output; //CREATING CNC-FILE
- //░░███░░░████░░█████░░█░░░█░░████░░░░░░░
- //░█░░░░░░█░░░░░░░█░░░░█░░░█░░█░░░█░░░░░░
- //░░███░░░████░░░░█░░░░█░░░█░░████░░░░░░░
- //░░░░░█░░█░░░░░░░█░░░░█░░░█░░█░░░░░░░░░░
- //░░███░░░████░░░░█░░░░░███░░░█░░░░░░░░░░
- void setup() {
- size(600, 600);
- background (0);
- stroke(255);
- frameRate(6000); //means basically: Go as fast as possible.
- strokeWeight(1);
- println(hour() + ":" + minute() + ":" + second() + "Uhr");
- // print(minute());
- // println(second());
- //myTextlabel = new Textlabel(cp5,"Text initalized",100,100,400,200);
- output = createWriter("dayrose_" + timestamp() + ".ngc");
- output.println("%");
- output.println("G 54");
- }
- //░████░░░████░░░░███░░░█░░░█░░░█░░░░░░░░░
- //░█░░░█░░█░░░█░░█░░░█░░░█░█░█░█░░░░░░░░░░
- //░█░░░█░░████░░░█░░░█░░░█░█░█░█░░░░░░░░░░
- //░█░░░█░░█░░░█░░█████░░░░█░░░█░░░░░░░░░░░
- //░████░░░█░░░█░░█░░░█░░░░█░░░█░░░░░░░░░░░
- void draw() {
- stroke(100);
- //line ((width/3)*2, 0, (width/3)*2, height);
- //text
- stroke ( 255, 100);
- if (play == true) { //░░░░░░░░░░░░░░░░░░░░PLAY//PAUSE
- // SIN-COS-BLOCK //
- float xsin = width/2 + sin(radians(rot*(h/24)))*radius*3; //░█░
- float ycos = height/2 + cos(radians(rot*(h/24)))*radius*3; //░█░
- //░█░
- float xsin2 = xsin + sin(radians (rot*(m/30)))*radius*3; //░█░
- float ycos2 = ycos + cos(radians (rot*(m/30)))*radius*3; //░█░
- newx = xsin2; // MAP SINCOS TO NEWX
- newy = ycos2; // MAP SINCOS TO NEWY
- float mapX = map (newx, 0, width, 0, 300); //SCALE THE CNC-SKETCH
- float mapY = map (newy, 0, height, 0, 300); //SCALE THE CNC-SKETCH
- // (DOES NOT CHANGE THE SCALE OF THE ACTUAL SKETCH IN PROCESSING)
- // (newx, 0, width, 0, Width of the CNC in MM)
- // (newy, 0, height, 0, Height of the CNC in MM)
- //Firstframe-abfrage
- if (firstframe == true) { //WHEN FIRSTFRAME...
- oldx = newx; // ...SET OLD X TO NEW...
- oldy = newy; // ...SET OLD Y TO NEW... (to avoid line from 0,0 to the first properly drawn line)
- firstx = newx; //REMEMBER FIRST NEWX-COORDINATE
- firsty = newy; //REMEMBER FIRST NEWY-COORDINATE
- firstxmin = firstx - tolerance;
- firstxmax = firstx + tolerance;
- firstymin = firsty - tolerance;
- firstymax = firsty + tolerance;
- //(those are used to end the process when the line hits the starting-point again)
- println(firstx+"; "+firsty+"; ...firstx and firsty saved!");
- output.println("G0 X"+mapX+" Y"+mapY);
- output.println("G1 Z "+tiefe+" F" + arbeitsgeschwindigkeit);
- // output.println("G0 Z3");
- }
- if (counter == 0) {
- line (oldx, oldy, newx, newy); // DRAW LINE ///////////////////////////
- output.println("G1 X"+mapX+" Y"+mapY);
- oldx = newx; //TRANSFER NEW TO OLD // X //
- oldy = newy; //TRANSFER NEW TO OLD // Y //
- }
- rot += rotinc;
- //CHECK IF
- if ((((newx <= firstxmax) && (newx >= firstxmin)) && ((newy <= firstymax) && (newy >= firstymin))) && (firstframe == false) && (counter == 0)) {
- // output.println("G01 Z3");
- // output.println("M 02");
- // output.println("%");
- // output.flush(); // Writes the remaining data to the file
- // output.close(); // Finishes the file
- line (oldx, oldy, firstx, firsty);
- output.println("G1 X"+firstx+" Y"+firsty);
- checkdone (round(width/2), round((height/10)*9));
- play = false;
- }
- } //░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░PLAY//PAUSE
- if (mousePressed) { //IF MOUSEPRESSED STOP//
- output.println("G01 Z3");
- output.println("M 02");
- output.println("%");
- output.flush(); // Writes the remaining data to the file
- output.close(); // Finishes the file
- saveFrame("dayrose_" + timestamp() + ".jpg");
- checksaved (round(width/2), round((height/10)*9));
- stop();
- }
- if (firstframe == true) { //SET FIRSTFRAME FALSE//
- firstframe = false;
- }
- if (counter == 0) { //RESET COUNTER WHEN 0//
- counter = counterstartwert;
- }
- counter -= 1; //COUNT DOWN//
- }
- String timestamp() {
- return String.format("%1$ty%1$tm%1$td_%1$tH%1$tM%1$tS", Calendar.getInstance());
- }
- void checkdone (int x, int y) {
- strokeWeight(3);
- stroke(120, 210, 20);
- noFill();
- beginShape();
- vertex(x+10, y+30);
- vertex(x+20, y+40);
- vertex(x+40, y+10);
- endShape();
- }
- void checksaved (int x, int y) {
- strokeWeight(5);
- stroke(255);
- noFill();
- beginShape();
- vertex(x+10, y+30);
- vertex(x+20, y+40);
- vertex(x+40, y+10);
- endShape();
- strokeWeight(3);
- stroke(120, 210, 20);
- noFill();
- beginShape();
- vertex(x+10, y+30);
- vertex(x+20, y+40);
- vertex(x+40, y+10);
- endShape();
- }