Line Trail
in
Programming Questions
•
2 years ago
I'm trying to do something like this effect (starting from 32 secs)
How can I make these trails for the lines on the planet? I made a simple test but the result is not even close to the one on the video. Do I have to write a shader to have this effect? My simple test is bellow. Thanks
- Linetrail[] horizontal;
- Linetrail[] vertical;
- void setup()
- {
- size(800, 600);
- int numberOfLines = 30;
- int numberOfColumns = 40;
- int offsetX = width / numberOfColumns;
- int offsetY = height / numberOfLines;
- vertical = new Linetrail[numberOfColumns];
- for (int i = 0; i < vertical.length; i++)
- {
- vertical[i] = new Linetrail(i * offsetX, 0, i * offsetX, height);
- }
- horizontal = new Linetrail[numberOfLines];
- for (int j = 0; j < horizontal.length; j++)
- {
- horizontal[j] = new Linetrail(0, j * offsetY, width, j * offsetY);
- }
- background(0);
- }
- void draw()
- {
- fill(0, 5);
- noStroke();
- rect(0, 0, width, height);
- for (int i = 0; i < vertical.length; i++) vertical[i].update();
- for (int j = 0; j < horizontal.length; j++) horizontal[j].update();
- for (int i = 0; i < vertical.length; i++) vertical[i].render();
- for (int j = 0; j < horizontal.length; j++) horizontal[j].render();
- }
- class Linetrail
- {
- private int startX, startY, endX, endY;
- private int trailX, trailY;
- private boolean vertical;
- private int trailVel = 5;
- private int trailSize = 25;
- private int trailWeight = 3;
- private color lineColor = #880000,
- trailColor = #FF0000;
- public Linetrail(int sx, int sy, int ex, int ey)
- {
- startX = sx;
- startY = sy;
- endX = ex;
- endY = ey;
- trailX = startX;
- trailY = startY;
- vertical = startX == endX ? true : false;
- }
- public void update()
- {
- if (vertical)
- {
- trailY += trailVel;
- if (trailY < startY || trailY + trailSize > endY) trailVel *= -1;
- }
- else
- {
- trailX += trailVel;
- if (trailX < startX || trailX + trailSize > endX) trailVel *= -1;
- }
- }
- public void render()
- {
- strokeWeight(trailWeight);
- stroke(lineColor);
- line(startX, startY, endX, endY);
- stroke(trailColor);
- if (vertical)
- {
- line(trailX, trailY, trailX, trailY + trailSize);
- }
- else
- {
- line(trailX, trailY, trailX + trailSize, trailY);
- }
- }
- }
1