import processing.opengl.*; /** * DiagDots * by Evan Raskob 2008. * * */ static final float MAX_FLOAT = +3.4028235E38; float boxXSpacing= 8, boxYSpacing = 14; // How far apart should each box be spaced float boxMaxHeight = 40; // how many pixels max for box height float boxMaxWidth = 16; // how many pixels max for box height int numBoxRows, numBoxCols; int interval; AnimBox[][] aboxes; int YPixelsPerFrame = 2; int currentYPixelsCount = 0; float dy = 0.05f; float yoff = 0.0f; // 2nd dimension of perlin noise float aspect, distance, fov; float maxXScale; int[] bgcolor; int[] boxFill; void setup() { //size(640, 480, P3D); size(1024, 512, JAVA2D); smooth(); frameRate(20); aspect = float(width) / float(height); fov = 0.25; distance = 100.0; colorMode(RGB,255,255,255,255); fill(0, 0, 0, 255); ellipseMode(CORNER); bgcolor = new int[3]; bgcolor[0] = 0; bgcolor[1] = 0; bgcolor[2] = 0; boxFill = new int[4]; boxFill[0] = int(random(255)); boxFill[1] = int(random(255)); boxFill[2] = int(random(255)); boxFill[3] = 255; interval = 30; float ypos = 0.0f; float xpos = 0.0f; float newXScale, newYScale; numBoxCols = round( ((float)width - 1 - boxXSpacing) / (boxMaxWidth + boxXSpacing) ); numBoxRows = round( ((float)height - 1 - boxYSpacing) / (boxMaxHeight + boxYSpacing) ); // maxXScale = float(width)*2.0f; aboxes = new AnimBox[numBoxCols][numBoxRows]; println("boxes: " + numBoxCols + " / " + numBoxRows); float noiz; for (int i=0; i < numBoxCols; i++) { for (int j=0; j < numBoxRows; j++) { aboxes[i][j] = new AnimBox(1.0, 0, 0, 0); } } recalcScales(); } void draw() { if (frameCount == 1) { background(0); fill(255); for (int i=0; i < numBoxCols; i++) for (int j=0; j < numBoxRows; j++) aboxes[i][j].draw(); } if(keyPressed) { println("key: " + key); switch(key) { case 'r': recalcScales(); break; case 'f': setFullScreen(true); break; case ']': interval += 2; break; case '[': if (interval > 10) interval -= 2; break; case 's': String saveString = "dotpattern_" + year() + month() + day() + "_" + hour() + "-" + minute() + "-" + second(); save(saveString+".tga"); PImage img = loadImage(saveString+".tga"); img.mask(img); println("Save path: " + savePath(saveString+".tif")); img.save(savePath(saveString)+".tga"); break; default: background(0); fill(255); for (int i=0; i < numBoxCols; i++) for (int j=0; j < numBoxRows; j++) aboxes[i][j].draw(); break; } } } void recalcScales() { float xpos, ypos; float newXScale, newYScale; float perDoneX = 0f; float perDoneY = 0f; for (int i=0; i < numBoxCols; i++) { perDoneX = float(i) / float (numBoxCols); xpos = i*(boxMaxWidth + boxXSpacing)+ boxXSpacing -1; for (int j=0; j < numBoxRows; j += 2) { perDoneY = float(j) / float (numBoxRows); ypos = j* (boxYSpacing + boxMaxHeight) + boxYSpacing -1; newYScale = (( pow(((0.5 - perDoneY)* 2f),2) + 1f)*0.4 + 0.2 ) * (1f - 2f*abs(perDoneX-0.5)) * boxMaxHeight; newXScale = (( pow(((0.5 - perDoneY)* 2f),2) + 1f)*0.4 + 0.2 ) * (1f - 2f*abs(perDoneX-0.5)) * boxMaxWidth; aboxes[i][j].setScale(newXScale, newYScale, 1.0); aboxes[i][j].setXY(xpos, ypos); } for (int j=1; j < numBoxRows; j += 2) { perDoneY = float(j) / float (numBoxRows); ypos = j* (boxYSpacing + boxMaxHeight) + boxYSpacing; newYScale = ( ( pow(((perDoneY- 0.5)* 2f),2) + 1f)*0.4 + 0.2 ) * 2f*abs(0.5-perDoneX) * boxMaxHeight; newXScale = ( ( pow(((perDoneY- 0.5)* 2f),2) + 1f)*0.4 + 0.2 ) * 2f*abs(perDoneX-0.5) * boxMaxWidth; aboxes[i][j].setScale(newXScale, newYScale, 1.0); aboxes[i][j].setXY(xpos, ypos); } } } class AnimBox { float _scaleX, _scaleY, _scaleZ, _x, _y, _z; int _animTime, _currentTime; float _newScaleX, _newScaleY, _newScaleZ; //float _tempScaleX, _tempScaleY, _tempScaleZ; // declared here for garbage collection optimization float _percentFinished; boolean _animateFlag; AnimBox(float __scaleX, float __scaleY, float __scaleZ, float __x, float __y, float __z) { this._scaleX = __scaleX ; this._scaleY = __scaleY ; this._scaleZ = __scaleZ ; this._x = __x; this._y = __y; this._z = __z; this._currentTime = 0; this._percentFinished = 1.0; this._animateFlag = false; } AnimBox(float __scale, float __x, float __y, float __z) { this._scaleX = __scale ; this._scaleY = __scale ; this._scaleZ = __scale ; this._x = __x; this._y = __y; this._z = __z; this._currentTime = 0; this._animateFlag = false; } void draw() { if (_animateFlag) { _currentTime++; _percentFinished = float(_currentTime) / float(_animTime); _scaleX = (1.0-_percentFinished)*_scaleX + _percentFinished*_newScaleX; _scaleY = (1.0-_percentFinished)*_scaleY + _percentFinished*_newScaleY; _scaleZ = (1.0-_percentFinished)*_scaleZ + _percentFinished*_newScaleZ; if (_currentTime >= (_animTime*0.33)) _animateFlag = false; } ellipse(_x, _y, _scaleX, _scaleY); //rect(_x, _y, _scaleX, _scaleY); } void setNewScale(float ascaleX, float ascaleY, float ascaleZ) { this._newScaleX = ascaleX; this._newScaleY = ascaleY; this._newScaleZ = ascaleZ; } void setScale(float ascaleX, float ascaleY, float ascaleZ) { this.stopAnimating(); this._scaleX = ascaleX; this._scaleY = ascaleY; this._scaleZ = ascaleZ; } void setXYZ(float aX, float aY, float aZ) { this._x = aX; this._y = aY; this._z = aZ; } void setXY(float aX, float aY) { this._x = aX; this._y = aY; } void setAnimTime(int at) { this._animTime = at*3; this._currentTime = 0; } void startAnimating() { this._animateFlag = true; } void stopAnimating() { this._animateFlag = false; } boolean doneAnimating() { return !this._animateFlag; } }