cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-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.

            
              html
  head
    script(src='https://code.jquery.com/jquery-2.1.1.min.js')
    script(src='https://code.famo.us/lib/functionPrototypeBind.js')
    script(src='https://code.famo.us/lib/classList.js')
    script(src='https://code.famo.us/lib/requestAnimationFrame.js')
    link(rel='stylesheet', href='https://code.famo.us/famous/0.3/famous.css')
    script(src='https://code.famo.us/famous/0.3/famous-global.min.js')
    meta(name='viewport', content='width=device-width, maximum-scale=1, user-scalable=no')
    meta(name='apple-mobile-web-app-capable', content='yes')
    meta(name='apple-mobile-web-app-status-bar-style', content='black')
    meta(name='apple-mobile-web-app-capable', content='yes')
    meta(name='mobile-web-app-capable', content='yes')
 body(style='background-color: #FF851B;')
   p#size(style='color: white; font-family: sans-serif;') Width: XXX, Height: XXX
            
          
!
            
              $ ->
  # Import library here
  Engine = famous.core.Engine
  Surface = famous.core.Surface
  View = famous.core.View
  Transform = famous.core.Transform
  Modifier = famous.core.Modifier
  PhysicsEngine = famous.physics.PhysicsEngine
  Body = famous.physics.bodies.Body
  Circle = famous.physics.bodies.Circle
  Walls = famous.physics.constraints.Walls

  # Start coding here
  Engine.nextTick ->
    
    docW = $(document).width()
    docH = $(document).height()
    ($ '#size').text "Width: #{docW}, Height: #{docH}"

    context = Engine.createContext()
    physicsEngine = new PhysicsEngine
    ball = new Surface
      size: [100, 100]
      properties:
        backgroundColor: '#FFDC00'
        border: '3px solid #FF4136'
        borderRadius: '50px'
    ball.state = new Modifier
      origin: [.5, .5]
      align: [.5, .5]
    ball.particle = new Circle radius: 100
    physicsEngine.addBody ball.particle

    famous.utilities.Timer.setTimeout ->
      ball.particle.setVelocity [1, 1, 0]
    , 1000

    (context.add ball.state).add ball

    walls = new Walls
      restitution: .2
      origin: [.5, .5]
      align: [.5, .5]
      size: [docW, docH]
      sides: famous.physics.constraints.Walls.SIDES.TWO_DIMENSIONAL

    physicsEngine.attach [
      walls.components[0]
      walls.components[1]
      walls.components[2]
      walls.components[3]
    ], [ball.particle]

    ball.state.transformFrom ->
      ball.particle.getTransform()
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console