cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

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.

            
              @import compass

html, body, canvas
  height: 100%
  width: 100%
  margin: 0
  padding: 0
            
          
!
            
              canvas = document.getElementById 'canvas'
ctx = canvas.getContext '2d'
canvasHeight = canvas.height
canvasWidth = canvas.width

time = 0
steps = 60
side = canvasWidth / steps
bars = Math.ceil canvasHeight / side


π = Math.PI

deg_to_rad = (deg) ->
  deg * 2 * π / 360

colorWaves = (t, T1, T2, T3, φ1, φ2, φ3, y_0 = 128, a = 127) ->
  ω1 = 2 * π / T1
  ω2 = 2 * π / T2
  ω3 = 2 * π / T3
  for bar in [0..bars]
    ø_y = (-1) ^ bar * bar * 2 * π / steps
    for ø_0 in [0..steps]
      ø_x = ø_0 * 2 * π / steps
      r = Math.floor Math.sin(ω1 * t + φ1 - ø_x + ø_y) * a + y_0
      g = Math.floor Math.sin(ω2 * t + φ2 - ø_x + ø_y) * a + y_0
      b = Math.floor Math.sin(ω3 * t + φ3 - ø_x + ø_y) * a + y_0

      ctx.fillStyle = "rgb(#{r}, #{g}, #{b})"
      ctx.fillRect ø_0 * side, bar * side, side, side

φ = deg_to_rad 120
paint = () ->
  colorWaves time, steps, steps, steps, φ, 0, -φ
  time++
  requestAnimationFrame paint

requestAnimationFrame paint, 30

            
          
!
999px
Loading ..................

Console