// Atomic particle a-la Bohr // (not very scientific) // Now with a faux electronic microscope! // Author: Ivan Safrin // Press any key to see the 3d model without the filter // Click to regenerate. Atom atom; boolean debug; void setup() { size(150, 150, P3D); debug = false; atom = new Atom(int(random(5,20)), 15, 255); } void draw() { if(keyPressed) { debug = true; } else { debug = false; } background(116, 105, 90); noStroke(); translate(width/2, height/2); scale(20); atom.draw(); if(!debug) { filter(GRAY); Noise(); filter(BLUR, 3); } } void mouseReleased() { atom = new Atom(int(random(5,20)), 15, 255); } void Noise() { loadPixels(); for(int i=0; i < (width*height)/7;i++) { pixels[int(random(width*height))] = color(255,255,255); } updatePixels(); } class Atom { int numorbits; Vector orbits; Atom(int pnumorbits, float res, int colorres) { numorbits = pnumorbits; orbits = new Vector(); for(int i=0; i < numorbits; i++) { Orbiter orb = new Orbiter(res, colorres, 0, int(random(255)), int(random(255)), int(random(255))); orbits.add(orb); } } void draw() { fill(0, 0, 0,100); sphereDetail(8); sphere(1); for (Enumeration e = orbits.elements(); e.hasMoreElements();) { Orbiter orb = (Orbiter)e.nextElement(); orb.draw(); } } } class Orbiter { float strip_res; int grad_res; int degree; int wobble; int alignment; int xalignment; int speed; int r; int g; int b; Orbiter(float stripres, int gradres, int pwobble, int pr, int pg, int pb) { wobble = pwobble; strip_res = stripres; grad_res = gradres; degree = int(random(359)); alignment = int(random(60)); xalignment = int(random(60)); speed = int(random(15)); if(speed == 0) speed = 1; r = pr; g = pg; b = pb; } void draw() { rotateZ(radians(alignment)); rotateX(radians(xalignment)); pushMatrix(); degree = degree + speed; if(degree >= 360) degree = 0; rotateX(radians(degree)); rotateY(radians(wobble)); beginShape(QUAD_STRIP); fill(0, 0, 0,255); float f = 0.0; int i = 0; while(f < TWO_PI) { i++; fill(r, g, b,255-((grad_res/strip_res)*i)); vertex(-0.5, 0.5 + sin(f)*2, 0.5 + cos(f)*2); vertex(0 , 0.5 + sin(f)*2, 0.5 + cos(f)*2); f += PI/strip_res; } endShape(); popMatrix(); } }