Created
December 7, 2016 13:24
-
-
Save nicetrysean/07969d6cc9ffd92379591161c7d756c0 to your computer and use it in GitHub Desktop.
First Processing Sketch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| color[] indexedColors = { | |
| color(180,205,60), | |
| color(223,175,74), | |
| color(240,82,42), | |
| color(241,235,216), | |
| color(0,140,114), | |
| color(0,105,168), | |
| color(125,123,125), | |
| color(163,157,171), | |
| color(230,200,187), | |
| color(213,78,135) | |
| }; | |
| Particle[] particles; | |
| void setup() | |
| { | |
| colorMode(RGB, 1); | |
| size(500, 500, P3D); | |
| frameRate(24); | |
| particles = new Particle[250]; | |
| for (int i = 0; i < 250; i++) { | |
| float x = random(width); | |
| float y = random(height); | |
| float z = random(width / height); | |
| float adj = map(y, 0, height, 255, 0); | |
| int c = color(40, adj, 255); | |
| particles[i]= new Particle(x - width / 2, y - height / 2, z, c); | |
| } | |
| } | |
| void draw() | |
| { | |
| int frames = 24 * 3; | |
| float t = (float)frameCount / frames; | |
| background(0); | |
| perspective(0.5, 1, 0.01, 100); | |
| camera( | |
| 0, 0, 25 + sin(PI * 2 * t) * 3, | |
| 0, 0, 0, | |
| 0, 1, 0 | |
| ); | |
| rotateX(-0.5 - 0.05 * sin(PI * 4 * t)); | |
| rotateY(-0.5 - 0.05 * cos(PI * 2 * t)); | |
| pushMatrix(); | |
| for (Particle p : particles) { | |
| p.update(); | |
| p.render(t); | |
| } | |
| popMatrix(); | |
| camera(); | |
| } | |
| //========================================================= | |
| class Particle { | |
| PVector pos, vel, acc; | |
| color c; | |
| Particle(float xIn, float yIn, float zIn, color cIn) { | |
| pos = new PVector(xIn, yIn, zIn); | |
| vel = new PVector(0, 0, 0); | |
| acc = new PVector(0, 0, 0); | |
| c = cIn; | |
| } | |
| /*-------*/ | |
| void interact(float r0, float x, float y) { // interact points with attractors | |
| float sign = r0/abs(r0); | |
| r0 = abs(r0); | |
| float r = dist(pos.x, pos.y, x, y); | |
| float angle = atan2(pos.y-y, pos.x-x); | |
| if (r <= r0) { | |
| float radius = 0.5*sign*(r0-r)/r0; | |
| vel.set(radius*cos(angle), radius*sin(angle)); | |
| } else { | |
| vel.set(0, 0); | |
| } | |
| pos.add(vel); | |
| } | |
| /*-------*/ | |
| void update() { // move attractors | |
| //change direction sometimes | |
| float angle = random(-PI, PI); | |
| acc.set(cos(angle), sin(angle), sin(angle) * cos(angle)); | |
| float mod = PVector.angleBetween(acc, vel); | |
| mod = map(mod, 0, PI, 0.1, 0.001); | |
| acc.mult(mod); | |
| vel.add(acc); | |
| } | |
| void render(float t) | |
| { | |
| pos.add(vel.x * cos( vel.x + t * 10) * exp(t / 10) * cos(t / 10) * sin(exp(t / 10)), -vel.y * cos(vel.y + t * 10) + (vel.y) * exp(t / 10) * cos(t / 10) * cos(exp(t / 10)), vel.z * (t / 10)); | |
| translate((pos.x / width) - sin(t / 10) * 0.01, pos.y / height, -(pos.z * sin(t / 10)) / height); | |
| fill(lerpColor(indexedColors[floor(4)], indexedColors[2], pos.x / 100)); | |
| ellipse(sin(t * 10) * cos(t * 10), cos(t * 10) * sin(t * 10), t / 10, t / 10); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment