Pen Settings

HTML

CSS

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

JavaScript

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

Packages

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.

Behavior

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.

HTML

              
                figure
  .figure-content
    canvas(is='my-painting')

              
            
!

CSS

              
                .figure-content
  background: #000
  overflow: hidden

// Page layout 📰

body
  height: 100vh
  background-color: #210
  // font-family: 'Roboto', sans-serif
  overflow: hidden
  display: flex
  flex-direction: column
  justify-content: center
  align-items: center
  
.figure-content
  width: 600px
  height: 350px
  border: 1px solid #222
  border-radius: 2px
  overflow: hidden
  user-select: none
  cursor: default

              
            
!

JS

              
                // Canvas Painting 
// https://codepen.io/FelixLuciano/pen/vYOKjQM

class MyPainting extends CanvasPainting {
  scope () {
    return {
      background: '#E82',
      color: '#FD2',
      width: 150,
      height: 250,
      offset: 0,
      speed: 1/4
    }
  }
  
  get $flamePath () {
    const { width, height, offset } = this.$scope
    const { PI, sin, pow, sqrt, cbrt } = Math
    const path = new Path2D()
    
    const wave = (x, w = width, h = height) =>
      width * sqrt(sin(pow(((cbrt(PI) * x) / h), 3))) / 2

    const distortY = (x, w = width, h = height, o = offset) =>
      h * wave(x)/w * sin(PI * sin(o + x / h * 16)) * 3/25

    const distortX = (x, w = width, o = offset) =>
      w * sin(o + x / w * 10) / 15

    for (let y = 0; y <= height; y++) {
      const posX = -wave(y) + distortX(y)
      const posY = y + distortY(y)
      
      path.lineTo(posX, posY)
    }    
    for (let y = height; y >= 0; y--) {
      const posX = wave(y) + distortX(y)
      const posY = y - distortY(y)
      
      path.lineTo(posX, posY)
    }
    
    return path
  }
  
  draw () {    
    const { width, height, color } = this.$scope
    const { ctx2D:ctx, $flamePath:path } = this
    const originX = this.width / 2
    const originY = (this.height - height) / 2
    
    ctx.save()
    
    ctx.fillStyle = color
    ctx.translate(originX, originY)
    ctx.fill(path)
    
    ctx.fillStyle = '#FFF'
    ctx.translate(0, height * .47)
    ctx.scale(.5, .5)
    ctx.fill(path)
    
    ctx.restore()
  }
  
  loop () {
    const { offset, speed } = this.$scope
    this.$scope.offset = (offset + speed) % (2 * Math.PI)
  }
}


window.customElements.define('my-painting', MyPainting, {extends: 'canvas'})

              
            
!
999px

Console