Pen Settings



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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource


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


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.


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.






                noise.seed Math.random()

# return an height value
generateHeight = (x, y) ->
  value = noise.perlin2 x / 64, y / 64
  Math.round Math.abs(value) * 255

# builds a tile map with the given width and height sizes
buildTileMap = (width, height) ->
  tileMap = new Array(width)
  for y in [0...width]
    tileMap[y] = new Array(height)
    for x in [0...height]
      tileMap[y][x] = generateHeight(x, y)

drawTile = (ctx, point, size) ->
  [x1, y1] = [point.x * size.w, point.y * size.h]
  [x2, y2] = [x1 + size.w, y1 + size.h]
  ctx.moveTo x1, y1
  ctx.lineTo x2, y1
  ctx.lineTo x2, y2
  ctx.lineTo x1, y2
  ctx.lineTo x1, y1

$ ->
  scene = document.createElement 'canvas'
  scene.width = scene.height = 512
  # build a tile map.
  # Tilemap size is the half of the canvas size
  map = buildTileMap 128, 128
  ctx = scene.getContext '2d'
  tileSize = 
    w: scene.width / map.length
    h: scene.height / map[0].length

  # draw a 2px circle for each tilemap location
  for y in []
    for height, x in map[y]
      ctx.fillStyle = ctx.strokeStyle = "rgb(#{height},#{height},#{height})"
      drawTile(ctx, { x, y }, tileSize)

  document.body.appendChild scene