Pen Settings

HTML

CSS

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

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

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.

HTML

              
                <section>
  
</section>
              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background: #222222;
}


              
            
!

JS

              
                function easeInOutCubic (t) { return t<.5 ? 4*t*t*t : (t-1)*(2*t-2)*(2*t-2)+1 }
const halfRotation = Math.PI
const fullRotation = Math.PI * 2

function clamp(input, min, max) {
  return Math.max(min, Math.min(input, max))
}

function map(value, low1, high1, low2, high2) {
  return low2 + ((high2 - low2) * (value - low1)) / (high1 - low1);
}

function randomNumber(min, max) {
  return Math.random() * (max - min) + min
}

function randomRoundNumber(min, max) {
  return Math.round(randomNumber(min, max))
}

function mapAndClamp(value, low1, high1, low2, high2) {
  return clamp(
    map(value, low1, high1, low2, high2),
    Math.min(low2, high2), 
    Math.max(low2, high2)
  )
}

const container = document.querySelector('section')


const params = {
  width: 500,
  height: 500
}


const two = new Two(params)
two.appendTo(container)

const loopDuration = 60 * 4
const numberOfShapes = 40
const shapeIncrement = 20
const aDelay = 1 / 120
const shapes = []



for (let i = 0; i < numberOfShapes; i++) {
   const size = (numberOfShapes - i) * shapeIncrement
   const shape = two.makeRectangle(250, 250, size, size)

   
     if (i % 2 === 0) {
        const hue = Math.round(360 / numberOfShapes * i)
        shape.fill = 'hsl(' + hue + ', 70%, 50%)'; 
     } else {
       shape.fill = '#222'       
     }

   
   shape.noStroke()
   shapes.push(shape)
}


two.bind('update', function(frameCount) {
  const currentFrame = frameCount % loopDuration
  const timeline = currentFrame / loopDuration
  
  shapes.forEach((shape, i) => {
    const aStart = aDelay * (numberOfShapes - i)
    const aEnd = aDelay * i
    const u = mapAndClamp(timeline, aStart, 1 - aEnd, 0, 1)
    
    
    if (i % 2 === 0) {
      shape.rotation = easeInOutCubic(u) * halfRotation
    }
    
  })
})

two.play()
              
            
!
999px

Console