[solved] how to use alpha to animate moving points with fading tails in 3D space?
in
Programming Questions
•
7 months ago
I'm studying Creative Coding's script to animate moving points:
http://www.creativecoding.org/example/processing:objektorientiertes-animieren-03-wandern-farbig
May I ask how to get this effect in 3D space in which you can tumble the view to see the pts with fading tails? It seems the "fill+rect" approach may not work in 3D space ...
Thanks!
source code been tweaked a little bit:
http://www.creativecoding.org/example/processing:objektorientiertes-animieren-03-wandern-farbig
May I ask how to get this effect in 3D space in which you can tumble the view to see the pts with fading tails? It seems the "fill+rect" approach may not work in 3D space ...
Thanks!
source code been tweaked a little bit:
- Gizmo giz[] = new Gizmo[100];
- void setup () {
- size (800, 300);
- colorMode (HSB, 255);
- //background (76);
- for (int i=0; i < giz.length; i++) {
- float x = random (width);
- float y = random (height);
- giz[i] = new Gizmo (x, y);
- }
- }
- void draw () {
- noStroke ();
- fill (0,10); // smaller alpha value gives longer tail
- rect (0, 0, width, height);
- for (int i=0; i < giz.length; i++) {
- giz[i].move ();
- stroke (giz[i].getHue(), 255, 255);
- giz[i].render();
- }
- }
- class Gizmo {
- PVector position;
- PVector direction;
- float spin = 0.2; // degree of direction changing
- Gizmo (float theX, float theY) {
- position = new PVector (theX, theY);
- direction = new PVector ();
- direction.x = random (-1, 1);
- direction.y = random (-1, 1);
- }
- void move () {
- direction.x += random (-spin, spin);
- direction.y += random (-spin, spin);
- direction.normalize ();
- position.add (direction);
- if (position.x < 0 || position.x > width) {
- direction.x *= -1;
- }
- if (position.y < 0 || position.y > height) {
- direction.y *= -1;
- }
- }
- void render (){
- strokeWeight(5);
- point (position.x, position.y);
- }
- int getHue () {
- PVector v = new PVector (0, 1);
- float a = PVector.angleBetween (v, direction);
- a /= TWO_PI;
- return int (255 * a);
- }
- }
1