javascript - Coffeescript 中的 beginPath() ?

标签 javascript html canvas coffeescript html5-canvas

希望使用 CoffeeScript 操作 html5 Canvas 。

正在寻找 jQuery beginPath() 的类似方法,但我在互联网上找不到。

如何在coffeescript中使用beginPath()?感谢您的任何想法!

最佳答案

这是来自 ( http://autotelicum.github.io/Smooth-CoffeeScript/interactive/interactive-coffeescript.html ) 的“生命种子”示例

webdesign = -> 
  doctype 5
  html ->
    head ->
      meta charset: 'utf-8'
      title 'My drawing | My awesome website'
      style '''
        body {font-family: sans-serif}
        header, nav, section, footer {display: block}
      '''
      coffeescript ->
        draw = (ctx, x, y) ->
          circle = (ctx, x, y) ->
            ctx.beginPath()
            ctx.arc x, y, 100, 0, 2*Math.PI, false
            ctx.stroke()
          ctx.strokeStyle = 'rgba(255,40,20,0.7)'
          circle ctx, x, y
          for angle in [0...2*Math.PI] by 1/3*Math.PI
            circle ctx, x+100*Math.cos(angle),
                        y+100*Math.sin(angle)
        window.onload = ->
          canvas = document.getElementById 'drawCanvas'
          context = canvas.getContext '2d'
          draw context, 300, 200
    body ->
      header -> h1 'Seed of Life'
      canvas id: 'drawCanvas', width: 550, height: 400

关于javascript - Coffeescript 中的 beginPath() ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25597785/

相关文章:

firefox - webGL readPixels 和 FireFox 35

javascript - Sketch.js如何导出/导入数据(导入为图像,透明线不透明)

javascript - 用头像表达

javascript - Grails 2.0 : Use Service in javascript function in GSP

javascript - 在创建时增加 javascript 对象名称?

javascript - p5.j​​s 沿多边形轨迹移动对象

javascript - 使用 Swiper 创建水平可拖动列表

javascript - 如何让抖动动画消失

jquery 下拉框字体和对齐方式

html - 响应式 iframe 内容 : scale d3 to iframe size