processing pvector

Solutions on MaxInterview for processing pvector by the best coders in the world

showing results for - "processing pvector"
Rebeca
01 Jun 2020
1PVector v1, v2;
2
3void setup() {
4  noLoop();
5  v1 = new PVector(40, 20);
6  v2 = new PVector(25, 50); 
7}
8
9void draw() {
10  ellipse(v1.x, v1.y, 12, 12);
11  ellipse(v2.x, v2.y, 12, 12);
12  v2.add(v1);
13  ellipse(v2.x, v2.y, 24, 24);
14}
Carolina
29 Sep 2020
1
2// Instead of a bunch of floats, we now just have two PVector variables.
3PVector location;
4PVector velocity;
5
6void setup() {
7  size(200,200);
8  smooth();
9  background(255);
10  location = new PVector(100,100);
11  velocity = new PVector(2.5,5);
12}
13
14void draw() {
15  noStroke();
16  fill(255,10);
17  rect(0,0,width,height);
18  
19  // Add the current speed to the location.
20  location.add(velocity);
21
22  // We still sometimes need to refer to the individual components of a PVector 
23  // and can do so using the dot syntax (location.x, velocity.y, etc.)
24  if ((location.x > width) || (location.x < 0)) {
25    velocity.x = velocity.x * -1;
26  }
27  if ((location.y > height) || (location.y < 0)) {
28    velocity.y = velocity.y * -1;
29  }
30
31  // Display circle at x location
32  stroke(0);
33  fill(175);
34  ellipse(location.x,location.y,16,16);
35}
36