Hello,
I have written the script about shapes that are constantly updating in z axis.
The last thing I do not know, how to make a shape between current frame vertexes and previous frame vertexes.
I know,that I have to access prievious xpos[i] and y[pos[i], and draw shape with current one but I cannot find the right solution. Problematic area is marked in red color.
Could your help me? Please:)
-
- import processing.opengl.*;
- import peasy.*;
- PeasyCam cam;
- Mover[] movers = new Mover[5];
- void setup() {
- size(800, 800, OPENGL);
- cam = new PeasyCam(this, 300, 300, 0, 1000);
- cam.setMinimumDistance(1);
- cam.setMaximumDistance(100000);
- noStroke();
- fill(160);
- for (int i = 0; i < movers.length; i++) {
- movers[i] = new Mover();
- }
- }
- void draw() {
- background(0);
- ambientLight(95, 95, 95);
- directionalLight(51, 102, 126, 0, 0, -1);
- directionalLight(60, 60, 60, 1, 60, 0);
- directionalLight(20, 20, 20, 0, -5, 0);
- lightSpecular(0, 50, 0);
- lightFalloff(1, 0, 0);
- for (int i = 0; i < movers.length; i++) {
- movers[i].update();
- movers[i].display();
- }
- }
- int[] xpos = new int[100];
- int[] ypos = new int[100];
- class Mover {
- PVector location;
- PVector velocity;
- PVector acceleration;
- float topspeed;
- float a;
- Mover() {
- location = new PVector(random(width)*2, random(height)*2);
- velocity = new PVector(0, 0);
- topspeed = 5;
- }
- void update() {
- }
- void display() {
- PVector mouse = new PVector(random(mouseX)*10, random(mouseY)*10);
- PVector acceleration = PVector.sub(mouse, location);
- acceleration.normalize();
- acceleration.mult(0.2);
- velocity.add(acceleration);
- velocity.limit(topspeed);
- location.add(velocity);
- float x1 = int(location.x);
- float y1 = int(location.y);
- for (int i=0; i<xpos.length-1; i++) {
- xpos[i] = xpos[i+1];
- ypos[i] = ypos[i+1];
- }
- xpos[xpos.length-1] = int(location.x);
- ypos[ypos.length-1] = int(location.y);
- for (int i=0; i<xpos.length; i++) {
- stroke(255);
- strokeWeight(1);
- fill(1055-i*0.5, 455-i*0.5, 1055-i*0.5, 255);
- float c1 = 1;
- float c2 = 1;
- line(location.x, location.y, 0, location.x, location.y, i);
- beginShape();
- PVector updateVector = new PVector(xpos[i], ypos[i]);
- mouse.add(updateVector);
- vertex(xpos[i]+c1, ypos[i]+c2, i*10);
- vertex(xpos[i]+c1+48, ypos[i]+c2, i*10);
- vertex(xpos[i]+c1+48, ypos[i]+c2+48, i*10);
- vertex(xpos[i]+c1, ypos[i]+c2+48, i*10);
- // println(xpos[i]);
- endShape(CLOSE);
- beginShape();
- vertex(xpos[i]+c1, ypos[i]+c2, i*10);
- vertex(xpos[i]+c1+48, ypos[i]+c2, i*10);
- //Here I get an error
- //vertex(xpos[i+1]+c1, ypos[i+1]+c2, i*10);
- // vertex(xpos[i+1]+c1+48, ypos[i+1]+c2, i*10);
- endShape(CLOSE);
- }
- }
- }
1