├── Animation └── OmbroCinema │ ├── OmbroCinema.pde │ ├── Scanimation.pde │ ├── Utils.pde │ └── exports │ ├── 141124_213530_export.pdf │ ├── 141126_164439_export.pdf │ ├── 141126_165620_export.pdf │ └── 141126_165723_export.pdf ├── Forms ├── CellularAutomaton │ ├── Automaton.pde │ ├── CellularAutomaton.pde │ └── Grid.pde ├── Chladni │ └── Chladni.pde ├── Circles_recursion │ ├── Circle.pde │ └── Circles_recursion.pde ├── HilbertCurve │ └── HilbertCurve.pde ├── L_System │ ├── LInterpreter.pde │ ├── LRule.pde │ ├── LSystem.pde │ ├── L_System.pde │ └── lsystem.png ├── LangtonAnt │ ├── Ant.pde │ ├── Grid.pde │ └── LangtonAnt.pde ├── LangtonAntMultiple │ ├── Ant.pde │ ├── Grid.pde │ └── LangtonAntMultiple.pde ├── Lorenz │ └── Lorenz.pde ├── MazeGenerator │ ├── Maze.pde │ ├── MazeGenerator.pde │ └── maze.png ├── Penrose │ ├── Penrose.pde │ ├── Sun.pde │ └── Triangle.pde ├── RuttEtra │ ├── ImageSize.pde │ ├── RuttEtra.pde │ └── RuttEtraizer.pde ├── Sunflower │ └── Sunflower.pde ├── Torus │ ├── Torus.pde │ └── TorusKnot.pde └── Turmites │ ├── Rules.pde │ ├── Turmite.pde │ └── Turmites.pde ├── Image ├── CameraPropagation │ └── CameraPropagation.pde └── CameraSlitScanVertical │ └── CameraSlitScanVertical.pde └── README.md /Animation/OmbroCinema/OmbroCinema.pde: -------------------------------------------------------------------------------- 1 | /* 2 | OmbroCinema 3 | 4 | — 5 | Developped and tested on : 6 | - Processing 2.1.1 on MacOSX (10.10.1) 7 | 8 | — 9 | Julien @v3ga Gachadoat 10 | www.v3ga.net 11 | www.2roqs.com 12 | 13 | — 14 | Keyboard : 15 | - 'i' draws the composition 16 | - 'c' draws the composition with mask 17 | - 'a' draws animation frames 18 | - 'e' exports composition (with timestamp) + mask to .pdf format 19 | 20 | */ 21 | 22 | // ------------------------------------------------------ 23 | import processing.pdf.*; 24 | 25 | // ------------------------------------------------------ 26 | Scanimation scanimation; 27 | int mode = 0; 28 | 29 | // ------------------------------------------------------ 30 | void setup() 31 | { 32 | size(600, 600); 33 | // Create the Scanimation instance, which will be made of 6 frames 34 | scanimation = new Scanimation(this, 6); 35 | // Compose the final frame (this is calling "drawScanimationFrame" for each frame) 36 | scanimation.composeFinalFrame(); 37 | // Set the animation period in seconds (use 'a' on keyboard) 38 | scanimation.setTimerPeriod(0.5); 39 | } 40 | 41 | // ------------------------------------------------------ 42 | void draw() 43 | { 44 | background(255); 45 | 46 | // Draws the composition 47 | if (mode == 0) 48 | { 49 | scanimation.draw(); 50 | } 51 | // Draws the composition with mask 52 | else if (mode == 1) 53 | { 54 | scanimation.drawWithMask(); 55 | } 56 | // Draws the animation 57 | else if (mode == 2) 58 | { 59 | scanimation.animate(); 60 | } 61 | } 62 | 63 | // ------------------------------------------------------ 64 | // Automatically called by composeFinalFrame 65 | void drawScanimationFrame(PGraphics pg, int frame, int nbFrames) 66 | { 67 | pg.translate(pg.width/2, pg.height/2); 68 | pg.rotate( map(frame, 0, nbFrames, 0, radians(90)) ); 69 | pg.noStroke(); 70 | pg.rectMode(CENTER); 71 | pg.rect(0,0,400,100); 72 | pg.ellipse(30,60,100,100); 73 | } 74 | 75 | 76 | // ------------------------------------------------------ 77 | void keyPressed() 78 | { 79 | if (key == 'i') 80 | { 81 | mode = 0; 82 | } 83 | else if (key == 'c') 84 | { 85 | mode = 1; 86 | } 87 | else if (key == 'a') 88 | { 89 | mode = 2; 90 | } 91 | else if (key == 'e') 92 | { 93 | scanimation.exportPDF(); 94 | } 95 | } 96 | 97 | -------------------------------------------------------------------------------- /Animation/OmbroCinema/Scanimation.pde: -------------------------------------------------------------------------------- 1 | import java.lang.reflect.*; 2 | 3 | // ------------------------------------------------------ 4 | class Scanimation 5 | { 6 | int nbFrames; 7 | PApplet applet; 8 | Method methodFrame; 9 | 10 | ArrayList listFrames; 11 | ArrayList listMaskedFrames; 12 | PGraphics compositionFrame; 13 | PGraphics maskFrame, maskFrameScreen, currentFrame; 14 | 15 | Timer timer; 16 | float periodChangeFrame = 0.25f; // seconds 17 | float timeChangeFrame=0.0f; 18 | int framePlaying = 0; 19 | 20 | boolean exportCompo = false; 21 | 22 | 23 | // ------------------------------------------------------ 24 | Scanimation(PApplet applet, int nbFrames) 25 | { 26 | this.applet = applet; 27 | this.nbFrames = nbFrames; 28 | createFrames(); 29 | findMethodFrame(); 30 | createTimer(); 31 | } 32 | 33 | // ------------------------------------------------------ 34 | Scanimation(PApplet applet) 35 | { 36 | this.applet = applet; 37 | this.nbFrames = 6; 38 | createFrames(); 39 | findMethodFrame(); 40 | createTimer(); 41 | } 42 | 43 | // ------------------------------------------------------ 44 | void createFrames() 45 | { 46 | listFrames = new ArrayList(); 47 | listMaskedFrames = new ArrayList(); 48 | for (int i=0;i=periodChangeFrame) 104 | { 105 | framePlaying = (framePlaying+1)%getNumberFrames(); 106 | resetTimer(); 107 | } 108 | PGraphics frame = getFrame(framePlaying); 109 | image(frame, 0, 0, width, height); 110 | } 111 | 112 | // ------------------------------------------------------ 113 | int getNumberFrames() 114 | { 115 | return nbFrames; 116 | } 117 | 118 | // ------------------------------------------------------ 119 | PGraphics getFrame(int i) 120 | { 121 | return listFrames.get(i); 122 | } 123 | 124 | // ------------------------------------------------------ 125 | PGraphics getFrameMasked(int i) 126 | { 127 | return listMaskedFrames.get(i); 128 | } 129 | 130 | // ------------------------------------------------------ 131 | PGraphics getCompositionFrame() 132 | { 133 | return compositionFrame; 134 | } 135 | 136 | // ------------------------------------------------------ 137 | PGraphics getMaskFrame() 138 | { 139 | return maskFrame; 140 | } 141 | 142 | // ------------------------------------------------------ 143 | PGraphics getMaskFrameScreen() 144 | { 145 | return maskFrameScreen; 146 | } 147 | 148 | // ------------------------------------------------------ 149 | void findMethodFrame() 150 | { 151 | try 152 | { 153 | this.methodFrame = applet.getClass().getMethod("drawScanimationFrame", new Class[] { 154 | PGraphics.class, Integer.TYPE, Integer.TYPE 155 | } 156 | ); 157 | System.out.println("- \"findMethodFrame\" found."); 158 | } 159 | catch (Exception e) 160 | { 161 | System.out.println("- no \"findMethodFrame\" found."); 162 | } 163 | } 164 | 165 | // ------------------------------------------------------ 166 | void composeFinalFrame() 167 | { 168 | if (methodFrame != null) 169 | { 170 | 171 | // Draw Each Frame 172 | PGraphics frame, frameMasked; 173 | 174 | for (int i=0;i=nbFrames) return; 219 | currentFrame = listFrames.get(i); 220 | currentFrame.beginDraw(); 221 | } 222 | 223 | // ------------------------------------------------------ 224 | void endFrame() 225 | { 226 | if (currentFrame!=null) 227 | currentFrame.endDraw(); 228 | } 229 | 230 | // ------------------------------------------------------ 231 | void draw() 232 | { 233 | if (exportCompo) 234 | { 235 | exportCompo = false; 236 | 237 | String time = timestamp(); 238 | beginRecord(PDF, "exports/"+time+"_export.pdf"); 239 | strokeCap(SQUARE); 240 | stroke(0, 255); 241 | strokeWeight(2); 242 | 243 | compositionFrame.loadPixels(); 244 | boolean isBeginLine = false; 245 | int r = 0, i=0, j=0, jbegin=0; 246 | 247 | for (i=0;i=254) { 256 | isBeginLine = false; 257 | line(i, jbegin, i, j-1); 258 | println("colonne end "+i+";j="+j); 259 | } 260 | } 261 | else 262 | { 263 | if (r<=5) { 264 | isBeginLine = true; 265 | jbegin = j; 266 | println("colonne begin "+i+";j="+j); 267 | } 268 | } 269 | } 270 | 271 | if (isBeginLine) 272 | { 273 | line(i, jbegin, i, compositionFrame.height); 274 | } 275 | } 276 | endRecord(); 277 | } 278 | image(compositionFrame, 0, 0, width, height); 279 | } 280 | 281 | // ------------------------------------------------------ 282 | void drawWithMask() 283 | { 284 | image(getCompositionFrame(),0,0); 285 | blend(getMaskFrameScreen(), 0, 0, width, height, mouseX-width/2, 0, width, height, BLEND); 286 | } 287 | 288 | // ------------------------------------------------------ 289 | void exportPDF() 290 | { 291 | exportCompo = true; 292 | } 293 | }; 294 | 295 | -------------------------------------------------------------------------------- /Animation/OmbroCinema/Utils.pde: -------------------------------------------------------------------------------- 1 | import java.util.Calendar; 2 | 3 | // ------------------------------------------------------ 4 | class Timer 5 | { 6 | float now, before; 7 | Timer() 8 | { 9 | now = before = millis(); 10 | } 11 | 12 | float update() 13 | { 14 | now = millis(); 15 | float dt = now-before; 16 | before = now; 17 | 18 | return dt/1000.0f; 19 | } 20 | } 21 | 22 | // ------------------------------------------------------ 23 | String timestamp() 24 | { 25 | Calendar now = Calendar.getInstance(); 26 | return String.format("%1$ty%1$tm%1$td_%1$tH%1$tM%1$tS", now); 27 | } 28 | -------------------------------------------------------------------------------- /Animation/OmbroCinema/exports/141124_213530_export.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/v3ga/Processing/f756857dd47d053e4c0c3c8ca728df915c7602ae/Animation/OmbroCinema/exports/141124_213530_export.pdf -------------------------------------------------------------------------------- /Animation/OmbroCinema/exports/141126_164439_export.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/v3ga/Processing/f756857dd47d053e4c0c3c8ca728df915c7602ae/Animation/OmbroCinema/exports/141126_164439_export.pdf -------------------------------------------------------------------------------- /Animation/OmbroCinema/exports/141126_165620_export.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/v3ga/Processing/f756857dd47d053e4c0c3c8ca728df915c7602ae/Animation/OmbroCinema/exports/141126_165620_export.pdf -------------------------------------------------------------------------------- /Animation/OmbroCinema/exports/141126_165723_export.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/v3ga/Processing/f756857dd47d053e4c0c3c8ca728df915c7602ae/Animation/OmbroCinema/exports/141126_165723_export.pdf -------------------------------------------------------------------------------- /Forms/CellularAutomaton/Automaton.pde: -------------------------------------------------------------------------------- 1 | class Automaton 2 | { 3 | Grid grid; 4 | int line=0; 5 | boolean done = false; 6 | int frameStep = 2; 7 | int rule = RULE_30; 8 | 9 | final static int RANDOM = 0; 10 | final static int CENTER = 1; 11 | 12 | final static int RULE_30 = 30; 13 | final static int RULE_110 = 110; 14 | 15 | Automaton(int rule, int initMode, int resx, int resy) 16 | { 17 | this.grid = new Grid(resx, resy); 18 | this.rule = rule; 19 | if (initMode == RANDOM) 20 | { 21 | for (int i=0; i0.5) 23 | this.grid.setState(i, 0, 1); 24 | } 25 | else if (initMode == CENTER) 26 | { 27 | this.grid.setState(resx/2, 0, 1); 28 | } 29 | } 30 | 31 | void setFrameStep(int n) 32 | { 33 | this.frameStep = max(1,n); 34 | } 35 | 36 | void setRule(int which) 37 | { 38 | this.rule = which; 39 | } 40 | 41 | boolean applyRule(int which, int s_1, int s0, int s1) 42 | { 43 | if (which == 30) 44 | { 45 | return 46 | ((s_1==1 && s0==0 && s1==0) || 47 | (s_1==0 && s0==1 && s1==1) || 48 | (s_1==0 && s0==1 && s1==0) || 49 | (s_1==0 && s0==0 && s1==1)); 50 | } else if (which == 110) 51 | { 52 | return 53 | ((s_1==1 && s0==1 && s1==0) || 54 | (s_1==1 && s0==0 && s1==1) || 55 | (s_1==0 && s0==1 && s1==1) || 56 | (s_1==0 && s0==1 && s1==0) || 57 | (s_1==0 && s0==0 && s1==1)); 58 | } 59 | return false; 60 | } 61 | 62 | 63 | void run() 64 | { 65 | if (this.done || frameCount%frameStep!=0) return; 66 | 67 | int i, j = line; 68 | int s_1, s0, s1; 69 | for (i=1; i= this.grid.resy-1) 85 | this.done = true; 86 | } 87 | 88 | void draw() 89 | { 90 | // this.grid.draw(); 91 | this.grid.drawState(); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /Forms/CellularAutomaton/CellularAutomaton.pde: -------------------------------------------------------------------------------- 1 | /* 2 | CellularAutomaton 3 | — 4 | An implementation of Rule 30 / 110 cellular automata described here: 5 | https://en.wikipedia.org/wiki/Rule_30 6 | https://en.wikipedia.org/wiki/Rule_110 7 | — 8 | Developped and tested on : 9 | - Processing 3.5.3 on Windows 10 10 | 11 | — 12 | Julien @v3ga Gachadoat 13 | www.v3ga.net 14 | www.2roqs.com 15 | */ 16 | 17 | Automaton automaton; 18 | 19 | void setup() 20 | { 21 | size(500,500); 22 | surface.setTitle("Rule 30 / 110"); 23 | 24 | automaton = new Automaton(Automaton.RULE_110,Automaton.RANDOM,200,200); 25 | automaton.setFrameStep(2); // every "n" frames 26 | } 27 | 28 | void draw() 29 | { 30 | background(255); 31 | automaton.run(); 32 | automaton.draw(); 33 | } 34 | -------------------------------------------------------------------------------- /Forms/CellularAutomaton/Grid.pde: -------------------------------------------------------------------------------- 1 | class Grid 2 | { 3 | int resx, resy; 4 | int[] state; 5 | float cellw, cellh; 6 | 7 | Grid(int resx, int resy) 8 | { 9 | this.resx = resx; 10 | this.resy = resy; 11 | this.state = new int[resx*resy]; 12 | this.cellw = float(width) / resx; 13 | this.cellh = float(height) / resy; 14 | } 15 | 16 | void setState(int i, int j, int state) 17 | { 18 | this.state[i+j*this.resx] = state; 19 | } 20 | 21 | int getState(int i, int j) 22 | { 23 | return this.state[i+j*this.resx]; 24 | } 25 | 26 | void draw() 27 | { 28 | pushStyle(); 29 | stroke(220); 30 | float x=0.0, y=0.0; 31 | for (int i=0; i<=this.resy; i++) 32 | { 33 | x = i*this.cellw; 34 | line(x,0,x,height); 35 | } 36 | for (int i=0; i<=this.resy; i++) 37 | { 38 | y = i*this.cellh; 39 | line(0,y,width,y); 40 | } 41 | popStyle(); 42 | } 43 | 44 | void drawState() 45 | { 46 | 47 | pushStyle(); 48 | noStroke(); 49 | fill(0); 50 | int i, j; 51 | float x=0.0, y=0.0; 52 | int c = 0; 53 | for (j=0; j getHilbertPoints(int order, float x, float y, float w, float h) 56 | { 57 | ArrayList points = new ArrayList(); 58 | 59 | float w2 = w/2; 60 | float h2 = h/2; 61 | 62 | if (order == 1) 63 | { 64 | points.add(new PVector(x+w2/2, y+3*h2/2)); // SW 65 | points.add(new PVector(x+w2/2, y+h2/2)); // NW 66 | points.add(new PVector(x+3*w2/2, y+h2/2)); // NE 67 | points.add(new PVector(x+3*w2/2, y+3*h2/2)); // SE 68 | } else 69 | { 70 | ArrayList pointsNW = getHilbertPoints(order-1, x, y, w2, h2); 71 | ArrayList pointsNE = getHilbertPoints(order-1, x+w2, y, w2, h2); 72 | ArrayList pointsSW = getHilbertPoints(order-1, x, y+h2, w2, h2); 73 | ArrayList pointsSE = getHilbertPoints(order-1, x+w2, y+h2, w2, h2); 74 | 75 | flipPoints(90, pointsSW, x, y+h2, w2, h2); 76 | flipPoints(-90, pointsSE, x+w2, y+h2, w2, h2); 77 | 78 | points.addAll(pointsSW); 79 | points.addAll(pointsNW); 80 | points.addAll(pointsNE); 81 | points.addAll(pointsSE); 82 | } 83 | 84 | return points; 85 | } 86 | 87 | // ------------------------------------------------------------------------------------------------ 88 | void flipPoints(int which, ArrayList source, float x, float y, float w, float h) 89 | { 90 | if (which == 90) 91 | { 92 | for (PVector p : source) 93 | p.set( x + w - (p.y-y), y + p.x-x ); 94 | } else if (which == -90) 95 | { 96 | for (PVector p : source) 97 | p.set( x + (p.y-y), y + h-(p.x-x) ); 98 | } 99 | 100 | Collections.reverse(source); 101 | } 102 | -------------------------------------------------------------------------------- /Forms/L_System/LInterpreter.pde: -------------------------------------------------------------------------------- 1 | interface LInterpreter 2 | { 3 | void run(String s); 4 | } 5 | -------------------------------------------------------------------------------- /Forms/L_System/LRule.pde: -------------------------------------------------------------------------------- 1 | class LRule 2 | { 3 | char variable; 4 | String replacement; 5 | 6 | LRule(char v, String r) 7 | { 8 | this.variable = v; 9 | this.replacement = r; 10 | } 11 | 12 | String apply() 13 | { 14 | return replacement; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Forms/L_System/LSystem.pde: -------------------------------------------------------------------------------- 1 | class LSystem 2 | { 3 | String seed = ""; 4 | int generation = 0; 5 | ArrayList listGenerations; 6 | ArrayList listRules; 7 | String str=""; 8 | LInterpreter interpreter; 9 | String infos=""; 10 | 11 | LSystem(String seed) 12 | { 13 | init(seed); 14 | } 15 | 16 | LSystem(String seed,LInterpreter interpreter) 17 | { 18 | init(seed); 19 | setInterpreter(interpreter); 20 | } 21 | 22 | void init(String seed) 23 | { 24 | this.seed = this.str = seed; 25 | this.listGenerations = new ArrayList(); 26 | this.listRules = new ArrayList(); 27 | 28 | this.listGenerations.add(seed); 29 | } 30 | 31 | void setInterpreter(LInterpreter interpreter) 32 | { 33 | this.interpreter = interpreter; 34 | } 35 | void addRule(char c, String r) 36 | { 37 | addRule( new LRule(c,r) ); 38 | } 39 | 40 | void addRule(LRule r) 41 | { 42 | this.listRules.add(r); 43 | } 44 | 45 | void grow(int generations) 46 | { 47 | for (int i=0;i0) 87 | return generation; 88 | return -1; 89 | } 90 | 91 | void draw() 92 | { 93 | draw(interpreter,getLastGeneration()); 94 | } 95 | 96 | void draw(LInterpreter interpreter, int generation) 97 | { 98 | if (interpreter!=null && generation!=-1) 99 | { 100 | interpreter.run( listGenerations.get(generation) ); 101 | } 102 | } 103 | 104 | void drawInfos() 105 | { 106 | if (infos.equals("")){ 107 | infos += seed+"\n"; 108 | for (LRule rule:listRules) 109 | { 110 | infos+=rule.variable+" to "+rule.replacement+"\n"; 111 | } 112 | } 113 | fill(0); 114 | textSize(11); 115 | text(infos,4,12); 116 | } 117 | 118 | String toString() 119 | { 120 | String s = generation+" generations\n"; 121 | s+="----"; 122 | int i=0; 123 | for (String str:listGenerations) 124 | { 125 | s+= i+"-"+str+"["+str.length()+" chars]\n"; 126 | i++; 127 | } 128 | return s; 129 | } 130 | 131 | } 132 | -------------------------------------------------------------------------------- /Forms/L_System/L_System.pde: -------------------------------------------------------------------------------- 1 | /* 2 | L_system 3 | 4 | — 5 | Developped and tested on : 6 | - Processing 2.1.1 on MacOSX (10.9.2) 7 | 8 | — 9 | Julien @v3ga Gachadoat 10 | www.v3ga.net 11 | www.2roqs.com 12 | 13 | */ 14 | 15 | // ------------------------------------------------------------------------------------------------ 16 | LSystem ls2; 17 | 18 | // ------------------------------------------------------------------------------------------------ 19 | void setup() 20 | { 21 | ls2 = new LSystem("X", new LInterpreterF()); 22 | ls2.addRule('X', "F-[[X]+X]+FF[+FX]-X"); 23 | ls2.addRule('F', "FF"); 24 | 25 | ls2.grow(6); 26 | println(ls2); 27 | 28 | size(500,500); 29 | smooth(); 30 | } 31 | 32 | 33 | // ------------------------------------------------------------------------------------------------ 34 | void draw() 35 | { 36 | background(255); 37 | 38 | pushMatrix(); 39 | translate(width/2, height); 40 | ls2.draw(); 41 | popMatrix(); 42 | ls2.drawInfos(); 43 | } 44 | 45 | // ------------------------------------------------------------------------------------------------ 46 | void mousePressed() 47 | { 48 | saveFrame("lsystem.png"); 49 | } 50 | 51 | 52 | // ------------------------------------------------------------------------------------------------ 53 | class LInterpreterF implements LInterpreter 54 | { 55 | float angle = PI/10; 56 | float length = 2.1; 57 | 58 | LInterpreterF() 59 | { 60 | } 61 | 62 | void run(String s) 63 | { 64 | length=map(mouseY,0,height,1,3); 65 | angle=map(mouseX,0,width,0,PI); 66 | 67 | stroke(0); 68 | noFill(); 69 | int nbChars = s.length(); 70 | char c; 71 | for (int i=0;i 0, 1->90, 2->180, 3->270 6 | Ant(Grid grid, int i, int j) 7 | { 8 | this.grid = grid; 9 | this.i = i%this.grid.resx; 10 | this.j = j%this.grid.resy; 11 | this.turn=0; 12 | } 13 | 14 | void run() 15 | { 16 | //if (frameCount % 2 == 0) 17 | { 18 | // check the state of the grid 19 | int c = this.grid.getState(this.i, this.j); 20 | // White square 21 | if (c == 0) 22 | { 23 | this.grid.setState(this.i, this.j, 1); 24 | this.turn90CW(); 25 | this.move(); 26 | } 27 | // Black square 28 | else if (c == 1) 29 | { 30 | this.grid.setState(this.i, this.j, 0); 31 | this.turn90CCW(); 32 | this.move(); 33 | } 34 | } 35 | } 36 | 37 | void turn90CW() 38 | { 39 | turn = (turn+1)%4; 40 | } 41 | 42 | void turn90CCW() 43 | { 44 | turn = turn-1; 45 | if (turn<0) turn = 3; 46 | } 47 | 48 | void move() 49 | { 50 | if (turn == 0) 51 | this.i +=1; 52 | else if (turn == 1) 53 | this.j +=1; 54 | else if (turn == 2) 55 | this.i -=1; 56 | else if (turn == 3) 57 | this.j -=1; 58 | 59 | if (this.i >= this.grid.resx) this.i=0; 60 | else if (this.i < 0) this.i=this.grid.resx-1; 61 | if (this.j >= this.grid.resy) this.j=0; 62 | else if (this.j < 0) this.j=this.grid.resy-1; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Forms/LangtonAnt/Grid.pde: -------------------------------------------------------------------------------- 1 | class Grid 2 | { 3 | int resx, resy; 4 | int[] state; 5 | float cellw, cellh; 6 | 7 | Grid(int resx, int resy) 8 | { 9 | this.resx = resx; 10 | this.resy = resy; 11 | this.state = new int[resx*resy]; 12 | this.cellw = float(width) / resx; 13 | this.cellh = float(height) / resy; 14 | } 15 | 16 | void setState(int i, int j, int state) 17 | { 18 | this.state[i+j*this.resx] = state; 19 | } 20 | 21 | int getState(int i, int j) 22 | { 23 | return this.state[i+j*this.resx]; 24 | } 25 | 26 | void draw() 27 | { 28 | pushStyle(); 29 | stroke(220); 30 | float x=0.0, y=0.0; 31 | for (int i=0; i<=this.resy; i++) 32 | { 33 | x = i*this.cellw; 34 | line(x,0,x,height); 35 | } 36 | for (int i=0; i<=this.resy; i++) 37 | { 38 | y = i*this.cellh; 39 | line(0,y,width,y); 40 | } 41 | popStyle(); 42 | } 43 | 44 | void drawState() 45 | { 46 | 47 | pushStyle(); 48 | noStroke(); 49 | fill(0); 50 | int i, j; 51 | float x=0.0, y=0.0; 52 | int c = 0; 53 | for (j=0; j 0, 1->90, 2->180, 3->270 6 | Ant(Grid grid, int i, int j) 7 | { 8 | this.grid = grid; 9 | this.i = i%this.grid.resx; 10 | this.j = j%this.grid.resy; 11 | this.turn=0; 12 | } 13 | 14 | void run() 15 | { 16 | //if (frameCount % 2 == 0) 17 | { 18 | // check the state of the grid 19 | int c = this.grid.getState(this.i, this.j); 20 | // White square 21 | if (c == 0) 22 | { 23 | this.grid.setState(this.i, this.j, 1); 24 | this.turn90CW(); 25 | this.move(); 26 | } 27 | // Black square 28 | else if (c == 1) 29 | { 30 | this.grid.setState(this.i, this.j, 0); 31 | this.turn90CCW(); 32 | this.move(); 33 | } 34 | } 35 | } 36 | 37 | void turn90CW() 38 | { 39 | turn = (turn+1)%4; 40 | } 41 | 42 | void turn90CCW() 43 | { 44 | turn = turn-1; 45 | if (turn<0) turn = 3; 46 | } 47 | 48 | void move() 49 | { 50 | if (turn == 0) 51 | this.i +=1; 52 | else if (turn == 1) 53 | this.j +=1; 54 | else if (turn == 2) 55 | this.i -=1; 56 | else if (turn == 3) 57 | this.j -=1; 58 | 59 | if (this.i >= this.grid.resx) this.i=0; 60 | else if (this.i < 0) this.i=this.grid.resx-1; 61 | if (this.j >= this.grid.resy) this.j=0; 62 | else if (this.j < 0) this.j=this.grid.resy-1; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Forms/LangtonAntMultiple/Grid.pde: -------------------------------------------------------------------------------- 1 | class Grid 2 | { 3 | int resx, resy; 4 | int[] state; 5 | float cellw, cellh; 6 | 7 | Grid(int resx, int resy) 8 | { 9 | this.resx = resx; 10 | this.resy = resy; 11 | this.state = new int[resx*resy]; 12 | this.cellw = float(width) / resx; 13 | this.cellh = float(height) / resy; 14 | } 15 | 16 | void setState(int i, int j, int state) 17 | { 18 | this.state[i+j*this.resx] = state; 19 | } 20 | 21 | int getState(int i, int j) 22 | { 23 | return this.state[i+j*this.resx]; 24 | } 25 | 26 | void draw() 27 | { 28 | pushStyle(); 29 | stroke(220); 30 | float x=0.0, y=0.0; 31 | for (int i=0; i<=this.resy; i++) 32 | { 33 | x = i*this.cellw; 34 | line(x,0,x,height); 35 | } 36 | for (int i=0; i<=this.resy; i++) 37 | { 38 | y = i*this.cellh; 39 | line(0,y,width,y); 40 | } 41 | popStyle(); 42 | } 43 | 44 | void drawState() 45 | { 46 | 47 | pushStyle(); 48 | noStroke(); 49 | fill(0); 50 | int i, j; 51 | float x=0.0, y=0.0; 52 | int c = 0; 53 | for (j=0; j ants = new ArrayList(); 18 | boolean bDrawGrid = false; 19 | 20 | void setup() 21 | { 22 | size(500,500); 23 | grid = new Grid(100,100); 24 | addAnt(50,50); 25 | } 26 | 27 | void draw() 28 | { 29 | background(255); 30 | for (Ant ant : ants) 31 | ant.run(); 32 | if (bDrawGrid) 33 | grid.draw(); 34 | grid.drawState(); 35 | } 36 | 37 | void mousePressed() 38 | { 39 | addAnt(floor(mouseX/grid.cellw), floor(mouseY/grid.cellh)); 40 | } 41 | 42 | void addAnt(int i, int j) 43 | { 44 | ants.add( new Ant(grid,i,j) ); 45 | } 46 | -------------------------------------------------------------------------------- /Forms/Lorenz/Lorenz.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Lorenz attractors 3 | 4 | — 5 | Developped and tested on : 6 | - Processing 2.1.1 on MacOSX (10.9.4) 7 | 8 | — 9 | Julien @v3ga Gachadoat 10 | www.v3ga.net 11 | www.2roqs.com 12 | 13 | */ 14 | 15 | // ------------------------------------------------------------------------------------------------ 16 | import controlP5.*; 17 | 18 | // ------------------------------------------------------------------------------------------------ 19 | PGraphics offscreen; 20 | 21 | // ------------------------------------------------------------------------------------------------ 22 | float x=1.0, x1=0.0; 23 | float y=1.0, y1=0.0; 24 | float z=1.0, z1=0.0; 25 | 26 | // ------------------------------------------------------------------------------------------------ 27 | float s = 5.0; 28 | float p = 15.0; 29 | float b = 1.0; 30 | float dt = 0.005; 31 | float scale = 6; 32 | 33 | // ------------------------------------------------------------------------------------------------ 34 | ControlP5 controls; 35 | 36 | // ------------------------------------------------------------------------------------------------ 37 | void setup() 38 | { 39 | size(800, 400, P3D); 40 | 41 | controls = new ControlP5(this); 42 | controls.begin(5,5); 43 | controls.addSlider("s", 1.0,30.0).linebreak(); 44 | controls.addSlider("p", 1.0,30.0).linebreak(); 45 | controls.addSlider("b", 1.0,30.0).linebreak(); 46 | controls.addSlider("scale", 1.0,10.0).linebreak(); 47 | controls.addButton("reset").setSize(30,14).linebreak(); 48 | controls.end(); 49 | 50 | offscreen = createGraphics(width, height,P3D); 51 | reset(); 52 | } 53 | 54 | // ------------------------------------------------------------------------------------------------ 55 | void draw() 56 | { 57 | drawOffscreen(); 58 | image(offscreen,0,0); 59 | } 60 | 61 | // ------------------------------------------------------------------------------------------------ 62 | void clearOffscreen() 63 | { 64 | offscreen.beginDraw(); 65 | offscreen.background(0); 66 | offscreen.endDraw(); 67 | } 68 | 69 | // ------------------------------------------------------------------------------------------------ 70 | void drawOffscreen() 71 | { 72 | x1 = x + dt*s*(y-x); 73 | y1 = y + dt*(p*x - y - x*z); 74 | z1 = z + dt*(x*y - b*z); 75 | 76 | offscreen.beginDraw(); 77 | offscreen.translate(width/2, height/2); 78 | offscreen.stroke(255); 79 | offscreen.line(scale*x1, scale*y1, scale*z1, scale*x, scale*y, scale*z); 80 | offscreen.endDraw(); 81 | 82 | x = x1; 83 | y = y1; 84 | z = z1; 85 | } 86 | 87 | // ------------------------------------------------------------------------------------------------ 88 | void reset() 89 | { 90 | x=random(-5,5); x1=0.0; 91 | y=random(-5,5); y1=0.0; 92 | z=random(-5,5); z1=0.0; 93 | 94 | clearOffscreen(); 95 | } 96 | 97 | -------------------------------------------------------------------------------- /Forms/MazeGenerator/Maze.pde: -------------------------------------------------------------------------------- 1 | class Maze 2 | { 3 | // Maze structure 4 | MazeCell[] cells; 5 | int resx, resy, nbCells; 6 | 7 | // Iteration variables 8 | ArrayList stack; 9 | MazeCell cellCurrent; 10 | int nbCellsVisited=0; 11 | int cellStartx = 0, cellStarty = 0; 12 | boolean computed = false; 13 | 14 | // Step by step variables 15 | boolean stepByStep = false; 16 | float time = 0.0f; 17 | float timeStep = 0.0015f; 18 | 19 | // Solution 20 | ArrayList solution; 21 | 22 | Maze(int resx, int resy) 23 | { 24 | this.resx = resx; 25 | this.resy = resy; 26 | this.nbCells = resx * resy; 27 | 28 | resetCells(); 29 | } 30 | 31 | void setCellStart(int x, int y) 32 | { 33 | if (x>=resx) x=0; 34 | if (y>=resy) y=0; 35 | 36 | this.cellStartx = x; 37 | this.cellStarty = y; 38 | } 39 | 40 | void setTimeStepByStep(float t) 41 | { 42 | this.timeStep = t; 43 | } 44 | 45 | boolean isComputed() 46 | { 47 | return computed; 48 | } 49 | 50 | void resetCells() 51 | { 52 | this.cells = new MazeCell[nbCells]; 53 | int k=0; 54 | for (int j=0; j=0 && x=0 && y cellNeighbor.y) 118 | { 119 | cellCurrent.hasNorth = false; 120 | cellNeighbor.hasSouth = false; 121 | } else 122 | { 123 | cellCurrent.hasSouth = false; 124 | cellNeighbor.hasNorth = false; 125 | } 126 | } else if (cellCurrent.y == cellNeighbor.y) 127 | { 128 | if (cellCurrent.x > cellNeighbor.x) 129 | { 130 | cellCurrent.hasWest = false; 131 | cellNeighbor.hasEast = false; 132 | } else 133 | { 134 | cellCurrent.hasEast = false; 135 | cellNeighbor.hasWest = false; 136 | } 137 | } 138 | } 139 | 140 | void reset() 141 | { 142 | resetCells(); 143 | 144 | cellCurrent = getCell(cellStartx, cellStarty); 145 | setCellVisited(cellCurrent); 146 | 147 | stack = new ArrayList(); 148 | } 149 | 150 | void compute() 151 | { 152 | reset(); 153 | stepByStep = false; 154 | computed = false; 155 | 156 | while (nbCellsVisited= timeStep*1000) 176 | { 177 | step(); 178 | time = timeNow; 179 | } 180 | } else 181 | computed = true; 182 | } 183 | 184 | 185 | void step() 186 | { 187 | if (hasCellNeightborUnvisited(cellCurrent)) 188 | { 189 | stack.add( cellCurrent ); 190 | 191 | MazeCell cellNeighbor = findCellNeightborUnvisited(cellCurrent); 192 | removeCellsWalls(cellCurrent, cellNeighbor); 193 | 194 | cellCurrent = cellNeighbor; 195 | setCellVisited(cellCurrent); 196 | } else 197 | { 198 | if (stack.size()>0) 199 | { 200 | cellCurrent = stack.remove( stack.size()-1 ); 201 | } 202 | } 203 | } 204 | 205 | void draw() 206 | { 207 | for (int i=0; i(); 216 | MazeCell cellCurrent = getCell(cellStartx, cellStarty); 217 | 218 | } 219 | } 220 | } 221 | 222 | class MazeCell 223 | { 224 | int x, y; 225 | float w, h; 226 | boolean hasNorth = true; 227 | boolean hasEast = true; 228 | boolean hasSouth = true; 229 | boolean hasWest = true; 230 | boolean visited = false; 231 | 232 | Maze parent; 233 | 234 | MazeCell(int x, int y, Maze parent) 235 | { 236 | this.x = x; 237 | this.y = y; 238 | this.parent = parent; 239 | this.w = (float)width/(float)parent.resx; 240 | this.h = (float)height/(float)parent.resy; 241 | } 242 | 243 | void draw() 244 | { 245 | float xx = (float)x; 246 | float yy = (float)y; 247 | 248 | float x1 = xx*w; 249 | float x2 = (xx+1)*w; 250 | float y1 = yy*h; 251 | float y2 = (yy+1)*h; 252 | if (x2>=width) x2=width-1; 253 | if (y2>=height) y2=height-1; 254 | 255 | if (visited && parent.stepByStep) { 256 | pushStyle(); 257 | noStroke(); 258 | fill(200); 259 | rectMode(CORNERS); 260 | rect(x1, y1, x2, y2); 261 | popStyle(); 262 | } 263 | if (hasNorth) line(x1, y1, x2, y1); 264 | if (hasEast) line(x2, y1, x2, y2); 265 | if (hasSouth) line(x1, y2, x2, y2); 266 | if (hasWest) line(x1, y1, x1, y2); 267 | } 268 | } -------------------------------------------------------------------------------- /Forms/MazeGenerator/MazeGenerator.pde: -------------------------------------------------------------------------------- 1 | /* 2 | MazeGenerator 3 | — 4 | An implementation of recursive backtracker algorithm described here: 5 | https://en.wikipedia.org/wiki/Maze_generation_algorithm 6 | — 7 | Developped and tested on : 8 | - Processing 3.0b4 on MacOSX (10.10.5) 9 | 10 | — 11 | Julien @v3ga Gachadoat 12 | www.v3ga.net 13 | www.2roqs.com 14 | */ 15 | 16 | Maze maze; 17 | 18 | void setup() 19 | { 20 | size(500, 500); 21 | maze = new Maze(25, 25); 22 | maze.setCellStart(0, 0); 23 | //maze.compute(); 24 | maze.beginComputeStepByStep(); 25 | } 26 | 27 | void draw() 28 | { 29 | background(255); 30 | stroke(0); 31 | strokeWeight(1); 32 | maze.computeStepByStep(); 33 | maze.draw(); 34 | } 35 | 36 | void mousePressed() 37 | { 38 | maze.compute(); 39 | } 40 | 41 | void keyPressed() 42 | { 43 | if (key == 'e') 44 | saveFrame("maze.png"); 45 | } -------------------------------------------------------------------------------- /Forms/MazeGenerator/maze.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/v3ga/Processing/f756857dd47d053e4c0c3c8ca728df915c7602ae/Forms/MazeGenerator/maze.png -------------------------------------------------------------------------------- /Forms/Penrose/Penrose.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Penrose 3 | — 4 | Based on explanations found here : 5 | https://en.wikipedia.org/wiki/Penrose_tiling 6 | http://preshing.com/20110831/penrose-tiling-explained/ 7 | — 8 | Developped and tested on : 9 | - Processing 3.2.1 on MacOSX (10.12.5) 10 | 11 | — 12 | Julien @v3ga Gachadoat 13 | www.v3ga.net 14 | www.2roqs.com 15 | */ 16 | 17 | // ------------------------------------------------------------------------------------------------ 18 | Sun sun; 19 | 20 | // ------------------------------------------------------------------------------------------------ 21 | void setup() 22 | { 23 | size(500, 500,P2D); 24 | sun = new Sun(7, 0.48*height); 25 | } 26 | 27 | // ------------------------------------------------------------------------------------------------ 28 | void draw() 29 | { 30 | translate(width/2, height/2); 31 | 32 | background(0); 33 | noStroke(); 34 | sun.draw(); 35 | } 36 | 37 | // ------------------------------------------------------------------------------------------------ 38 | void keyPressed() 39 | { 40 | if (key == 's') 41 | saveFrame("Penrose.png"); 42 | } 43 | -------------------------------------------------------------------------------- /Forms/Penrose/Sun.pde: -------------------------------------------------------------------------------- 1 | class Sun 2 | { 3 | int nbTriangles = 10; 4 | Triangle[] triangles = new Triangle[nbTriangles]; 5 | 6 | 7 | Sun(int subdivide, float r) 8 | { 9 | for (int i = 0; i < nbTriangles; i++) 10 | { 11 | float start = (2*i-1) * PI/nbTriangles; 12 | float end = (2*i+1) * PI/nbTriangles; 13 | 14 | PVector A = new PVector(0, 0); 15 | PVector B = new PVector(r*cos(start), r*sin(start)); 16 | PVector C = new PVector(r*cos(end), r*sin(end)); 17 | 18 | triangles[i] = new Triangle(0, A, i%2 == 0 ? B : C, i%2 == 0 ? C : B); 19 | triangles[i].subdivide(subdivide); 20 | } 21 | } 22 | 23 | void draw() 24 | { 25 | for (int i = 0; i < nbTriangles; i++) 26 | triangles[i].draw(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Forms/Penrose/Triangle.pde: -------------------------------------------------------------------------------- 1 | class Triangle 2 | { 3 | final static float phi = 1.61803398875; 4 | 5 | int type = 0; 6 | int level = 0; 7 | 8 | PVector A = new PVector(); 9 | PVector B = new PVector(); 10 | PVector C = new PVector(); 11 | 12 | Triangle[] children; 13 | 14 | 15 | Triangle(int type, PVector A, PVector B, PVector C) 16 | { 17 | this.type = type; 18 | this.level = 0; 19 | this.A = A; 20 | this.B = B; 21 | this.C = C; 22 | } 23 | 24 | Triangle(int type, PVector A, PVector B, PVector C, int level) 25 | { 26 | this.type = type; 27 | this.level = level; 28 | this.A = A; 29 | this.B = B; 30 | this.C = C; 31 | } 32 | 33 | void draw() 34 | { 35 | if (children != null) 36 | { 37 | for (int i=0; i= '1' && key <='6') re.setDrawMode(key-'0'); 64 | } 65 | 66 | -------------------------------------------------------------------------------- /Forms/RuttEtra/RuttEtraizer.pde: -------------------------------------------------------------------------------- 1 | class RuttEtraizer 2 | { 3 | PGraphics imgSmall; 4 | PImage imgRef; 5 | int blurImgSmall = 1; 6 | int drawMode = 1; 7 | int s = 8; 8 | float filterTh = 0.5; 9 | 10 | // ------------------------------------------------------ 11 | // RuttEtra 12 | // ------------------------------------------------------ 13 | RuttEtraizer(PImage img, int s) 14 | { 15 | imgRef = img; 16 | setScale(s); 17 | resizeImageSmall(); 18 | } 19 | 20 | // ------------------------------------------------------ 21 | // setImgRef 22 | // ------------------------------------------------------ 23 | void setImgRef(PImage img) 24 | { 25 | this.imgRef = img; 26 | resizeImageSmall(); 27 | } 28 | 29 | // ------------------------------------------------------ 30 | // resizeImg 31 | // ------------------------------------------------------ 32 | PImage getImageResized() 33 | { 34 | return imgSmall; 35 | } 36 | 37 | // ------------------------------------------------------ 38 | // setDrawMode 39 | // ------------------------------------------------------ 40 | void setDrawMode(int i) 41 | { 42 | drawMode = i; 43 | } 44 | 45 | // ------------------------------------------------------ 46 | // setBlur 47 | // ------------------------------------------------------ 48 | void setBlur(int b) 49 | { 50 | blurImgSmall = b; 51 | blurImgSmall=constrain(blurImgSmall, 0, 10); 52 | } 53 | 54 | // ------------------------------------------------------ 55 | // increaseBlur 56 | // ------------------------------------------------------ 57 | void increaseBlur() 58 | { 59 | setBlur(++blurImgSmall); 60 | } 61 | 62 | // ------------------------------------------------------ 63 | // decreaseBlur 64 | // ------------------------------------------------------ 65 | void decreaseBlur() 66 | { 67 | setBlur(--blurImgSmall); 68 | } 69 | 70 | // ------------------------------------------------------ 71 | // setScale 72 | // ------------------------------------------------------ 73 | void setScale(int s) 74 | { 75 | this.s = s; 76 | this.s = constrain(s, 2, 8); 77 | resizeImageSmall(); 78 | } 79 | 80 | 81 | // ------------------------------------------------------ 82 | // apply 83 | // ------------------------------------------------------ 84 | void apply() 85 | { 86 | imgSmall.beginDraw(); 87 | imgRef.filter(THRESHOLD, filterTh); 88 | imgRef.filter(BLUR, blurImgSmall); 89 | imgSmall.image(imgRef, 0, 0, imgSmall.width, imgSmall.height); 90 | imgSmall.endDraw(); 91 | } 92 | 93 | // ------------------------------------------------------ 94 | // resizeImageSmall 95 | // ------------------------------------------------------ 96 | void resizeImageSmall() 97 | { 98 | imgSmall = createGraphics(imgRef.width/s, imgRef.height/s); 99 | apply(); 100 | } 101 | 102 | // ------------------------------------------------------ 103 | // draw 104 | // ------------------------------------------------------ 105 | void draw(PApplet applet, float h) 106 | { 107 | draw(applet.g, h); 108 | } 109 | 110 | // ------------------------------------------------------ 111 | // draw 112 | // ------------------------------------------------------ 113 | void draw(PGraphics g, float h) 114 | { 115 | if (drawMode == 1) 116 | drawLines(g,imgSmall, h); 117 | else if (drawMode == 2) 118 | drawPoints(g,imgSmall); 119 | else if (drawMode == 3) 120 | drawTriangles(g,imgSmall, h); 121 | else if (drawMode == 4) 122 | drawLines2(g,imgSmall, 280); 123 | else if (drawMode == 5) 124 | { 125 | drawLines(g,imgSmall, h); 126 | drawLines2(g,imgSmall, h); 127 | } 128 | else if (drawMode == 6) 129 | { 130 | drawMesh(g,imgSmall, h); 131 | g.stroke(255,255); 132 | g.pushMatrix(); 133 | g.translate(0,0,2); 134 | drawLines(g, imgSmall, h); 135 | g.popMatrix(); 136 | } 137 | } 138 | 139 | 140 | // ------------------------------------------------------ 141 | // drawPoints 142 | // ------------------------------------------------------ 143 | void drawPoints(PGraphics g,PImage img) 144 | { 145 | int i, j, offset; 146 | int w = img.width; 147 | int h = img.height; 148 | int gg = 0; 149 | 150 | g.pushMatrix(); 151 | g.translate(-s*img.width/2, -s*img.height/2); 152 | img.loadPixels(); 153 | for (j=0;j lines; 12 | 13 | int res = 500; 14 | int res2 = 60; 15 | float r2 = 100.0; 16 | 17 | int renderMode = 0; 18 | 19 | // Constructor 20 | TorusKnot(float R_, float R2_, float P_, float Q_, int res_, int res2_, int renderMode_) 21 | { 22 | R = R_; 23 | r2 = R2_; 24 | P = P_; 25 | Q = Q_; 26 | res = res_; 27 | res2 = res2_; 28 | renderMode = renderMode_; 29 | 30 | // mesh = new TriangleMesh(); 31 | lines = new ArrayList(); 32 | 33 | 34 | PVector A, B; 35 | float[] b; 36 | Matrix4x4 transfo = new Matrix4x4(); 37 | Matrix4x4 basisM = new Matrix4x4(); 38 | float th = 0.0; 39 | float dth = 360.0/(res) ; 40 | 41 | points = new Vec3D[res][res2]; 42 | normals = new Vec3D[res][res2]; 43 | 44 | for (int i=0; i= r.length) which = 0; 32 | this.ruleIndex = which; 33 | } 34 | 35 | boolean color0(color c) 36 | { 37 | return (red(c) == 255); 38 | } 39 | 40 | boolean color1(color c) 41 | { 42 | return (red(c) == 0); 43 | } 44 | 45 | int colorIndex(color pixel) 46 | { 47 | if (color0(pixel)) return 0; 48 | if (color1(pixel)) return 1; 49 | return -1; 50 | } 51 | 52 | void colorCell(int colorIndex) 53 | { 54 | offset = this.x + grid.width*this.y; 55 | grid.pixels[offset] = color(colorIndex == 0 ? 255 : 0); 56 | } 57 | 58 | void turn(int which) 59 | { 60 | this.direction = TurmiteTurn[which][direction]; 61 | } 62 | 63 | void state_(int which) 64 | { 65 | this.state = which; 66 | } 67 | 68 | void move() 69 | { 70 | switch(direction) 71 | { 72 | case 0: 73 | y = y-1; 74 | if (y<0) y=grid.height-1; 75 | break; 76 | case 1: 77 | x = (x+1)%grid.width; 78 | break; 79 | case 2: 80 | y = (y+1)%grid.height; 81 | break; 82 | case 3: 83 | x = x-1; 84 | if (x<0) x=grid.width-1; 85 | break; 86 | } 87 | 88 | } 89 | 90 | void run() 91 | { 92 | grid.loadPixels(); 93 | color pixel = grid.get(x, y); 94 | 95 | // Rule 96 | int c = colorIndex(pixel); 97 | if (c>=0) 98 | { 99 | int[] next = r[ruleIndex][state][c]; 100 | int nextColorIndex = next[0]; 101 | int nextTurn = next[1]; 102 | int nextState = next[2]; 103 | 104 | // Action 105 | colorCell(nextColorIndex); 106 | turn(nextTurn); 107 | state_(nextState); 108 | 109 | // Move 110 | move(); 111 | 112 | // Iteration 113 | iteration++; 114 | } 115 | 116 | grid.updatePixels(); 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /Forms/Turmites/Turmites.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Turmites 3 | 4 | — 5 | Based on : 6 | - http://en.wikipedia.org/wiki/Turmite 7 | - can't remember where I grabbed the table in Rules tab though ... 8 | 9 | — 10 | Developped and tested on : 11 | - Processing 2.1.1 on MacOSX (10.9.2) 12 | 13 | — 14 | Instructions : 15 | - click to generate new turmite. 16 | 17 | — 18 | Julien @v3ga Gachadoat 19 | www.v3ga.net 20 | www.2roqs.com 21 | 22 | */ 23 | 24 | 25 | // ------------------------------------------------------------------------------------------------ 26 | PImage grid; 27 | Turmite turmite; 28 | int div = 20; 29 | int ruleIndex = 0; 30 | 31 | // ------------------------------------------------------------------------------------------------ 32 | void setup() 33 | { 34 | size(800, 800, P2D); 35 | grid = createImage(width/div, height/div, RGB); 36 | turmite = new Turmite(grid, 0); 37 | setWindowTitle(); 38 | } 39 | 40 | // ------------------------------------------------------------------------------------------------ 41 | void draw() 42 | { 43 | turmite.run(); 44 | 45 | background(255); 46 | fill(0); 47 | grid.loadPixels(); 48 | int i, j, off; 49 | int x, y; 50 | color c; 51 | stroke(0); 52 | fill(0); 53 | noStroke(); 54 | rectMode(CENTER); 55 | 56 | for (i=0;i images.length-1) 61 | { 62 | indexImageCurrent=0; 63 | } 64 | } 65 | 66 | // Dessin de notre grille d'images 67 | // (Identique à ce que l'on a fait sur le dessin de «patterns») 68 | for (int j=0; j