From 3b84c790cd5827b503cede6d9af9acc040f0188c Mon Sep 17 00:00:00 2001 From: Casey Reas Date: Tue, 6 Sep 2011 04:13:14 +0000 Subject: [PATCH] Remove Effects from Topic examples --- .../Cellular Automata/Spore2/Spore2.pde | 2 +- .../Topics/Cellular Automata/Wolfram/CA.pde | 33 ++--- .../Topics/Effects/FireCube/FireCube.pde | 112 ----------------- java/examples/Topics/Effects/Lens/Lens.pde | 105 ---------------- .../Topics/Effects/Metaball/Metaball.pde | 76 ------------ .../examples/Topics/Effects/Plasma/Plasma.pde | 60 --------- .../examples/Topics/Effects/Tunnel/Tunnel.pde | 114 ------------------ .../UnlimitedSprites/UnlimitedSprites.pde | 60 --------- .../Topics/Effects/Wormhole/Wormhole.pde | 70 ----------- .../Topics/Effects/Wormhole/data/texture.gif | Bin 95 -> 0 bytes .../Mandelbrot/Mandelbrot.pde | 110 +++++++++-------- 11 files changed, 74 insertions(+), 668 deletions(-) delete mode 100644 java/examples/Topics/Effects/FireCube/FireCube.pde delete mode 100644 java/examples/Topics/Effects/Lens/Lens.pde delete mode 100644 java/examples/Topics/Effects/Metaball/Metaball.pde delete mode 100644 java/examples/Topics/Effects/Plasma/Plasma.pde delete mode 100644 java/examples/Topics/Effects/Tunnel/Tunnel.pde delete mode 100644 java/examples/Topics/Effects/UnlimitedSprites/UnlimitedSprites.pde delete mode 100644 java/examples/Topics/Effects/Wormhole/Wormhole.pde delete mode 100644 java/examples/Topics/Effects/Wormhole/data/texture.gif diff --git a/java/examples/Topics/Cellular Automata/Spore2/Spore2.pde b/java/examples/Topics/Cellular Automata/Spore2/Spore2.pde index ab4cc8397..2ad9da4b7 100644 --- a/java/examples/Topics/Cellular Automata/Spore2/Spore2.pde +++ b/java/examples/Topics/Cellular Automata/Spore2/Spore2.pde @@ -20,7 +20,7 @@ int runs_per_loop = 10000; void setup() { - size(640, 200, P2D); + size(640, 360); frameRate(24); clearscr(); w = new World(); diff --git a/java/examples/Topics/Cellular Automata/Wolfram/CA.pde b/java/examples/Topics/Cellular Automata/Wolfram/CA.pde index 30d02a378..9d468253b 100644 --- a/java/examples/Topics/Cellular Automata/Wolfram/CA.pde +++ b/java/examples/Topics/Cellular Automata/Wolfram/CA.pde @@ -51,18 +51,24 @@ class CA { int left = cells[i-1]; // Left neighbor state int me = cells[i]; // Current state int right = cells[i+1]; // Right neighbor state - nextgen[i] = rules(left,me,right); // Compute next generation state based on ruleset + nextgen[i] = executeRules(left,me,right); // Compute next generation state based on ruleset } // Copy the array into current value - cells = (int[]) nextgen.clone(); + for (int i = 1; i < cells.length-1; i++) { + cells[i] = nextgen[i]; + } + //cells = (int[]) nextgen.clone(); generation++; } // This is the easy part, just draw the cells, fill 255 for '1', fill 0 for '0' void render() { for (int i = 0; i < cells.length; i++) { - if (cells[i] == 1) fill(255); - else fill(0); + if (cells[i] == 1) { + fill(255); + } else { + fill(0); + } noStroke(); rect(i*scl,generation*scl, scl,scl); } @@ -70,15 +76,15 @@ class CA { // Implementing the Wolfram rules // Could be improved and made more concise, but here we can explicitly see what is going on for each case - int rules (int a, int b, int c) { - if (a == 1 && b == 1 && c == 1) return rules[0]; - if (a == 1 && b == 1 && c == 0) return rules[1]; - if (a == 1 && b == 0 && c == 1) return rules[2]; - if (a == 1 && b == 0 && c == 0) return rules[3]; - if (a == 0 && b == 1 && c == 1) return rules[4]; - if (a == 0 && b == 1 && c == 0) return rules[5]; - if (a == 0 && b == 0 && c == 1) return rules[6]; - if (a == 0 && b == 0 && c == 0) return rules[7]; + int executeRules (int a, int b, int c) { + if (a == 1 && b == 1 && c == 1) { return rules[0]; } + if (a == 1 && b == 1 && c == 0) { return rules[1]; } + if (a == 1 && b == 0 && c == 1) { return rules[2]; } + if (a == 1 && b == 0 && c == 0) { return rules[3]; } + if (a == 0 && b == 1 && c == 1) { return rules[4]; } + if (a == 0 && b == 1 && c == 0) { return rules[5]; } + if (a == 0 && b == 0 && c == 1) { return rules[6]; } + if (a == 0 && b == 0 && c == 0) { return rules[7]; } return 0; } @@ -91,4 +97,3 @@ class CA { } } } - diff --git a/java/examples/Topics/Effects/FireCube/FireCube.pde b/java/examples/Topics/Effects/FireCube/FireCube.pde deleted file mode 100644 index 7c7247fc0..000000000 --- a/java/examples/Topics/Effects/FireCube/FireCube.pde +++ /dev/null @@ -1,112 +0,0 @@ -/** - * Fire Cube demo effect - * by luis2048. - * - * A rotating wireframe cube with flames rising up the screen. - * The fire effect has been used quite often for oldskool demos. - * First you create a palette of 256 colors ranging from red to - * yellow (including black). For every frame, calculate each row - * of pixels based on the two rows below it: The value of each pixel, - * becomes the sum of the 3 pixels below it (one directly below, one - * to the left, and one to the right), and one pixel directly two - * rows below it. Then divide the sum so that the fire dies out as - * it rises. - */ - -// This will contain the pixels used to calculate the fire effect -int[][] fire; - -// Flame colors -color[] palette; -float angle; -int[] calc1,calc2,calc3,calc4,calc5; - -PGraphics pg; - -void setup(){ - size(640, 360, P2D); - - // Create buffered image for 3d cube - pg = createGraphics(width, height, P3D); - - calc1 = new int[width]; - calc3 = new int[width]; - calc4 = new int[width]; - calc2 = new int[height]; - calc5 = new int[height]; - - 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)); - } - - // Precalculate which pixel values to add during animation loop - // this speeds up the effect by 10fps - for (int x = 0; x < width; x++) { - calc1[x] = x % width; - calc3[x] = (x - 1 + width) % width; - calc4[x] = (x + 1) % width; - } - - for(int y = 0; y < height; y++) { - calc2[y] = (y + 1) % height; - calc5[y] = (y + 2) % height; - } -} - -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(); - - int counter = 0; - // Do the fire calculations for every pixel, from top to bottom - for (int y = 0; y < height; y++) { - for(int x = 0; x < width; x++) { - // Add pixel values around current pixel - - fire[x][y] = - ((fire[calc3[x]][calc2[y]] - + fire[calc1[x]][calc2[y]] - + fire[calc4[x]][calc2[y]] - + fire[calc1[x]][calc5[y]]) << 5) / 129; - - // Output everything to screen using our palette colors - pixels[counter] = palette[fire[x][y]]; - - // Extract the red value using right shift and bit mask - // equivalent of red(pg.pixels[x+y*w]) - if ((pg.pixels[counter++] >> 16 & 0xFF) == 128) { - // Only map 3D cube 'lit' pixels onto fire array needed for next frame - fire[x][y] = 128; - } - } - } - updatePixels(); -} diff --git a/java/examples/Topics/Effects/Lens/Lens.pde b/java/examples/Topics/Effects/Lens/Lens.pde deleted file mode 100644 index 804ff14fd..000000000 --- a/java/examples/Topics/Effects/Lens/Lens.pde +++ /dev/null @@ -1,105 +0,0 @@ -/** - * Lens Demo Effect - * by luis2048. - * - * A picture is shown and it looks like a magnifying glass - * is drawn over the picture. One of the most famous demos - * that has a lens effect is 2nd reality by future crew. - * The trick is to precalculate the entire effect. Just make - * an array that for each pixel in the destination picture - * tells which pixel to take from the source picture. This - * array is called the transformation array. The tricky part - * is to calculate the transformation array to make the - * destination look like a lens is beeing held over the source - * picture. Based on lens formula by on Abe Racadabra. - */ - -int lensD = 256; // Lens diameter -int[] lensArray = new int[lensD*lensD]; // Height and width of lens - -PGraphics lensEffect; -PImage lensImage; -PImage lensImage2; - -int xx = 0; -int yy = 0; -int dx = 1; -int dy = 1; - -void setup() { - - size(640, 360); - - // Create buffered image for lens effect - lensEffect = createGraphics(width, height, P2D); - - // Load background image - lensEffect.beginDraw(); - lensEffect.image(loadImage("red_smoke.jpg"), 0, 0, - lensEffect.width, lensEffect.height); - lensEffect.endDraw(); - - // Create buffered image for image to warp - lensImage = createGraphics(lensD, lensD, P2D); - lensImage2 = createGraphics(lensD, lensD, P2D); - - // Lens algorithm (transformation array) - int magFactor = 40; // Magnification factor - int m, a, b; - - int r = lensD / 2; - float s = sqrt(r*r - magFactor*magFactor); - - for (int y = -r; y < r; y++) { - for (int x = -r ;x < r; x++) { - if(x*x + y*y >= s*s) { - a = x; - b = y; - } - else { - float z = sqrt(r*r - x*x - y*y); - a = int(x * magFactor / z + 0.5); - b = int(y * magFactor / z + 0.5); - } - lensArray[(y + r)*lensD + (x + r)] = (b + r) * lensD + (a + r); - } - } -} - -void draw() { - - // Bounce lens around the screen - if((xx+dx+lensD > lensEffect.width) || (xx+dx < 0)) { - dx =- dx; - } - if((yy+dy+lensD > lensEffect.height) || (yy+dy < 0)) { - dy =- dy; - } - xx += dx; - yy += dy; - - lensImage = createGraphics(lensD, lensD, P2D); - - // save the backgrounlensD of lensHeight*lensWilensDth pixels rectangle at the coorlensDinates - // where the lens effect will be applielensD. - lensImage2.copy(lensEffect, xx, yy, lensD, lensD, 0, 0, lensD, lensD); - - // output into a bufferelensD image for reuse - lensImage.loadPixels(); - - // For each pixel in the destination rectangle, apply the color - // from the appropriate pixel in the saved background. The lensArray - // array tells the offset into the saved background. - for (int i = 0; i < lensImage.pixels.length; i++) { - lensImage.pixels[i] = lensImage2.pixels[lensArray[i]]; - } - lensImage.updatePixels(); - - // Restore the original picture - image(lensEffect, 0, 0, width, height); - - // Overlay the lens square - image(lensImage, xx, yy, lensD, lensD); - -} - diff --git a/java/examples/Topics/Effects/Metaball/Metaball.pde b/java/examples/Topics/Effects/Metaball/Metaball.pde deleted file mode 100644 index cde5d1c4a..000000000 --- a/java/examples/Topics/Effects/Metaball/Metaball.pde +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Metaball Demo Effect - * by luis2048. - * - * Organic-looking n-dimensional objects. The technique for rendering - * metaballs was invented by Jim Blinn in the early 1980s. Each metaball - * is defined as a function in n-dimensions. - */ - -int numBlobs = 3; - -int[] blogPx = { 0, 90, 90 }; -int[] blogPy = { 0, 120, 45 }; - -// Movement vector for each blob -int[] blogDx = { 1, 1, 1 }; -int[] blogDy = { 1, 1, 1 }; - -PGraphics pg; -int[][] vy,vx; - -void setup() { - size(640, 360); - pg = createGraphics(160, 90, P2D); - vy = new int[numBlobs][pg.height]; - vx = new int[numBlobs][pg.width]; -} - -void draw() { - for (int i=0; i pg.width) { - blogDx[i] = -1; - } - if (blogPy[i] < 0) { - blogDy[i] = 1; - } - if (blogPy[i] > pg.height) { - blogDy[i]=-1; - } - - for (int x = 0; x < pg.width; x++) { - vx[i][x] = int(sq(blogPx[i]-x)); - } - - for (int y = 0; y < pg.height; y++) { - vy[i][y] = int(sq(blogPy[i]-y)); - } - } - - // Output into a buffered image for reuse - pg.beginDraw(); - pg.loadPixels(); - for (int y = 0; y < pg.height; y++) { - for (int x = 0; x < pg.width; x++) { - int m = 1; - for (int i = 0; i < numBlobs; i++) { - // Increase this number to make your blobs bigger - m += 60000/(vy[i][y] + vx[i][x]+1); - } - pg.pixels[x+y*pg.width] = color(0, m+x, (x+m+y)/2); - } - } - pg.updatePixels(); - pg.endDraw(); - - // Display the results - image(pg, 0, 0, width, height); -} - diff --git a/java/examples/Topics/Effects/Plasma/Plasma.pde b/java/examples/Topics/Effects/Plasma/Plasma.pde deleted file mode 100644 index 04b20d84d..000000000 --- a/java/examples/Topics/Effects/Plasma/Plasma.pde +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Plasma Demo Effect - * by luis2048. - * - * Cycles of changing colours warped to give an illusion - * of liquid, organic movement.Colors are the sum of sine - * functions and various formulas. Based on formula by Robert Klep. - */ - -int pixelSize=2; -PGraphics pg; - -void setup(){ - size(640, 360); - // Create buffered image for plasma effect - pg = createGraphics(160, 90, P2D); - colorMode(HSB); - noSmooth(); -} - -void draw() -{ - float xc = 25; - - // Enable this to control the speed of animation regardless of CPU power - // int timeDisplacement = millis()/30; - - // This runs plasma as fast as your computer can handle - int timeDisplacement = frameCount; - - // No need to do this math for every pixel - float calculation1 = sin( radians(timeDisplacement * 0.61655617)); - float calculation2 = sin( radians(timeDisplacement * -3.6352262)); - - // Output into a buffered image for reuse - pg.beginDraw(); - pg.loadPixels(); - - // Plasma algorithm - for (int x = 0; x < pg.width; x++, xc += pixelSize) - { - float yc = 25; - float s1 = 128 + 128 * sin(radians(xc) * calculation1 ); - - for (int y = 0; y < pg.height; y++, yc += pixelSize) - { - float s2 = 128 + 128 * sin(radians(yc) * calculation2 ); - float s3 = 128 + 128 * sin(radians((xc + yc + timeDisplacement * 5) / 2)); - float s = (s1+ s2 + s3) / 3; - pg.pixels[x+y*pg.width] = color(s, 255 - s / 2.0, 255); - } - } - pg.updatePixels(); - pg.endDraw(); - - // display the results - image(pg,0,0,width,height); - -} - diff --git a/java/examples/Topics/Effects/Tunnel/Tunnel.pde b/java/examples/Topics/Effects/Tunnel/Tunnel.pde deleted file mode 100644 index 5e98f3e47..000000000 --- a/java/examples/Topics/Effects/Tunnel/Tunnel.pde +++ /dev/null @@ -1,114 +0,0 @@ -/** - * Tunnel Demo Effect - * by luis2048. - * - * This effect shows a tunnel in which you fly while the tunnel - * rotates, seemingly in 3D. The animation of the tunnel actually - * isn't calculated on the fly while the animation runs, but is - * precalculated. These calculations are stored in two tables: - * one for the angle and one for the distance. For every frame, - * go through every pixel (x,y) and use the angle and distance - * tables to get which pixel of the texture it should draw at the - * current pixel. To look like its rotating and zooming, the values - * of the angle and distance tables are shifted. - */ - -int x, y, radius, l; -PGraphics tunnelEffect; -PImage textureImg; - -// build lookup table -int[][] distanceTable; -int[][] angleTable; -int[][] shadeTable; -int w, h; - -void setup() { - size(640, 360); - - // Load texture 512 x 512 - textureImg = loadImage("red_smoke.jpg"); - textureImg.loadPixels(); - - // Create buffer screen - tunnelEffect = createGraphics(320, 200, P2D); - w = tunnelEffect.width; - h = tunnelEffect.height; - - float ratio = 32.0; - int angle; - int depth; - int shade = 0; - - // Make the tables twice as big as the screen. - // The center of the buffers is now the position (w,h). - distanceTable= new int[2 * w][2 * h]; - angleTable= new int[2 * w][2 * h]; - - for (int x = 0; x < w*2; x++) - { - for (int y = 0; y < h*2; y++) - { - depth = int(ratio * textureImg.height - / sqrt(float((x - w) * (x - w) + (y - h) * (y - h)))) ; - angle = int(0.5 * textureImg.width * atan2(float(y - h), - float(x - w)) / PI) ; - - // The distance table contains for every pixel of the - // screen, the inverse of the distance to the center of - // the screen this pixel has. - distanceTable[x][y] = depth ; - - // The angle table contains the angle of every pixel of the screen, - // where the center of the screen represents the origin. - angleTable[x][y] = angle ; - } - } -} - - -void draw() { - - tunnelEffect.beginDraw(); - tunnelEffect.loadPixels(); - - float timeDisplacement = millis() / 1000.0; - - // Calculate the shift values out of the time value - int shiftX = int(textureImg.width * .2 * timeDisplacement+300); // speed of zoom - int shiftY = int(textureImg.height * .15 * timeDisplacement+300); //speed of spin - - // Calculate the look values out of the time value - // by using sine functions, it'll alternate between - // looking left/right and up/down - int shiftLookX = w / 2 + int(w / 4 * sin(timeDisplacement)); - int shiftLookY = h / 2 + int(h / 4 * sin(timeDisplacement * 1.5)); - - for (int y = 0; y < h; y++) { - for (int x = 0; x < w; x++) { - - // Make sure that x + shiftLookX never goes outside - // the dimensions of the table - int texture_x = constrain((distanceTable[x + shiftLookX][y + shiftLookY] - + shiftX) % textureImg.width ,0, textureImg.width); - - int texture_y = (angleTable[x + shiftLookX][y + shiftLookY] - + shiftY) % textureImg.height; - - tunnelEffect.pixels[x+y*w] = textureImg.pixels[texture_y - * textureImg.width + texture_x]; - - // Test lookuptables - // tunnelEffect.pixels[x+y*w] = color( 0,texture_x,texture_y); - } - } - - tunnelEffect.updatePixels(); - tunnelEffect.endDraw(); - - // Display the results - image(tunnelEffect, 0, 0, width, height); - -} - - diff --git a/java/examples/Topics/Effects/UnlimitedSprites/UnlimitedSprites.pde b/java/examples/Topics/Effects/UnlimitedSprites/UnlimitedSprites.pde deleted file mode 100644 index 6395eeaa1..000000000 --- a/java/examples/Topics/Effects/UnlimitedSprites/UnlimitedSprites.pde +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Unlimited Sprites Demo Effect - * by luis2048. - * - * An infinate number of sprites drawn to screen. It's basically - * a flick-book effect; you draw the same sprite in different - * positions on different bufffer 'screens' and flip between them. - * When you've drawn on all frames, you loop back to the beginning - * and repeat. - */ - -PGraphics[] spriteFrames = new PGraphics[6]; -PImage sprite; - -float x, y; -float xang = 0.0; -float yang = 0.0; -int surf = 0; - -void setup() { - size(640, 360); - noSmooth(); - background(0); - - // Create sprite - sprite=loadImage("Aqua-Ball-48x48.png"); - - // Create blank surfaces to draw on - for (int i = 0; i < spriteFrames.length; i++) { - spriteFrames[i] = createGraphics(width, height, JAVA2D); - } -} - -void draw() -{ - background(0); - - // Get X, Y positions - x = (width/2)*sin((radians(xang))*0.95); - y = (height/2)*cos((radians(yang))*0.97); - - // Inc the angle of the sine - xang += 1.17; - yang += 1.39; - - // Blit our 'bob' on the 'active' surface - spriteFrames[surf].beginDraw(); - spriteFrames[surf].image(sprite, x+(width/2)-32, y+(height/2)-32); - spriteFrames[surf].endDraw(); - - // Blit the active surface to the screen - image(spriteFrames[surf], 0, 0, width, height); - - // Inc the active surface number - surf = (surf+1) % spriteFrames.length; - - // Display the results - //image(spriteEffect, 0, 0, width, height); -} - diff --git a/java/examples/Topics/Effects/Wormhole/Wormhole.pde b/java/examples/Topics/Effects/Wormhole/Wormhole.pde deleted file mode 100644 index 9f2f8fed8..000000000 --- a/java/examples/Topics/Effects/Wormhole/Wormhole.pde +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Wormhole Demo Effect - * by luis2048. - * - * A funnel-shaped hole sucking its texture to the middle. - * The effect is accomplished like the tunnel effect but with - * a 15 x 15 texture and static lookup table. The texture is shifted - * and mapped to the static lookup table. - */ - -PImage wormImg, wormTexture; -int[] reg = new int[15]; - -void setup() { - size(640, 360, P2D); - noSmooth(); - - // Reference image used to transpose texture - wormImg = loadImage("wormhole.png"); - wormImg.resize(width, height); - wormImg.loadPixels(); - - // Texture image array - wormTexture = loadImage("texture.gif"); - wormTexture.loadPixels(); -} - -// Moves the bottom row of pixels to the top and shifting remaining pixels 1 over -void shiftup() { - for (int k = 0; k < 15; k++) { - reg[k] = wormTexture.pixels[k]; - } - - for (int k = 15; k < 225; k++) { - wormTexture.pixels[k-15] = wormTexture.pixels[k]; - } - for (int k = 0; k < 15; k++) { - wormTexture.pixels[k+210] = reg[k]; - } -} - -// Moves left column of pixels to the right and shifting remaining pixels 1 over -void shiftright() { - for(int k = 0; k < 15; k++) { - reg[k] = wormTexture.pixels[15*k+14]; - for(int i = 14;i > 0; i--) { - wormTexture.pixels[15*k+i] = wormTexture.pixels[15*k+(i-1)]; - } - wormTexture.pixels[15*k] = reg[k]; - } -} - -void draw() { - // Load pixel data array - loadPixels(); - - // Loop through all pixels - for (int i = 0; i < pixels.length; i++){ - // Map texture to wormhole in a bit shift blue - pixels[i] = wormTexture.pixels[constrain(wormImg.pixels[i] & 0xFF, 0, 224)]; - } - - updatePixels(); - - shiftright(); - shiftup(); -} - - - diff --git a/java/examples/Topics/Effects/Wormhole/data/texture.gif b/java/examples/Topics/Effects/Wormhole/data/texture.gif deleted file mode 100644 index 37b7eb03339f3cc52a386651dfc258b802982a30..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 95 zcmZ?wbhEHbSKCbtX%c9?7{I__4FEwN9C-i$ diff --git a/java/examples/Topics/Fractals and L-Systems/Mandelbrot/Mandelbrot.pde b/java/examples/Topics/Fractals and L-Systems/Mandelbrot/Mandelbrot.pde index 2f31de8fb..7eafbf2e2 100644 --- a/java/examples/Topics/Fractals and L-Systems/Mandelbrot/Mandelbrot.pde +++ b/java/examples/Topics/Fractals and L-Systems/Mandelbrot/Mandelbrot.pde @@ -4,7 +4,7 @@ * * Simple rendering of the Mandelbrot set. */ - + // Establish a range of values on the complex plane // A different range will allow us to "zoom" in or out on the fractal // float xmin = -1.5; float ymin = -.1; float wh = 0.15; @@ -12,64 +12,62 @@ float xmin = -2.5; float ymin = -2; float wh = 4; -void setup() { - size(200, 200, P2D); - noLoop(); - background(255); - // Make sure we can write to the pixels[] array. - // Only need to do this once since we don't do any other drawing. - loadPixels(); -} +size(640, 360); +noLoop(); +background(255); -void draw() { - // Maximum number of iterations for each point on the complex plane - int maxiterations = 200; +// Make sure we can write to the pixels[] array. +// Only need to do this once since we don't do any other drawing. +loadPixels(); - // x goes from xmin to xmax - float xmax = xmin + wh; - // y goes from ymin to ymax - float ymax = ymin + wh; - - // Calculate amount we increment x,y for each pixel - float dx = (xmax - xmin) / (width); - float dy = (ymax - ymin) / (height); +// Maximum number of iterations for each point on the complex plane +int maxiterations = 100; - // Start y - float y = ymin; - for (int j = 0; j < height; j++) { - // Start x - float x = xmin; - for (int i = 0; i < width; i++) { - - // Now we test, as we iterate z = z^2 + cm does z tend towards infinity? - float a = x; - float b = y; - int n = 0; - while (n < maxiterations) { - float aa = a * a; - float bb = b * b; - float twoab = 2.0 * a * b; - a = aa - bb + x; - b = twoab + y; - // Infinty in our finite world is simple, let's just consider it 16 - if(aa + bb > 16.0) { - break; // Bail - } - n++; +// x goes from xmin to xmax +float xmax = xmin + wh; +// y goes from ymin to ymax +float ymax = ymin + wh; + +// Calculate amount we increment x,y for each pixel +float dx = (xmax - xmin) / (width); +float dy = (ymax - ymin) / (height); + +// Start y +float y = ymin; +for (int j = 0; j < height; j++) { + // Start x + float x = xmin; + for (int i = 0; i < width; i++) { + + // Now we test, as we iterate z = z^2 + cm does z tend towards infinity? + float a = x; + float b = y; + int n = 0; + while (n < maxiterations) { + float aa = a * a; + float bb = b * b; + float twoab = 2.0 * a * b; + a = aa - bb + x; + b = twoab + y; + // Infinty in our finite world is simple, let's just consider it 16 + if (aa + bb > 16.0) { + break; // Bail } - - // We color each pixel based on how long it takes to get to infinity - // If we never got there, let's pick the color black - if (n == maxiterations) { - pixels[i+j*width] = 0; - } else { - // Gosh, we could make fancy colors here if we wanted - pixels[i+j*width] = color(n*16 % 255); - } - x += dx; + n++; } - y += dy; - } - updatePixels(); -} + + // We color each pixel based on how long it takes to get to infinity + // If we never got there, let's pick the color black + if (n == maxiterations) { + pixels[i+j*width] = 0; + } + else { + // Gosh, we could make fancy colors here if we wanted + pixels[i+j*width] = color(n*16 % 255); + } + x += dx; + } + y += dy; +} +updatePixels();