Repository: v3ga/Processing Branch: master Commit: f756857dd47d Files: 38 Total size: 69.9 KB Directory structure: gitextract_73h8wnpj/ ├── Animation/ │ └── OmbroCinema/ │ ├── OmbroCinema.pde │ ├── Scanimation.pde │ └── Utils.pde ├── 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 │ ├── LangtonAnt/ │ │ ├── Ant.pde │ │ ├── Grid.pde │ │ └── LangtonAnt.pde │ ├── LangtonAntMultiple/ │ │ ├── Ant.pde │ │ ├── Grid.pde │ │ └── LangtonAntMultiple.pde │ ├── Lorenz/ │ │ └── Lorenz.pde │ ├── MazeGenerator/ │ │ ├── Maze.pde │ │ └── MazeGenerator.pde │ ├── 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 ================================================ FILE CONTENTS ================================================ ================================================ FILE: Animation/OmbroCinema/OmbroCinema.pde ================================================ /* OmbroCinema — Developped and tested on : - Processing 2.1.1 on MacOSX (10.10.1) — Julien @v3ga Gachadoat www.v3ga.net www.2roqs.com — Keyboard : - 'i' draws the composition - 'c' draws the composition with mask - 'a' draws animation frames - 'e' exports composition (with timestamp) + mask to .pdf format */ // ------------------------------------------------------ import processing.pdf.*; // ------------------------------------------------------ Scanimation scanimation; int mode = 0; // ------------------------------------------------------ void setup() { size(600, 600); // Create the Scanimation instance, which will be made of 6 frames scanimation = new Scanimation(this, 6); // Compose the final frame (this is calling "drawScanimationFrame" for each frame) scanimation.composeFinalFrame(); // Set the animation period in seconds (use 'a' on keyboard) scanimation.setTimerPeriod(0.5); } // ------------------------------------------------------ void draw() { background(255); // Draws the composition if (mode == 0) { scanimation.draw(); } // Draws the composition with mask else if (mode == 1) { scanimation.drawWithMask(); } // Draws the animation else if (mode == 2) { scanimation.animate(); } } // ------------------------------------------------------ // Automatically called by composeFinalFrame void drawScanimationFrame(PGraphics pg, int frame, int nbFrames) { pg.translate(pg.width/2, pg.height/2); pg.rotate( map(frame, 0, nbFrames, 0, radians(90)) ); pg.noStroke(); pg.rectMode(CENTER); pg.rect(0,0,400,100); pg.ellipse(30,60,100,100); } // ------------------------------------------------------ void keyPressed() { if (key == 'i') { mode = 0; } else if (key == 'c') { mode = 1; } else if (key == 'a') { mode = 2; } else if (key == 'e') { scanimation.exportPDF(); } } ================================================ FILE: Animation/OmbroCinema/Scanimation.pde ================================================ import java.lang.reflect.*; // ------------------------------------------------------ class Scanimation { int nbFrames; PApplet applet; Method methodFrame; ArrayList listFrames; ArrayList listMaskedFrames; PGraphics compositionFrame; PGraphics maskFrame, maskFrameScreen, currentFrame; Timer timer; float periodChangeFrame = 0.25f; // seconds float timeChangeFrame=0.0f; int framePlaying = 0; boolean exportCompo = false; // ------------------------------------------------------ Scanimation(PApplet applet, int nbFrames) { this.applet = applet; this.nbFrames = nbFrames; createFrames(); findMethodFrame(); createTimer(); } // ------------------------------------------------------ Scanimation(PApplet applet) { this.applet = applet; this.nbFrames = 6; createFrames(); findMethodFrame(); createTimer(); } // ------------------------------------------------------ void createFrames() { listFrames = new ArrayList(); listMaskedFrames = new ArrayList(); for (int i=0;i=periodChangeFrame) { framePlaying = (framePlaying+1)%getNumberFrames(); resetTimer(); } PGraphics frame = getFrame(framePlaying); image(frame, 0, 0, width, height); } // ------------------------------------------------------ int getNumberFrames() { return nbFrames; } // ------------------------------------------------------ PGraphics getFrame(int i) { return listFrames.get(i); } // ------------------------------------------------------ PGraphics getFrameMasked(int i) { return listMaskedFrames.get(i); } // ------------------------------------------------------ PGraphics getCompositionFrame() { return compositionFrame; } // ------------------------------------------------------ PGraphics getMaskFrame() { return maskFrame; } // ------------------------------------------------------ PGraphics getMaskFrameScreen() { return maskFrameScreen; } // ------------------------------------------------------ void findMethodFrame() { try { this.methodFrame = applet.getClass().getMethod("drawScanimationFrame", new Class[] { PGraphics.class, Integer.TYPE, Integer.TYPE } ); System.out.println("- \"findMethodFrame\" found."); } catch (Exception e) { System.out.println("- no \"findMethodFrame\" found."); } } // ------------------------------------------------------ void composeFinalFrame() { if (methodFrame != null) { // Draw Each Frame PGraphics frame, frameMasked; for (int i=0;i=nbFrames) return; currentFrame = listFrames.get(i); currentFrame.beginDraw(); } // ------------------------------------------------------ void endFrame() { if (currentFrame!=null) currentFrame.endDraw(); } // ------------------------------------------------------ void draw() { if (exportCompo) { exportCompo = false; String time = timestamp(); beginRecord(PDF, "exports/"+time+"_export.pdf"); strokeCap(SQUARE); stroke(0, 255); strokeWeight(2); compositionFrame.loadPixels(); boolean isBeginLine = false; int r = 0, i=0, j=0, jbegin=0; for (i=0;i=254) { isBeginLine = false; line(i, jbegin, i, j-1); println("colonne end "+i+";j="+j); } } else { if (r<=5) { isBeginLine = true; jbegin = j; println("colonne begin "+i+";j="+j); } } } if (isBeginLine) { line(i, jbegin, i, compositionFrame.height); } } endRecord(); } image(compositionFrame, 0, 0, width, height); } // ------------------------------------------------------ void drawWithMask() { image(getCompositionFrame(),0,0); blend(getMaskFrameScreen(), 0, 0, width, height, mouseX-width/2, 0, width, height, BLEND); } // ------------------------------------------------------ void exportPDF() { exportCompo = true; } }; ================================================ FILE: Animation/OmbroCinema/Utils.pde ================================================ import java.util.Calendar; // ------------------------------------------------------ class Timer { float now, before; Timer() { now = before = millis(); } float update() { now = millis(); float dt = now-before; before = now; return dt/1000.0f; } } // ------------------------------------------------------ String timestamp() { Calendar now = Calendar.getInstance(); return String.format("%1$ty%1$tm%1$td_%1$tH%1$tM%1$tS", now); } ================================================ FILE: Forms/CellularAutomaton/Automaton.pde ================================================ class Automaton { Grid grid; int line=0; boolean done = false; int frameStep = 2; int rule = RULE_30; final static int RANDOM = 0; final static int CENTER = 1; final static int RULE_30 = 30; final static int RULE_110 = 110; Automaton(int rule, int initMode, int resx, int resy) { this.grid = new Grid(resx, resy); this.rule = rule; if (initMode == RANDOM) { for (int i=0; i0.5) this.grid.setState(i, 0, 1); } else if (initMode == CENTER) { this.grid.setState(resx/2, 0, 1); } } void setFrameStep(int n) { this.frameStep = max(1,n); } void setRule(int which) { this.rule = which; } boolean applyRule(int which, int s_1, int s0, int s1) { if (which == 30) { return ((s_1==1 && s0==0 && s1==0) || (s_1==0 && s0==1 && s1==1) || (s_1==0 && s0==1 && s1==0) || (s_1==0 && s0==0 && s1==1)); } else if (which == 110) { return ((s_1==1 && s0==1 && s1==0) || (s_1==1 && s0==0 && s1==1) || (s_1==0 && s0==1 && s1==1) || (s_1==0 && s0==1 && s1==0) || (s_1==0 && s0==0 && s1==1)); } return false; } void run() { if (this.done || frameCount%frameStep!=0) return; int i, j = line; int s_1, s0, s1; for (i=1; i= this.grid.resy-1) this.done = true; } void draw() { // this.grid.draw(); this.grid.drawState(); } } ================================================ FILE: Forms/CellularAutomaton/CellularAutomaton.pde ================================================ /* CellularAutomaton — An implementation of Rule 30 / 110 cellular automata described here: https://en.wikipedia.org/wiki/Rule_30 https://en.wikipedia.org/wiki/Rule_110 — Developped and tested on : - Processing 3.5.3 on Windows 10 — Julien @v3ga Gachadoat www.v3ga.net www.2roqs.com */ Automaton automaton; void setup() { size(500,500); surface.setTitle("Rule 30 / 110"); automaton = new Automaton(Automaton.RULE_110,Automaton.RANDOM,200,200); automaton.setFrameStep(2); // every "n" frames } void draw() { background(255); automaton.run(); automaton.draw(); } ================================================ FILE: Forms/CellularAutomaton/Grid.pde ================================================ class Grid { int resx, resy; int[] state; float cellw, cellh; Grid(int resx, int resy) { this.resx = resx; this.resy = resy; this.state = new int[resx*resy]; this.cellw = float(width) / resx; this.cellh = float(height) / resy; } void setState(int i, int j, int state) { this.state[i+j*this.resx] = state; } int getState(int i, int j) { return this.state[i+j*this.resx]; } void draw() { pushStyle(); stroke(220); float x=0.0, y=0.0; for (int i=0; i<=this.resy; i++) { x = i*this.cellw; line(x,0,x,height); } for (int i=0; i<=this.resy; i++) { y = i*this.cellh; line(0,y,width,y); } popStyle(); } void drawState() { pushStyle(); noStroke(); fill(0); int i, j; float x=0.0, y=0.0; int c = 0; for (j=0; j getHilbertPoints(int order, float x, float y, float w, float h) { ArrayList points = new ArrayList(); float w2 = w/2; float h2 = h/2; if (order == 1) { points.add(new PVector(x+w2/2, y+3*h2/2)); // SW points.add(new PVector(x+w2/2, y+h2/2)); // NW points.add(new PVector(x+3*w2/2, y+h2/2)); // NE points.add(new PVector(x+3*w2/2, y+3*h2/2)); // SE } else { ArrayList pointsNW = getHilbertPoints(order-1, x, y, w2, h2); ArrayList pointsNE = getHilbertPoints(order-1, x+w2, y, w2, h2); ArrayList pointsSW = getHilbertPoints(order-1, x, y+h2, w2, h2); ArrayList pointsSE = getHilbertPoints(order-1, x+w2, y+h2, w2, h2); flipPoints(90, pointsSW, x, y+h2, w2, h2); flipPoints(-90, pointsSE, x+w2, y+h2, w2, h2); points.addAll(pointsSW); points.addAll(pointsNW); points.addAll(pointsNE); points.addAll(pointsSE); } return points; } // ------------------------------------------------------------------------------------------------ void flipPoints(int which, ArrayList source, float x, float y, float w, float h) { if (which == 90) { for (PVector p : source) p.set( x + w - (p.y-y), y + p.x-x ); } else if (which == -90) { for (PVector p : source) p.set( x + (p.y-y), y + h-(p.x-x) ); } Collections.reverse(source); } ================================================ FILE: Forms/L_System/LInterpreter.pde ================================================ interface LInterpreter { void run(String s); } ================================================ FILE: Forms/L_System/LRule.pde ================================================ class LRule { char variable; String replacement; LRule(char v, String r) { this.variable = v; this.replacement = r; } String apply() { return replacement; } } ================================================ FILE: Forms/L_System/LSystem.pde ================================================ class LSystem { String seed = ""; int generation = 0; ArrayList listGenerations; ArrayList listRules; String str=""; LInterpreter interpreter; String infos=""; LSystem(String seed) { init(seed); } LSystem(String seed,LInterpreter interpreter) { init(seed); setInterpreter(interpreter); } void init(String seed) { this.seed = this.str = seed; this.listGenerations = new ArrayList(); this.listRules = new ArrayList(); this.listGenerations.add(seed); } void setInterpreter(LInterpreter interpreter) { this.interpreter = interpreter; } void addRule(char c, String r) { addRule( new LRule(c,r) ); } void addRule(LRule r) { this.listRules.add(r); } void grow(int generations) { for (int i=0;i0) return generation; return -1; } void draw() { draw(interpreter,getLastGeneration()); } void draw(LInterpreter interpreter, int generation) { if (interpreter!=null && generation!=-1) { interpreter.run( listGenerations.get(generation) ); } } void drawInfos() { if (infos.equals("")){ infos += seed+"\n"; for (LRule rule:listRules) { infos+=rule.variable+" to "+rule.replacement+"\n"; } } fill(0); textSize(11); text(infos,4,12); } String toString() { String s = generation+" generations\n"; s+="----"; int i=0; for (String str:listGenerations) { s+= i+"-"+str+"["+str.length()+" chars]\n"; i++; } return s; } } ================================================ FILE: Forms/L_System/L_System.pde ================================================ /* L_system — Developped and tested on : - Processing 2.1.1 on MacOSX (10.9.2) — Julien @v3ga Gachadoat www.v3ga.net www.2roqs.com */ // ------------------------------------------------------------------------------------------------ LSystem ls2; // ------------------------------------------------------------------------------------------------ void setup() { ls2 = new LSystem("X", new LInterpreterF()); ls2.addRule('X', "F-[[X]+X]+FF[+FX]-X"); ls2.addRule('F', "FF"); ls2.grow(6); println(ls2); size(500,500); smooth(); } // ------------------------------------------------------------------------------------------------ void draw() { background(255); pushMatrix(); translate(width/2, height); ls2.draw(); popMatrix(); ls2.drawInfos(); } // ------------------------------------------------------------------------------------------------ void mousePressed() { saveFrame("lsystem.png"); } // ------------------------------------------------------------------------------------------------ class LInterpreterF implements LInterpreter { float angle = PI/10; float length = 2.1; LInterpreterF() { } void run(String s) { length=map(mouseY,0,height,1,3); angle=map(mouseX,0,width,0,PI); stroke(0); noFill(); int nbChars = s.length(); char c; for (int i=0;i 0, 1->90, 2->180, 3->270 Ant(Grid grid, int i, int j) { this.grid = grid; this.i = i%this.grid.resx; this.j = j%this.grid.resy; this.turn=0; } void run() { //if (frameCount % 2 == 0) { // check the state of the grid int c = this.grid.getState(this.i, this.j); // White square if (c == 0) { this.grid.setState(this.i, this.j, 1); this.turn90CW(); this.move(); } // Black square else if (c == 1) { this.grid.setState(this.i, this.j, 0); this.turn90CCW(); this.move(); } } } void turn90CW() { turn = (turn+1)%4; } void turn90CCW() { turn = turn-1; if (turn<0) turn = 3; } void move() { if (turn == 0) this.i +=1; else if (turn == 1) this.j +=1; else if (turn == 2) this.i -=1; else if (turn == 3) this.j -=1; if (this.i >= this.grid.resx) this.i=0; else if (this.i < 0) this.i=this.grid.resx-1; if (this.j >= this.grid.resy) this.j=0; else if (this.j < 0) this.j=this.grid.resy-1; } } ================================================ FILE: Forms/LangtonAnt/Grid.pde ================================================ class Grid { int resx, resy; int[] state; float cellw, cellh; Grid(int resx, int resy) { this.resx = resx; this.resy = resy; this.state = new int[resx*resy]; this.cellw = float(width) / resx; this.cellh = float(height) / resy; } void setState(int i, int j, int state) { this.state[i+j*this.resx] = state; } int getState(int i, int j) { return this.state[i+j*this.resx]; } void draw() { pushStyle(); stroke(220); float x=0.0, y=0.0; for (int i=0; i<=this.resy; i++) { x = i*this.cellw; line(x,0,x,height); } for (int i=0; i<=this.resy; i++) { y = i*this.cellh; line(0,y,width,y); } popStyle(); } void drawState() { pushStyle(); noStroke(); fill(0); int i, j; float x=0.0, y=0.0; int c = 0; for (j=0; j 0, 1->90, 2->180, 3->270 Ant(Grid grid, int i, int j) { this.grid = grid; this.i = i%this.grid.resx; this.j = j%this.grid.resy; this.turn=0; } void run() { //if (frameCount % 2 == 0) { // check the state of the grid int c = this.grid.getState(this.i, this.j); // White square if (c == 0) { this.grid.setState(this.i, this.j, 1); this.turn90CW(); this.move(); } // Black square else if (c == 1) { this.grid.setState(this.i, this.j, 0); this.turn90CCW(); this.move(); } } } void turn90CW() { turn = (turn+1)%4; } void turn90CCW() { turn = turn-1; if (turn<0) turn = 3; } void move() { if (turn == 0) this.i +=1; else if (turn == 1) this.j +=1; else if (turn == 2) this.i -=1; else if (turn == 3) this.j -=1; if (this.i >= this.grid.resx) this.i=0; else if (this.i < 0) this.i=this.grid.resx-1; if (this.j >= this.grid.resy) this.j=0; else if (this.j < 0) this.j=this.grid.resy-1; } } ================================================ FILE: Forms/LangtonAntMultiple/Grid.pde ================================================ class Grid { int resx, resy; int[] state; float cellw, cellh; Grid(int resx, int resy) { this.resx = resx; this.resy = resy; this.state = new int[resx*resy]; this.cellw = float(width) / resx; this.cellh = float(height) / resy; } void setState(int i, int j, int state) { this.state[i+j*this.resx] = state; } int getState(int i, int j) { return this.state[i+j*this.resx]; } void draw() { pushStyle(); stroke(220); float x=0.0, y=0.0; for (int i=0; i<=this.resy; i++) { x = i*this.cellw; line(x,0,x,height); } for (int i=0; i<=this.resy; i++) { y = i*this.cellh; line(0,y,width,y); } popStyle(); } void drawState() { pushStyle(); noStroke(); fill(0); int i, j; float x=0.0, y=0.0; int c = 0; for (j=0; j ants = new ArrayList(); boolean bDrawGrid = false; void setup() { size(500,500); grid = new Grid(100,100); addAnt(50,50); } void draw() { background(255); for (Ant ant : ants) ant.run(); if (bDrawGrid) grid.draw(); grid.drawState(); } void mousePressed() { addAnt(floor(mouseX/grid.cellw), floor(mouseY/grid.cellh)); } void addAnt(int i, int j) { ants.add( new Ant(grid,i,j) ); } ================================================ FILE: Forms/Lorenz/Lorenz.pde ================================================ /* Lorenz attractors — Developped and tested on : - Processing 2.1.1 on MacOSX (10.9.4) — Julien @v3ga Gachadoat www.v3ga.net www.2roqs.com */ // ------------------------------------------------------------------------------------------------ import controlP5.*; // ------------------------------------------------------------------------------------------------ PGraphics offscreen; // ------------------------------------------------------------------------------------------------ float x=1.0, x1=0.0; float y=1.0, y1=0.0; float z=1.0, z1=0.0; // ------------------------------------------------------------------------------------------------ float s = 5.0; float p = 15.0; float b = 1.0; float dt = 0.005; float scale = 6; // ------------------------------------------------------------------------------------------------ ControlP5 controls; // ------------------------------------------------------------------------------------------------ void setup() { size(800, 400, P3D); controls = new ControlP5(this); controls.begin(5,5); controls.addSlider("s", 1.0,30.0).linebreak(); controls.addSlider("p", 1.0,30.0).linebreak(); controls.addSlider("b", 1.0,30.0).linebreak(); controls.addSlider("scale", 1.0,10.0).linebreak(); controls.addButton("reset").setSize(30,14).linebreak(); controls.end(); offscreen = createGraphics(width, height,P3D); reset(); } // ------------------------------------------------------------------------------------------------ void draw() { drawOffscreen(); image(offscreen,0,0); } // ------------------------------------------------------------------------------------------------ void clearOffscreen() { offscreen.beginDraw(); offscreen.background(0); offscreen.endDraw(); } // ------------------------------------------------------------------------------------------------ void drawOffscreen() { x1 = x + dt*s*(y-x); y1 = y + dt*(p*x - y - x*z); z1 = z + dt*(x*y - b*z); offscreen.beginDraw(); offscreen.translate(width/2, height/2); offscreen.stroke(255); offscreen.line(scale*x1, scale*y1, scale*z1, scale*x, scale*y, scale*z); offscreen.endDraw(); x = x1; y = y1; z = z1; } // ------------------------------------------------------------------------------------------------ void reset() { x=random(-5,5); x1=0.0; y=random(-5,5); y1=0.0; z=random(-5,5); z1=0.0; clearOffscreen(); } ================================================ FILE: Forms/MazeGenerator/Maze.pde ================================================ class Maze { // Maze structure MazeCell[] cells; int resx, resy, nbCells; // Iteration variables ArrayList stack; MazeCell cellCurrent; int nbCellsVisited=0; int cellStartx = 0, cellStarty = 0; boolean computed = false; // Step by step variables boolean stepByStep = false; float time = 0.0f; float timeStep = 0.0015f; // Solution ArrayList solution; Maze(int resx, int resy) { this.resx = resx; this.resy = resy; this.nbCells = resx * resy; resetCells(); } void setCellStart(int x, int y) { if (x>=resx) x=0; if (y>=resy) y=0; this.cellStartx = x; this.cellStarty = y; } void setTimeStepByStep(float t) { this.timeStep = t; } boolean isComputed() { return computed; } void resetCells() { this.cells = new MazeCell[nbCells]; int k=0; for (int j=0; j=0 && x=0 && y cellNeighbor.y) { cellCurrent.hasNorth = false; cellNeighbor.hasSouth = false; } else { cellCurrent.hasSouth = false; cellNeighbor.hasNorth = false; } } else if (cellCurrent.y == cellNeighbor.y) { if (cellCurrent.x > cellNeighbor.x) { cellCurrent.hasWest = false; cellNeighbor.hasEast = false; } else { cellCurrent.hasEast = false; cellNeighbor.hasWest = false; } } } void reset() { resetCells(); cellCurrent = getCell(cellStartx, cellStarty); setCellVisited(cellCurrent); stack = new ArrayList(); } void compute() { reset(); stepByStep = false; computed = false; while (nbCellsVisited= timeStep*1000) { step(); time = timeNow; } } else computed = true; } void step() { if (hasCellNeightborUnvisited(cellCurrent)) { stack.add( cellCurrent ); MazeCell cellNeighbor = findCellNeightborUnvisited(cellCurrent); removeCellsWalls(cellCurrent, cellNeighbor); cellCurrent = cellNeighbor; setCellVisited(cellCurrent); } else { if (stack.size()>0) { cellCurrent = stack.remove( stack.size()-1 ); } } } void draw() { for (int i=0; i(); MazeCell cellCurrent = getCell(cellStartx, cellStarty); } } } class MazeCell { int x, y; float w, h; boolean hasNorth = true; boolean hasEast = true; boolean hasSouth = true; boolean hasWest = true; boolean visited = false; Maze parent; MazeCell(int x, int y, Maze parent) { this.x = x; this.y = y; this.parent = parent; this.w = (float)width/(float)parent.resx; this.h = (float)height/(float)parent.resy; } void draw() { float xx = (float)x; float yy = (float)y; float x1 = xx*w; float x2 = (xx+1)*w; float y1 = yy*h; float y2 = (yy+1)*h; if (x2>=width) x2=width-1; if (y2>=height) y2=height-1; if (visited && parent.stepByStep) { pushStyle(); noStroke(); fill(200); rectMode(CORNERS); rect(x1, y1, x2, y2); popStyle(); } if (hasNorth) line(x1, y1, x2, y1); if (hasEast) line(x2, y1, x2, y2); if (hasSouth) line(x1, y2, x2, y2); if (hasWest) line(x1, y1, x1, y2); } } ================================================ FILE: Forms/MazeGenerator/MazeGenerator.pde ================================================ /* MazeGenerator — An implementation of recursive backtracker algorithm described here: https://en.wikipedia.org/wiki/Maze_generation_algorithm — Developped and tested on : - Processing 3.0b4 on MacOSX (10.10.5) — Julien @v3ga Gachadoat www.v3ga.net www.2roqs.com */ Maze maze; void setup() { size(500, 500); maze = new Maze(25, 25); maze.setCellStart(0, 0); //maze.compute(); maze.beginComputeStepByStep(); } void draw() { background(255); stroke(0); strokeWeight(1); maze.computeStepByStep(); maze.draw(); } void mousePressed() { maze.compute(); } void keyPressed() { if (key == 'e') saveFrame("maze.png"); } ================================================ FILE: Forms/Penrose/Penrose.pde ================================================ /* Penrose — Based on explanations found here : https://en.wikipedia.org/wiki/Penrose_tiling http://preshing.com/20110831/penrose-tiling-explained/ — Developped and tested on : - Processing 3.2.1 on MacOSX (10.12.5) — Julien @v3ga Gachadoat www.v3ga.net www.2roqs.com */ // ------------------------------------------------------------------------------------------------ Sun sun; // ------------------------------------------------------------------------------------------------ void setup() { size(500, 500,P2D); sun = new Sun(7, 0.48*height); } // ------------------------------------------------------------------------------------------------ void draw() { translate(width/2, height/2); background(0); noStroke(); sun.draw(); } // ------------------------------------------------------------------------------------------------ void keyPressed() { if (key == 's') saveFrame("Penrose.png"); } ================================================ FILE: Forms/Penrose/Sun.pde ================================================ class Sun { int nbTriangles = 10; Triangle[] triangles = new Triangle[nbTriangles]; Sun(int subdivide, float r) { for (int i = 0; i < nbTriangles; i++) { float start = (2*i-1) * PI/nbTriangles; float end = (2*i+1) * PI/nbTriangles; PVector A = new PVector(0, 0); PVector B = new PVector(r*cos(start), r*sin(start)); PVector C = new PVector(r*cos(end), r*sin(end)); triangles[i] = new Triangle(0, A, i%2 == 0 ? B : C, i%2 == 0 ? C : B); triangles[i].subdivide(subdivide); } } void draw() { for (int i = 0; i < nbTriangles; i++) triangles[i].draw(); } } ================================================ FILE: Forms/Penrose/Triangle.pde ================================================ class Triangle { final static float phi = 1.61803398875; int type = 0; int level = 0; PVector A = new PVector(); PVector B = new PVector(); PVector C = new PVector(); Triangle[] children; Triangle(int type, PVector A, PVector B, PVector C) { this.type = type; this.level = 0; this.A = A; this.B = B; this.C = C; } Triangle(int type, PVector A, PVector B, PVector C, int level) { this.type = type; this.level = level; this.A = A; this.B = B; this.C = C; } void draw() { if (children != null) { for (int i=0; i= '1' && key <='6') re.setDrawMode(key-'0'); } ================================================ FILE: Forms/RuttEtra/RuttEtraizer.pde ================================================ class RuttEtraizer { PGraphics imgSmall; PImage imgRef; int blurImgSmall = 1; int drawMode = 1; int s = 8; float filterTh = 0.5; // ------------------------------------------------------ // RuttEtra // ------------------------------------------------------ RuttEtraizer(PImage img, int s) { imgRef = img; setScale(s); resizeImageSmall(); } // ------------------------------------------------------ // setImgRef // ------------------------------------------------------ void setImgRef(PImage img) { this.imgRef = img; resizeImageSmall(); } // ------------------------------------------------------ // resizeImg // ------------------------------------------------------ PImage getImageResized() { return imgSmall; } // ------------------------------------------------------ // setDrawMode // ------------------------------------------------------ void setDrawMode(int i) { drawMode = i; } // ------------------------------------------------------ // setBlur // ------------------------------------------------------ void setBlur(int b) { blurImgSmall = b; blurImgSmall=constrain(blurImgSmall, 0, 10); } // ------------------------------------------------------ // increaseBlur // ------------------------------------------------------ void increaseBlur() { setBlur(++blurImgSmall); } // ------------------------------------------------------ // decreaseBlur // ------------------------------------------------------ void decreaseBlur() { setBlur(--blurImgSmall); } // ------------------------------------------------------ // setScale // ------------------------------------------------------ void setScale(int s) { this.s = s; this.s = constrain(s, 2, 8); resizeImageSmall(); } // ------------------------------------------------------ // apply // ------------------------------------------------------ void apply() { imgSmall.beginDraw(); imgRef.filter(THRESHOLD, filterTh); imgRef.filter(BLUR, blurImgSmall); imgSmall.image(imgRef, 0, 0, imgSmall.width, imgSmall.height); imgSmall.endDraw(); } // ------------------------------------------------------ // resizeImageSmall // ------------------------------------------------------ void resizeImageSmall() { imgSmall = createGraphics(imgRef.width/s, imgRef.height/s); apply(); } // ------------------------------------------------------ // draw // ------------------------------------------------------ void draw(PApplet applet, float h) { draw(applet.g, h); } // ------------------------------------------------------ // draw // ------------------------------------------------------ void draw(PGraphics g, float h) { if (drawMode == 1) drawLines(g,imgSmall, h); else if (drawMode == 2) drawPoints(g,imgSmall); else if (drawMode == 3) drawTriangles(g,imgSmall, h); else if (drawMode == 4) drawLines2(g,imgSmall, 280); else if (drawMode == 5) { drawLines(g,imgSmall, h); drawLines2(g,imgSmall, h); } else if (drawMode == 6) { drawMesh(g,imgSmall, h); g.stroke(255,255); g.pushMatrix(); g.translate(0,0,2); drawLines(g, imgSmall, h); g.popMatrix(); } } // ------------------------------------------------------ // drawPoints // ------------------------------------------------------ void drawPoints(PGraphics g,PImage img) { int i, j, offset; int w = img.width; int h = img.height; int gg = 0; g.pushMatrix(); g.translate(-s*img.width/2, -s*img.height/2); img.loadPixels(); for (j=0;j lines; int res = 500; int res2 = 60; float r2 = 100.0; int renderMode = 0; // Constructor TorusKnot(float R_, float R2_, float P_, float Q_, int res_, int res2_, int renderMode_) { R = R_; r2 = R2_; P = P_; Q = Q_; res = res_; res2 = res2_; renderMode = renderMode_; // mesh = new TriangleMesh(); lines = new ArrayList(); PVector A, B; float[] b; Matrix4x4 transfo = new Matrix4x4(); Matrix4x4 basisM = new Matrix4x4(); float th = 0.0; float dth = 360.0/(res) ; points = new Vec3D[res][res2]; normals = new Vec3D[res][res2]; for (int i=0; i= r.length) which = 0; this.ruleIndex = which; } boolean color0(color c) { return (red(c) == 255); } boolean color1(color c) { return (red(c) == 0); } int colorIndex(color pixel) { if (color0(pixel)) return 0; if (color1(pixel)) return 1; return -1; } void colorCell(int colorIndex) { offset = this.x + grid.width*this.y; grid.pixels[offset] = color(colorIndex == 0 ? 255 : 0); } void turn(int which) { this.direction = TurmiteTurn[which][direction]; } void state_(int which) { this.state = which; } void move() { switch(direction) { case 0: y = y-1; if (y<0) y=grid.height-1; break; case 1: x = (x+1)%grid.width; break; case 2: y = (y+1)%grid.height; break; case 3: x = x-1; if (x<0) x=grid.width-1; break; } } void run() { grid.loadPixels(); color pixel = grid.get(x, y); // Rule int c = colorIndex(pixel); if (c>=0) { int[] next = r[ruleIndex][state][c]; int nextColorIndex = next[0]; int nextTurn = next[1]; int nextState = next[2]; // Action colorCell(nextColorIndex); turn(nextTurn); state_(nextState); // Move move(); // Iteration iteration++; } grid.updatePixels(); } } ================================================ FILE: Forms/Turmites/Turmites.pde ================================================ /* Turmites — Based on : - http://en.wikipedia.org/wiki/Turmite - can't remember where I grabbed the table in Rules tab though ... — Developped and tested on : - Processing 2.1.1 on MacOSX (10.9.2) — Instructions : - click to generate new turmite. — Julien @v3ga Gachadoat www.v3ga.net www.2roqs.com */ // ------------------------------------------------------------------------------------------------ PImage grid; Turmite turmite; int div = 20; int ruleIndex = 0; // ------------------------------------------------------------------------------------------------ void setup() { size(800, 800, P2D); grid = createImage(width/div, height/div, RGB); turmite = new Turmite(grid, 0); setWindowTitle(); } // ------------------------------------------------------------------------------------------------ void draw() { turmite.run(); background(255); fill(0); grid.loadPixels(); int i, j, off; int x, y; color c; stroke(0); fill(0); noStroke(); rectMode(CENTER); for (i=0;i images.length-1) { indexImageCurrent=0; } } // Dessin de notre grille d'images // (Identique à ce que l'on a fait sur le dessin de «patterns») for (int j=0; j