/** * 10 PRINT CHR$(109+RND(1)*2); : GOTO 10
* ported liberally to Processing by Casey Reas
* color tweaked by Mark Sample */ // If you want to modify this code, you need to add the // controlP5 library to your Processing sketchbook: // http://www.sojamo.de/libraries/controlP5/index.html import controlP5.*; ControlP5 controlP5; int xunit; int yunit; float thickness = 4; float randomval = 0.5; float framerate = 1; float lastframe = 0; int linestyle = 0; void setup() { size(682, 510); xunit = 17; yunit = 16; stroke(255); smooth(); // GUI controlP5 = new ControlP5(this); controlP5.addSlider("randomval", 0.0, 1.0, 0.5, 10, height-90, 120, 10).setId(0); controlP5.addSlider("thickness", 0.5, 10.0, 4, 10, height-70, 120, 10).setId(1); controlP5.addSlider("framerate", 0.01, 24.0, 4, 10, height-50, 120, 10).setId(2); Radio r = controlP5.addRadio("radio", 260 , height-90); r.deactivateAll(); // use deactiveAll to not make the first radio button active. r.add("round",0); r.add("square",1); r.add("project",2); } void draw() { strokeWeight(thickness); // 0.5 - 10.0 if (millis() > lastframe + 1000.0/framerate) { background(#3E31A2); stroke(#7C70DA); for (float y = 0; y < yunit * 25; y += yunit) { for (float x = 0; x < xunit * 40; x += xunit) { float rnd = random(1); if (rnd < randomval) { line(x + 0, y + 0, x + xunit - 0, y + yunit - 0); } else { line(x + 0, y + yunit - 0, x + xunit - 0, y + 0 ); } } } lastframe = millis(); } } void controlEvent(ControlEvent theEvent) { //println("got a control event from controller with id "+theEvent.controller().id()); switch(theEvent.controller().id()) { case(0): randomval = theEvent.controller().value(); break; case(1): thickness = theEvent.controller().value(); break; case(2): framerate = theEvent.controller().value(); break; } } void radio(int theID) { switch(theID) { case(0): strokeCap(ROUND); break; case(1): strokeCap(SQUARE); break; case(2): strokeCap(PROJECT); break; } }