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

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

              
                <canvas width="800" height="600">Your browser sucks !</canvas>
<!--Click on the document to create more circle!-->
              
            
!

CSS

              
                body{
  color: #7fff00;
  background: #090909;
  margin: 0;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

canvas{
  margin: 0 auto;
  width: 100vw;
  height: 100vh;
}
              
            
!

JS

              
                const $canvas = document.querySelector("canvas")
const ctx = $canvas.getContext("2d")

// Responsive canvas

const resize = () => {
  $canvas.width = window.innerWidth
  $canvas.height = window.innerHeight
}

window.addEventListener("resize", resize)
resize()

// App

// Circle class, used to created unique waving circle
class Circle {
  constructor (x, y, radius, waveNumber, ctx) {
    this.pos = {x: x, y: y}
    this.radius = radius
    this.waves = []
    this.createWave(waveNumber)

    this.circleColor = ctx.createRadialGradient(x, y, 0, x, y, radius) 
    this.circleColor.addColorStop(0, "#595959")
    this.circleColor.addColorStop(1, "#191919")
  }

  createWave(num) {
    while (this.waves.length < num) {
      this.waves.push(new Wave(this))
    }
  }

  draw() {
    
    ctx.beginPath()
    ctx.arc(this.pos.x, this.pos.y, this.radius, 0, Math.PI * 2)
    ctx.fillStyle = this.circleColor
    ctx.shadowColor = "rgba(0, 0, 0, 0)"
    ctx.fill()

    //ctx.globalCompositeOperation = "lighter"
    for (const wave of this.waves) {
      wave.waving(this)
      ctx.beginPath()
      ctx.arc(this.pos.x, this.pos.y, this.radius, wave.start.angle, wave.end.angle)
      ctx.bezierCurveTo(
        wave.tension1.x, wave.tension1.y,
        wave.tension2.x, wave.tension2.y,
        wave.start.x, wave.start.y
      )
      ctx.fillStyle = wave.color
      ctx.shadowColor = "rgba(0, 0, 0, .8)"
      ctx.shadowBlur = 5
      ctx.shadowOffsetX = Math.cos((wave.start.angle + wave.end.angle) / 2 + Math.PI) * 5
      ctx.shadowOffsetY = Math.sin((wave.start.angle + wave.end.angle) / 2 + Math.PI) * 5
      ctx.fill()
    }

    ctx.beginPath()
    ctx.arc(this.pos.x, this.pos.y, this.radius, 0, Math.PI * 2)
    ctx.strokeStyle = this.circleColor
    ctx.lineWidth = 10
    ctx.shadowColor = "rgba(0, 0, 0, .8)"
    ctx.shadowBlur = 10
    ctx.shadowOffsetX = 5
    ctx.shadowOffsetY = 5
    ctx.stroke()
  }
}

// Wave class used to create and update each wave of each circle
class Wave {
  constructor (that) {
    this.minAngle = 0.4
    this.maxAngle = 0.7 - this.minAngle

    this.start = {angle: Math.PI * 2 * Math.random()}
    this.end = {angle: this.start.angle + Math.PI * (this.minAngle + Math.random() * this.maxAngle)}

    this.color = `hsl(${Math.random() * 360}, 100%, ${Math.random() * 20 + 50}%)`
    this.speed = 0.001 + Math.random() * 0.005
    this.globalAmpl = 0.1
    this.tension1 = {
      xAmpl: 1 + this.globalAmpl + Math.random() * this.globalAmpl,
      yAmpl: 1 + this.globalAmpl + Math.random() * this.globalAmpl,
      noise: Math.random() - 0.5
    }
    this.tension2 = {
      xAmpl: 1 + this.globalAmpl + Math.random() * this.globalAmpl,
      yAmpl: 1 + this.globalAmpl + Math.random() * this.globalAmpl,
      noise: Math.random() - 0.5
    }
  }

  waving(that) {
    this.start.angle += this.speed
    this.start.x = that.pos.x + that.radius * Math.cos(this.start.angle)
    this.start.y = that.pos.y + that.radius * Math.sin(this.start.angle)
    
    this.end.angle += this.speed
    this.end.x = that.pos.x + that.radius * Math.cos(this.end.angle)
    this.end.y = that.pos.y + that.radius * Math.sin(this.end.angle)

    this.tension1.x = that.pos.x + (that.radius / this.tension1.xAmpl) * Math.cos(this.end.angle + Math.sin(Date.now() * 0.1 * this.speed + this.tension1.noise))
    this.tension1.y = that.pos.y + (that.radius / this.tension1.yAmpl) * Math.sin(this.end.angle + Math.sin(Date.now() * 0.1 * this.speed + this.tension1.noise))

    this.tension2.x = that.pos.x + (that.radius / this.tension1.xAmpl) * Math.cos(this.start.angle + Math.sin(Date.now() * 0.1 * this.speed + this.tension2.noise))
    this.tension2.y = that.pos.y + (that.radius / this.tension1.yAmpl) * Math.sin(this.start.angle + Math.sin(Date.now() * 0.1 * this.speed + this.tension2.noise))
  }
}

// x, y, radius, number of wave, context
const circles = [new Circle(400, 200, 100, 10, ctx)]

// Create new circle on click
window.addEventListener("mouseup", (e) => {
  if(circles.length >= 10) {
    circles.splice(0, 1)
  }
  circles.push(new Circle(
    e.clientX,
    e.clientY,
    50 + Math.floor(Math.random() * 150),
    1 + Math.floor(Math.random() * 15),
    ctx
  ))
})

// Updating
const loop = () =>
{
  window.requestAnimationFrame(loop)
  
  ctx.clearRect(0, 0, $canvas.width, $canvas.height)

  for(const circle of circles) {
    circle.draw()
  }
}

loop()
              
            
!
999px

Console