import generativedesign.*; import geomerative.*; import controlP5.*; import processing.pdf.*; boolean savePDF = false; public ControlP5 controlP5; Slider[] sliders; Toggle[] toggles; Textfield editTextfield; LazyFont[] chars; // dragged node Node selectedNode = null; public float nodeDiameter = 5; public int segmentLength = 12; public int springLength = 15; public int stiffness = 5; RFont font; RPoint[] pnts; public boolean monochrome = false; public boolean isShowNode = true; public boolean isShowPath = true; String fontName = "miso-regular.ttf"; //"Times New Roman.ttf";//// "Linotype - DIN Next LT Pro Condensed.ttf";// boolean editing = false; int fontSize = 200; int left_margin = 130; int baseline_y = 350; int space = 15; int node_num = 0; boolean isDrawCharBound = false; int offsetX = 0; int offsetY = 0; boolean guiEvent = false; String inputedText = "Lazy dogs"; boolean animating = false; int fps = 60; void setup() { size(1000, 600); background(255); frameRate(fps); smooth(); noStroke(); RG.init(this); setupGUI(); initNodesAndSprings(); } void setupGUI() { controlP5 = new ControlP5(this); controlP5.setColorForeground(0xff222222); controlP5.setColorBackground(0xffbbbbbb); controlP5.setColorLabel(0x00000000); controlP5.setColorValue(0xffcccccc); controlP5.setColorActive(0xFF000000); sliders = new Slider[30]; toggles = new Toggle[30]; int slid_cnt = 0; int tgl_cnt = 0; int left = 20; int top = 20; int len = 100; int posY = 0; editTextfield = controlP5.addTextfield("textTyped", left, top, 60, 20); editTextfield.setId(1); editTextfield.setText(inputedText); editTextfield.setAutoClear(true); Button btn = controlP5.addButton("GENERATE"); btn.setSize(45, 20); btn.setPosition(90, 20); //editTextfield.setFocus(true); editTextfield.setColorBackground(0xffeeeeee); editTextfield.setColorValue(color(0)); editTextfield.setLabel("TEXT"); editTextfield.setAutoClear(false); editTextfield.setColorActive(color(255,20,0)); //editTextfield.keepFocus(true); posY += 50; sliders[slid_cnt] = controlP5.addSlider("segmentLength", 4, 30, left, top+posY+0, len, 10); sliders[slid_cnt++].setLabel("Segment Length [4-30]"); posY += 15; sliders[slid_cnt] = controlP5.addSlider("nodeDiameter", 1, 10, left, top+posY+0, len, 10); sliders[slid_cnt++].setLabel("Node Diameter [1-10]"); posY += 15; sliders[slid_cnt] = controlP5.addSlider("springLength", 1, 50, left, top+posY+0, len, 10); sliders[slid_cnt++].setLabel("Spring Length [1-50]"); posY += 15; sliders[slid_cnt] = controlP5.addSlider("stiffness", 1, 10, left, top+posY+0, len, 10); sliders[slid_cnt++].setLabel("stiffness [1-10]"); posY += 15; toggles[tgl_cnt] = controlP5.addToggle("isShowNode",isShowNode,left+0,top+posY,15,15); toggles[tgl_cnt].setLabel("nodes"); Label l = toggles[tgl_cnt].captionLabel(); l.style().marginTop = -15; //move upwards (relative to button size) l.style().marginLeft = 20; //move to the right tgl_cnt++; posY += 20; toggles[tgl_cnt] = controlP5.addToggle("isShowPath",isShowPath,left+0,top+posY,15,15); toggles[tgl_cnt].setLabel("paths"); l = toggles[tgl_cnt].captionLabel(); l.style().marginTop = -15; //move upwards (relative to button size) l.style().marginLeft = 20; //move to the right tgl_cnt++; posY += 20; toggles[tgl_cnt] = controlP5.addToggle("monochrome",isShowPath,left+0,top+posY,15,15); toggles[tgl_cnt].setLabel("monochrome"); l = toggles[tgl_cnt].captionLabel(); l.style().marginTop = -15; //move upwards (relative to button size) l.style().marginLeft = 20; //move to the right tgl_cnt++; } void draw() { if (savePDF) beginRecord(PDF, timestamp()+".pdf"); background(255); if (selectedNode != null) { selectedNode.x = mouseX; selectedNode.y = mouseY; } for(int i = 0; i < chars.length; i++ ) { chars[i].setSpringLength(springLength); chars[i].setSpringStiffness(stiffness); chars[i].update(); } for(int i = 0; i < chars.length; i++ ) { chars[i].draw(); } if (savePDF) { savePDF = false; println("saving to pdf – finishing"); endRecord(); } } void initNodesAndSprings() { font = new RFont(fontName, fontSize, RFont.LEFT); int node_num = 0; int numOfChar = editTextfield.getText().length(); if(numOfChar != 0) { inputedText = editTextfield.getText(); editTextfield.clear(); } String strChar; chars = new LazyFont[0]; int charPosX = left_margin; LazyFont newChar = new LazyFont(inputedText); newChar.setPos(left_margin, baseline_y); newChar.init(); charPosX += (newChar.getWidth()); chars = (LazyFont[]) append(chars, newChar); } public void keyEvent(KeyEvent theKeyEvent) { println("theKeyEvent" + theKeyEvent); } void mousePressed() { for(int i = 0; i < chars.length; i++ ) { chars[i].findNode(); } } void mouseReleased() { if (selectedNode != null) { selectedNode = null; } else if (!editTextfield.isFocus() && !guiEvent) { animating = true; } guiEvent = false; } String timestamp() { return String.format("%1$ty%1$tm%1$td_%1$tH%1$tM%1$tS", Calendar.getInstance()); } void controlEvent(ControlEvent theEvent) { guiEvent = true; if(theEvent.isController()) { if(theEvent.controller().name().equals("GENERATE")) { initNodesAndSprings(); } else if(theEvent.controller().name().equals("segmentLength")) { initNodesAndSprings(); } } if(theEvent.controller() instanceof Textfield) { println("case 1" + theEvent.controller().id()); } switch(theEvent.controller().id()) { case(1): println("case 1"); break; } } public void textTyped(String theText) { //String t = editTextfield.getText(); //println("theText =" + theText); //println("textTyped = " + t); initNodesAndSprings(); }