Sha256: 3a06afc2340420bdadc019005857a3c80a2922b541f10f7bbcd6bb1e4aa20e25

Contents?: true

Size: 1.23 KB

Versions: 21

Compression:

Stored size: 1.23 KB

Contents

page = require('webpage').create()

page.viewportSize = { width: 400, height : 400 }
page.content = '<html><body><canvas id="surface"></canvas></body></html>'

page.evaluate ->
  el = document.getElementById 'surface'
  context = el.getContext '2d'
  width = window.innerWidth
  height = window.innerHeight
  cx = width / 2
  cy = height / 2
  radius = width / 2.3
  i = 0

  el.width = width
  el.height = height
  imageData = context.createImageData(width, height)
  pixels = imageData.data

  for y in [0...height]
    for x in [0...width]
      i = i + 4
      rx = x - cx
      ry = y - cy
      d = rx * rx + ry * ry
      if d < radius * radius
        hue = 6 * (Math.atan2(ry, rx) + Math.PI) / (2 * Math.PI)
        sat = Math.sqrt(d) / radius
        g = Math.floor(hue)
        f = hue - g
        u = 255 * (1 - sat)
        v = 255 * (1 - sat * f)
        w = 255 * (1 - sat * (1 - f))
        pixels[i] = [255, v, u, u, w, 255, 255][g]
        pixels[i + 1] = [w, 255, 255, v, u, u, w][g]
        pixels[i + 2] = [u, u, w, 255, 255, v, u][g]
        pixels[i + 3] = 255

  context.putImageData imageData, 0, 0
  document.body.style.backgroundColor = 'white'
  document.body.style.margin = '0px'

page.render('colorwheel.png')

phantom.exit()

Version data entries

21 entries across 19 versions & 3 rubygems

Version Path
hooch-0.4.2 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/colorwheel.coffee
hooch-0.4.1 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/colorwheel.coffee
hooch-0.4.0 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/colorwheel.coffee
hooch-0.3.0 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/colorwheel.coffee
hooch-0.2.1 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/colorwheel.coffee
hooch-0.2.0 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/colorwheel.coffee
hooch-0.1.0 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/colorwheel.coffee
hooch-0.0.8 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/colorwheel.coffee
hooch-0.0.7 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/colorwheel.coffee
hooch-0.0.6 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/examples/colorwheel.coffee
entangled-0.0.16 spec/dummy/public/node_modules/phantomjs/lib/phantom/examples/colorwheel.coffee
entangled-0.0.15 spec/dummy/public/node_modules/phantomjs/lib/phantom/examples/colorwheel.coffee
entangled-0.0.14 spec/dummy/public/node_modules/phantomjs/lib/phantom/examples/colorwheel.coffee
entangled-0.0.13 spec/dummy/public/node_modules/phantomjs/lib/phantom/examples/colorwheel.coffee
entangled-0.0.12 spec/dummy/public/node_modules/phantomjs/lib/phantom/examples/colorwheel.coffee
entangled-0.0.11 spec/dummy/public/node_modules/phantomjs/lib/phantom/examples/colorwheel.coffee
entangled-0.0.10 spec/dummy/public/node_modules/phantomjs/lib/phantom/examples/colorwheel.coffee
phantomjs.rb-0.0.2 vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/colorwheel.coffee
phantomjs.rb-0.0.2 vendor/phantomjs-1.4.1_OSX/examples/colorwheel.coffee
phantomjs.rb-0.0.1 vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/colorwheel.coffee