/** * Moving Fractal Triangle Effect * by David Oxley. * * Uses bitwise XOR to generate the fractal triangle pattern * XOR copies and shifts pixels for scrolling effect */ // This will contain the pixels used to calculate the scrolling triangle effect int[][] fire; // Flame colors color[] palette; float angle; void setup(){ size(640, 480, P2D); frameRate(100); colorMode(HSB); fire = new int[width][height]; palette = new color[255]; // Generate the palette for(int x = 0; x < palette.length; x++) { //Hue goes from 0 to 85: red to yellow //Saturation is always the maximum: 255 //Lightness is 0..255 for x=0..128, and 255 for x=128..255 palette[x] = color(x/3, 255, constrain(x*3, 0, 255)); } } void draw() { angle = angle + 0.05; // Rotating wireframe cube /* pg.beginDraw(); pg.translate(width >> 1, height >> 1); pg.rotateX(sin(angle/2)); pg.rotateY(cos(angle/2)); pg.background(0); pg.stroke(128); pg.scale(25); pg.noFill(); pg.box(4); pg.endDraw(); */ // Randomize the bottom row of the fire buffer /* for(int x = 0; x < width; x++) { fire[x][height-1] = int(random(0,190)) ; } */ loadPixels(); //fire[320+20+int(10*sin(angle/3))][height-2] = 100; //fire[320][height-2] = 120; fire[600+int(30*sin(angle/3)*cos(angle/5))][height-65+int(60*sin(angle/2)*cos(angle/4))] = 100; int counter = 0; for (int y = 1; y < height-2; y++) { for(int x = 0; x < width; x++) { if (x > 2 && y > 2 && x < width-2 && y < height-2) { //fire[x-1][y-1] = fire[x][y-1] ^= fire[x][y]; fire[x-1][y-1] = fire[x][y]^fire[x][y-1]; //fire[x-2][y-1] = fire[x-1][y] ^= fire[x][y]; //fire[x+1][y-1] ^= fire[x][y]; //fire[x-1][y-1] = fire[x][y-1]; } pixels[counter] = palette[fire[x][y]]; counter++; } } updatePixels(); }