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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource


Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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


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 id="main-canvas" width="512" height="200"></canvas>


                #main-canvas {
  width: 100%;
  background: #fff000;


                // 메인 캔버스
const canvas = document.getElementById('main-canvas');
const context = canvas.getContext('2d');

// off-screen 캔버스와 컨텍스트를 설정
// 눈에 보여줄 캔버스가 아니므로, 생성 후 body에 붙이지 않는다
canvas.offCanvas = document.createElement('canvas');
canvas.offContext = canvas.offCanvas.getContext('2d');
// 이미지 크기로 width, height 세팅
canvas.offCanvas.width = 88;
canvas.offCanvas.height = 88;

const imgElem = new Image();
const sunFaceArray = [];
let angle = 0;

class SunFace {
  constructor(x, y, speed) {
    this.x = x;
    this.y = y;
    this.speed = speed;
  draw() {
    if (this.x < -100) this.x = 512;
    // 이미지 엘리먼트 대신, off-screen 캔버스를 그린다
    context.drawImage(canvas.offCanvas, this.x, this.y);

function render() {
  context.clearRect(0, 0, canvas.width, canvas.height);
  let sunFace;
  for (let i = 0; i < sunFaceArray.length; i++) {
    sunFace = sunFaceArray[i];
    sunFace.x -= sunFace.speed;
    sunFace.y += Math.sin(angle++ * Math.PI/180) * sunFace.speed;

imgElem.src = '';
imgElem.addEventListener('load', () => {
  // off-screen 캔버스에 이미지를 그려둔다
  canvas.offContext.drawImage(imgElem, 0, 0);
  let x, y, speed;
  for (let i = 0; i < 10; i++) {
    x = Math.floor(Math.random() * canvas.width) * 0.8;
    y = Math.floor(Math.random() * canvas.height) * 0.7;
    speed = Math.floor(Math.random() * 4) + 1;
    sunFaceArray.push(new SunFace(x, y, speed));