0.2.7
0.2.7
This release has some new features in Vector and 2d noise, as well as some fixes.
Vector
Vector is a new class for working with 2d and 3d vectors. The full documentation is here, but here are some quick examples to get the idea:
This example normalizes a vector so that its magnitude is equal to the radius of the circle.

let origin = new Vector(getWidth() / 2, getHeight() / 2);
let mouseVector = new Vector(mouseX, mouseY).subtract(origin);
let normal = mouseVector.clone().normalize().multiply(radius);https://codehs.github.io/chs-js-lib/examples/datastructures/vector/normalize/
This example adds two vectors to produce a third:

let origin = new Vector(0, 0);
let v1 = new Vector(mouseX, mouseY);
let v2 = new Vector(-30, 20);
draw(origin, v1, 'red');
let v3 = v1.copy().add(v2);
draw(origin, v3, 'purple');
draw(v1, v2, 'blue');https://codehs.github.io/chs-js-lib/examples/datastructures/vector/add/
These examples can be found at https://codehs.github.io/chs-js-lib/examples/.
2d Noise
Randomizer.noise will now return 2 dimensional Perlin noise if it receives a second argument.

setBackgroundColor('white');
for (let row = 0; row < getHeight(); row++) {
for (let col = 0; col < getWidth(); col++) {
const scaledRow = row * 0.02;
const scaledCol = col * 0.02;
const pxl = new Rectangle(1, 1);
pxl.setPosition(col, row);
const n = Randomizer.noise(scaledCol, scaledRow);
pxl.setColor(Color.createFromRGB(n * 255, n * 255, n * 255));
add(pxl);
}
}https://codehs.github.io/chs-js-lib/examples/randomizer/2dnoise/
Fixes
- Rotation calculations are only performed if an element has non-zero rotation, which is a performance gain in some cases.
- Lines rotated in Groups have been fixed by making sure that the width and height of a line are distance, rather than potentially negative vectors.
Full Changelog: 0.2.6...0.2.7