filter(BLUR) changes in Processing 2.0 / restoring old Processing sketch
in
Core Library Questions
•
3 months ago
Did filter(BLUR) change in Processing 2.0?
I was looking at one of my favorite sketches by Algirdas Rascius (
http://www.openprocessing.org/sketch/2256) in Processing v2.0, and noticed that it looks very different from how it did in Processing 1.5.1 and earlier.
I made a few changes to the syntax and function calls to match what's available in Processing v2.0, but the sketch still looks different -- and it seems like it's the blur that doesn't seem to work well in the PGraphics buffer.
Did the functionality of filter(BLUR) somehow change in Processing 2.0, or is there something else in this sketch that's not the same in Processing 2.0?
The code (kaleidoscope.pde), updated for Processing v2.0 as best as I can, is below (though to run it you'll need to get ColorPalettes.pde and ShapeGenerator.pde from the openprocessing site).
The code (kaleidoscope.pde), updated for Processing v2.0 as best as I can, is below (though to run it you'll need to get ColorPalettes.pde and ShapeGenerator.pde from the openprocessing site).
- /*
- * Kaleidoscope by Algirdas Rascius (http://mydigiverse.com).
- */
- /**
- * Mouse-click to change pattern and color.
- */
- import java.util.Iterator;
- static final int SCREEN_SIZE = 200;
- static final int SIDE = 150;
- static final float MAX_TILE_ROTATION_DELTA = 0.02;
- static final float MAX_ROTATION_DELTA = 0.008;
- static final int AUTO_INITIALIZE_COUNT = 3000;
- PGraphics tile;
- ArrayList shapes;
- Palette palette;
- ShapeGenerator shapeGenerator;
- float tileRotation;
- float rotation;
- float tileRotationDelta;
- float rotationDelta;
- int nextAutoInitialize;
- void setup() {
- size(1280, 800, P3D);
- smooth();
- colorMode(HSB, TWO_PI, 1, 1);
- noStroke();
- frameRate(30);
- textureMode(NORMAL);
- tile = createGraphics(SCREEN_SIZE, SCREEN_SIZE, P3D);
- tile.background(0);
- tile.smooth();
- shapes = new ArrayList();
- initialize();
- }
- void initialize() {
- shapes.clear();
- palette = getRandomPalette();
- shapeGenerator = getRandomShapeGenerator();
- tileRotationDelta = random(-MAX_TILE_ROTATION_DELTA, MAX_TILE_ROTATION_DELTA);
- rotationDelta = random(-MAX_ROTATION_DELTA, MAX_ROTATION_DELTA);
- nextAutoInitialize = AUTO_INITIALIZE_COUNT;
- }
- void mousePressed() {
- initialize();
- }
- void keyPressed() {
- initialize();
- }
- void draw() {
- drawTile();
- drawAllTiles();
- if (nextAutoInitialize-- < 0) {
- initialize();
- }
- }
- void drawTile() {
- tile.beginDraw();
- tile.background(0);
- tile.filter(BLUR);
- shapeGenerator.createShapes(shapes, tile, palette);
- for (Iterator i=shapes.iterator(); i.hasNext();) {
- Shape s = (Shape)i.next();
- if (!s.draw(tile)) {
- i.remove();
- }
- }
- tile.endDraw();
- }
- final static float SIN_30 = sin(TWO_PI/12);
- final static float COS_30 = cos(TWO_PI/12);
- void drawAllTiles() {
- tileRotation = (tileRotation + tileRotationDelta + TWO_PI) % TWO_PI;
- rotation = (rotation + rotationDelta + TWO_PI) % TWO_PI;
- float tx1 = 0.5+0.49*sin(tileRotation);
- float ty1 = 0.5+0.49*cos(tileRotation);
- float tx2 = 0.5+0.49*sin(tileRotation+TWO_PI/3);
- float ty2 = 0.5+0.49*cos(tileRotation+TWO_PI/3);
- float tx3 = 0.5+0.49*sin(tileRotation+TWO_PI/3*2);
- float ty3 = 0.5+0.49*cos(tileRotation+TWO_PI/3*2);
- translate(width/2, height/2);
- scale(SIDE, SIDE);
- rotate(rotation);
- for (int y=-2; y<=2; y++) {
- pushMatrix();
- translate(0, y*(1+SIN_30));
- for (int x=-2; x<=2; x++) {
- pushMatrix();
- translate(x*2*COS_30, 0);
- if (abs(y)%2==1) {
- translate(COS_30, 0);
- }
- for (int i=0; i<3; i++) {
- rotate(TWO_PI/3);
- for (int j=0; j<2; j++) {
- scale(-1,1);
- beginShape();
- texture(tile);
- vertex(0, 0, tx1, ty1);
- vertex(0, 1, tx2, ty2);
- vertex(COS_30, SIN_30, tx3, ty3);
- endShape();
- }
- }
- popMatrix();
- }
- popMatrix();
- }
- }
1