Canvas链式操作
2024-09-02 06:43:03
Canvas 链式操作
canvas有个非常麻烦的地方就是不支持链式操作,导致书写极其繁琐,刚刚学习了canvas的链式操作。
下面是代码
改进之后的写法,犀利得多啊!
1.canvas = document.querySelector('#canvas')
2.
3.class C2D
4. (canvas) ->
5. @context = canvas.getContext \2d
6. for let prop of @context
7. @[prop] = ->
8. if typeof @context[prop] is "function"
9. return @context[prop].apply @context, & or this
10. @context[prop] = Array.prototype.join.call &
11. this
12. this
13.
14.cc = new C2D canvas
15.cc.beginPath!
16. .arc 50, 50, 20, Math.PI * 2, false
17. .fillStyle("red")
18. .fill!
19. .stroke!
20. .beginPath!
21. .moveTo 100, 100
22. .lineTo 200, 200
23. .strokeStyle "lawngreen"
24. .lineWidth 10
25. .stroke!
26.
最新文章
- dijkstra 最短路算法
- Java类型相互转换byte[]类型,blob类型
- Diving Into Lync Client Logins
- 【转】TCP三次握手过程
- JAVA 年轻代收集器 第九节
- GCD实现倒计时
- 逆向集录_00_不同程序OEP特征总结
- 深入理解SpringBoot之装配条件
- 微信小程序 组件 Demo
- LR参数化取值规则总结
- C语言 · 单词数统计
- python 全栈开发,Day82(点赞和踩灭,用户评论)
- vue给元素动态添加class
- html随笔CSS(*^__^*)
- Knockout学习,添加模板,事件,Mouseover,mouseout
- 基于Python自动上传包到nexus仓库
- 企业搜索引擎开发之连接器connector(二十一)
- Undirected Graphs
- Ubuntu/Debian下编译PC版的ffmpeg
- 浅谈深度学习中的激活函数 - The Activation Function in Deep Learning
热门文章
- android 跨进程通讯 AIDL
- SIGGRAPH 2017:深度学习与计算机图形学的碰撞
- 将C4C Service Request中的summary和其他附件同步到ERP的Billing Request去
- 2018.2.25 关于JavaScript
- java sql database相关收集
- eclipse报错GC overhead limit exceed,卡顿
- javaweb基础(6)_servlet配置参数
- iOS 通过storyboard设置UIView或者其他layer图层的圆角
- 吐槽在cocos2dx游戏接入腾讯信鸽的坑
- cesium底图加载底图切换 基于天地图服务