# Vector

Vector by Daniel Shiffman.

Demonstration some basic vector math: subtraction, normalization, scaling Normalizing a vector sets its length to 1.

```
void setup() {
size(640,360);
}

void draw() {
background(0);

// A vector that points to the mouse location
PVector mouse = new PVector(mouseX,mouseY);
// A vector that points to the center of the window
PVector center = new PVector(width/2,height/2);
// Subtract center from mouse which results in a vector that points from center to mouse
mouse.sub(center);

// Normalize the vector
mouse.normalize();

// Multiply its length by 150 (Scaling its length)
mouse.mult(150);

translate(width/2,height/2);
// Draw the resulting vector
stroke(255);
strokeWeight(4);
line(0,0,mouse.x,mouse.y);

}
```

## Functions Used

stroke()

Sets the color used to draw lines and borders around shapes

size()

Defines the dimension of the display window width and height in units of pixels

setup()

The setup() function is run once, when the program starts

strokeWeight()

Sets the width of the stroke used for lines, points, and the border around shapes

translate()

Specifies an amount to displace objects within the display window

draw()

Called directly after setup(), the draw() function continuously executes the lines of code contained inside its block until the program is stopped or noLoop() is called

PVector

A class to describe a two or three dimensional vector, specifically a Euclidean (also known as geometric) vector