Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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.


Auto Save

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" style="border: 1px solid gray;"></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);

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 context = document.querySelector('canvas').getContext('2d');

// Translate the origin to the center of the canvas
context.translate(context.canvas.width / 2, context.canvas.height / 2);

let angleInRadians = 0;

setInterval(() => {
  // Clear the screen each frame. Since we moved the origin to 0, 0 and our canvas is 300px
  // in width and height, we actually need to clear from -150, -150.
    -context.canvas.width / 2, 
    -context.canvas.height / 2, 

  const xInUnitCircle = Math.cos(angleInRadians);
  const yInUnitCircle = Math.sin(angleInRadians);
  angleInRadians += 0.1;
  const distanceFromOrigin = 10; // draw 10 pixels out from the unit circle
  const newX = xInUnitCircle * distanceFromOrigin;
  const newY = yInUnitCircle * distanceFromOrigin;
  context.fillRect(newX, newY, 20, 20);
}, 30);