Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <canvas width="300" height="300"></canvas>




                class Vector2 {
	constructor(x, y) {
  	this.x = x;
    this.y = y;
  plus(otherVector) {
    return new Vector2(this.x + otherVector.x, this.y + otherVector.y);
  timesScalar(scalar) {
    return new Vector2(this.x * scalar, this.y * scalar);
  componentsTimesVector(otherVector) {
    return new Vector2(this.x * otherVector.x, this.y * otherVector.y);
  magnitude() {
    return Math.sqrt(this.x ** 2 + this.y ** 2);

// Our translate, or "move" vector, that we will add to each vector of our square.
const translateVector = new Vector2(100, 200);

// Our scale vector which should triple the width of the square and double its height
const scaleVector = new Vector2(2, 3);

// Log the translate vector's magnitude

const upperLeftCorner = new Vector2(0, 0);
const upperRightCorner = new Vector2(40, 0);
const lowerRightCorner = new Vector2(40, 40);
const lowerLeftCorner = new Vector2(0, 40);

const transatedUpperLeftCorner =;
const translatedUpperRightCorner =;
const translatedLowerRightCorner =;
const translatedLowerLeftCorner =;

const scaledUpperLeftCorner = transatedUpperLeftCorner.componentsTimesVector(scaleVector);
const scaledUpperRightCorner = translatedUpperRightCorner.componentsTimesVector(scaleVector);
const scaledLowerRightCorner = translatedLowerRightCorner.componentsTimesVector(scaleVector);
const scaledLowerLeftCorner = translatedLowerLeftCorner.componentsTimesVector(scaleVector);

const context = document.querySelector('canvas').getContext('2d');
context.moveTo(scaledUpperLeftCorner.x, scaledUpperLeftCorner.y);
context.lineTo(scaledUpperRightCorner.x, scaledUpperRightCorner.y);
context.lineTo(scaledLowerRightCorner.x, scaledLowerRightCorner.y);
context.lineTo(scaledLowerLeftCorner.x, scaledLowerLeftCorner.y);