Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import controlP5.*;
- import processing.svg.*;
- import java.util.*;
- float maxAngle = PI/15;
- float minAngle = maxAngle;
- float maxRadius = 200;
- float minRadius = 10;
- int numberOfPoints = 3;
- int numberOfDivisions = 50;
- float amplitude = 6;
- boolean exportSVG = false;
- ControlP5 cp5;
- void setup() {
- //fullScreen();
- size(1000, 700);
- cp5 = new ControlP5(this);
- cp5.setAutoDraw(false);
- cp5.addSlider("maxRadius").setRange((min(width, height)/2-10)*0.5, min(width, height)/2-10).setPosition(10, 10);
- cp5.addSlider("minRadius").setRange(5, (min(width, height)/2-10)*0.45).setPosition(10, 25);
- cp5.addSlider("maxAngle").setRange(0, PI/10).setPosition(170, 10);
- cp5.addSlider("minAngle").setRange(0, PI/10).setPosition(170, 25);
- cp5.addSlider("numberOfPoints").setRange(3, 20).setPosition(340, 10);
- cp5.addSlider("numberOfDivisions").setRange(1, 100).setPosition(340, 25);
- cp5.addSlider("amplitude").setRange(0, 20).setPosition(550, 10);
- cp5.addButton("exportSVG").setPosition(720, 10);
- }
- void draw() {
- background(0);
- cp5.draw();
- translate(width/2, height/2);
- stroke(255);
- noFill();
- if (exportSVG) {
- selectOutput("Save SVG File: ", "saveSVGFile");
- }
- for (int j = 0; j <= numberOfDivisions; j++) {
- beginShape();
- for (int i = 0; i< numberOfPoints; i++) {
- float angle = (TWO_PI / numberOfPoints) * i;
- float ratio = (float)j/(float)numberOfDivisions;
- float angleSum = lerp(-minAngle, maxAngle, map(sin(ratio*amplitude), -1, 1, 0, 1));
- angle += angleSum;
- float radius = lerp(minRadius, maxRadius, ratio);
- float x = sin(angle) * radius;
- float y = cos(angle) * radius;
- //strokeWeight(3);
- //point(x, y);
- strokeWeight(1);
- vertex(x, y);
- }
- endShape(CLOSE);
- }
- if (exportSVG) {
- endRecord();
- exportSVG = false;
- }
- }
- // --------------------------------------------------
- // Function borrowed from generative gestaltung sketches
- // http://www.generative-gestaltung.de
- String timestamp()
- {
- Calendar now = Calendar.getInstance();
- return String.format("%1$tY%1$tm%1$td_%1$tH%1$tM%1$tS", now);
- }
- void saveSVGFile(File sel) {
- if (sel != null) {
- if (sel.getName().toLowerCase().endsWith(".svg")) {
- beginRecord(SVG, sel.getAbsolutePath());
- } else {
- beginRecord(SVG, sel.getAbsolutePath().concat(".svg"));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement