/** a digital caleidoscop by Guru */ import processing.opengl.*; import javax.media.opengl.*; PGraphics pg1; void setup() { size(400,400,OPENGL); pg1 = makeTexture( 15 ); frameRate(25); background(0); } color[] colors = new color[]{ color(255,255,255), color( 255, 0, 0 ), color( 255, 255, 0), color( 0, 255,0 ), color( 0, 255, 255 ), color( 0, 0, 255 ), color( 255, 0, 255) }; float alph = 0.0; void draw() { fill(0,15); noStroke(); rect( 0,0, width, height ); PGraphicsOpenGL pgl = (PGraphicsOpenGL) g; GL gl = pgl.gl; pgl.beginGL(); pushMatrix(); scale(2); gl.glDepthMask(false); gl.glDisable(GL.GL_DEPTH_TEST); gl.glEnable(GL.GL_BLEND); gl.glBlendFunc(GL.GL_SRC_ALPHA,GL.GL_ONE); alph += 0.1; for (int i = 0; i < 7; i++) { pushMatrix(); translate(width/2, height/2); rotate( i*2*PI/7 ); drawStar( pg1, sin(alph/3.7) * 150 * sin(alph), cos(alph/4.2) * 150 * cos( alph ), colors[i]); drawStar( pg1, sin(alph/2.5) * 150 * sin(alph), cos(alph/3.2) * 150 * cos( alph/2.1), colors[i]); drawStar( pg1, sin(alph/2.7) * 150 * sin(alph/2.1), cos(alph/3.4) * 150 * cos( alph/1.1 ), colors[i]); popMatrix(); } popMatrix(); pgl.endGL(); } void drawStar( PImage img, float x, float y, color t ) { beginShape(); tint( t, 200 ); texture( img ); vertex(x-img.width/2,y-img.width/2, 0, 0); vertex(x-img.width/2,y+img.width/2, 0, img.width); vertex(x+img.width/2,y+img.width/2, img.height, img.width); vertex(x+img.width/2,y-img.width/2, img.height, 0); endShape(); } PGraphics makeTexture( int r ) { PGraphics res = createGraphics( r * 6, r * 6, P2D); res.beginDraw(); res.loadPixels(); for ( int x = 0; x < res.width; x++) { for( int y = 0; y < res.height; y++ ) { float d = min( 512, 50* sq( r / sqrt( sq( x - 3 * r) + sq( y - 3 * r)))); res.pixels[y * res.width + x] = color( min(255,d), min(255, d*0.8), d* 0.5 ); } } res.updatePixels(); res.endDraw(); return res; }