Little little little problem - syntax
in
Contributed Library Questions
•
1 year ago
How to make my script work as I t to use location.x, location.y coordinates instead of mouseX, mouseY. The problematic area is in red bold color:) Thank you.
- import processing.opengl.*;
- import peasy.*;
- PeasyCam cam;
- Mover[] movers = new Mover[2];
- 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(255);
- 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();
- }
- }
- ArrayList coordinates = new ArrayList();
- class Mover {
- PVector location;
- PVector velocity;
- PVector acceleration;
- float topspeed;
- float a;
- Mover() {
- location = new PVector(random(width), random(height));
- velocity = new PVector(0, 0);
- topspeed = 5;
- }
- void update() {
- PVector mouse = new PVector(mouseX, mouseY);
- PVector acceleration = PVector.sub(mouse, location);
- acceleration.normalize();
- acceleration.mult(0.2);
- velocity.add(acceleration);
- velocity.limit(topspeed);
- location.add(velocity);
- a = a + 1;
- }
- void display() {
- stroke(100);
- strokeWeight(2);
- fill(127, 200);
- a = a + 1;
- coordinates.add(new Coordinate(mouseX, mouseY)); // this has to be changed to location.x, location.y
- // display circles at all the coordinates
- for (int i=0; i<coordinates.size(); i++) {
- Coordinate c = (Coordinate) coordinates.get(i);
- stroke(1, a);
- line(location.x, location.y, 0, location.x, location.y, a);
- beginShape();
- vertex(c.x, c.y, a);
- vertex(c.x+48, c.y, a);
- vertex(c.x+48, c.y+48, a);
- vertex(c.x, c.y+48, a);
- endShape(CLOSE);
- }
- // removes coordinates if there are more than 150, comment this out to keep all coordinates
- if (coordinates.size() > 150) {
- coordinates.remove(0);
- }
- }
- }
- class Coordinate {
- int x, y;
- Coordinate(int x, int y) {
- this.x = x;
- this.y = y;
- }
- }
1