提交 c0c091c8 编写于 作者: 张磊

支持贝塞尔曲线

上级 2722c735
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
<view ref="draw-house" style="width: 750rpx;height: 550rpx; background-color: lightgray;margin: 30rpx 0rpx;"></view> <view ref="draw-house" style="width: 750rpx;height: 550rpx; background-color: lightgray;margin: 30rpx 0rpx;"></view>
<view ref="draw-style" style="width: 750rpx;height: 550rpx; background-color: lightgray;margin: 30rpx 0rpx;"></view> <view ref="draw-style" style="width: 750rpx;height: 550rpx; background-color: lightgray;margin: 30rpx 0rpx;"></view>
<view ref="draw-odd" style="width: 750rpx;height: 550rpx; background-color: lightgray;margin: 30rpx 0rpx;"></view> <view ref="draw-odd" style="width: 750rpx;height: 550rpx; background-color: lightgray;margin: 30rpx 0rpx;"></view>
<view ref="draw-arcto" style="width: 750rpx;height: 550rpx; background-color: lightgray;margin: 30rpx 0rpx;"></view>
</view> </view>
<!-- #ifdef APP --> <!-- #ifdef APP -->
</scroll-view> </scroll-view>
...@@ -49,13 +50,14 @@ ...@@ -49,13 +50,14 @@
this.drawhouse() this.drawhouse()
this.drawPoint() this.drawPoint()
this.drawRect() this.drawRect()
this.drawArcTo()
}, },
onUnload() { onUnload() {
y = 160 y = 160
}, },
methods: { methods: {
drawText() { drawText() {
let node = (this.$refs['draw-text-view'] as Element) let node = (this.$refs['draw-text-view'] as INode)
let ctx = node.getDrawableContext() let ctx = node.getDrawableContext()
let width = node.getBoundingClientRect().width let width = node.getBoundingClientRect().width
ctx!!.reset() ctx!!.reset()
...@@ -72,7 +74,7 @@ ...@@ -72,7 +74,7 @@
ctx!!.update() ctx!!.update()
}, },
drawLines() { drawLines() {
let ctx = (this.$refs['draw-line-view'] as Element).getDrawableContext() let ctx = (this.$refs['draw-line-view'] as INode).getDrawableContext()
ctx!!.reset() ctx!!.reset()
ctx!!.lineWidth = 10; ctx!!.lineWidth = 10;
...@@ -106,14 +108,14 @@ ...@@ -106,14 +108,14 @@
ctx!.stroke(); ctx!.stroke();
}); });
ctx!.lineWidth = 1; ctx!.lineWidth = 1;
this.drawDashedLine([], ctx); this.drawDashedLine([], ctx!);
this.drawDashedLine([2, 2], ctx); this.drawDashedLine([2, 2], ctx!);
this.drawDashedLine([10, 10], ctx); this.drawDashedLine([10, 10], ctx!);
this.drawDashedLine([20, 5], ctx); this.drawDashedLine([20, 5], ctx!);
this.drawDashedLine([15, 3, 3, 3], ctx); this.drawDashedLine([15, 3, 3, 3], ctx!);
this.drawDashedLine([20, 3, 3, 3, 3, 3, 3, 3], ctx); this.drawDashedLine([20, 3, 3, 3, 3, 3, 3, 3], ctx!);
ctx!.lineDashOffset = 18; ctx!.lineDashOffset = 18;
this.drawDashedLine([12, 3, 3], ctx); this.drawDashedLine([12, 3, 3], ctx!);
ctx!.lineDashOffset = 0 ctx!.lineDashOffset = 0
ctx!.setLineDash([0]) ctx!.setLineDash([0])
ctx!!.update() ctx!!.update()
...@@ -127,7 +129,7 @@ ...@@ -127,7 +129,7 @@
y += 15; y += 15;
}, },
drawCircles() { drawCircles() {
let ctx = (this.$refs['draw-circle-view'] as Element).getDrawableContext() let ctx = (this.$refs['draw-circle-view'] as INode).getDrawableContext()
ctx!!.reset() ctx!!.reset()
// Draw shapes // Draw shapes
for (var i = 0; i < 4; i++) { for (var i = 0; i < 4; i++) {
...@@ -153,7 +155,7 @@ ...@@ -153,7 +155,7 @@
}, },
drawStar() { drawStar() {
let ctx = (this.$refs['draw-dash-line'] as Element).getDrawableContext() let ctx = (this.$refs['draw-dash-line'] as INode).getDrawableContext()
ctx!!.reset() ctx!!.reset()
ctx!!.beginPath(); ctx!!.beginPath();
var horn = 5; // 画5个角 var horn = 5; // 画5个角
...@@ -224,7 +226,7 @@ ...@@ -224,7 +226,7 @@
return result return result
}, },
drawhouse() { drawhouse() {
let ctx = (this.$refs['draw-house'] as Element).getDrawableContext() let ctx = (this.$refs['draw-house'] as INode).getDrawableContext()
ctx!!.reset() ctx!!.reset()
ctx!!.lineWidth = 10; ctx!!.lineWidth = 10;
...@@ -244,7 +246,7 @@ ...@@ -244,7 +246,7 @@
ctx!!.update() ctx!!.update()
}, },
drawPoint() { drawPoint() {
let ctx = (this.$refs['draw-style'] as Element).getDrawableContext() let ctx = (this.$refs['draw-style'] as INode).getDrawableContext()
ctx!!.reset() ctx!!.reset()
for (let i = 0; i < 6; i++) { for (let i = 0; i < 6; i++) {
for (let j = 0; j < 6; j++) { for (let j = 0; j < 6; j++) {
...@@ -263,7 +265,7 @@ ...@@ -263,7 +265,7 @@
ctx!!.update() ctx!!.update()
}, },
drawRect() { drawRect() {
let ctx = (this.$refs['draw-odd'] as Element).getDrawableContext() let ctx = (this.$refs['draw-odd'] as INode).getDrawableContext()
ctx!!.reset() ctx!!.reset()
// Create path // Create path
ctx!!.moveTo(30, 90); ctx!!.moveTo(30, 90);
...@@ -279,6 +281,27 @@ ...@@ -279,6 +281,27 @@
ctx!.fill("evenodd"); ctx!.fill("evenodd");
ctx!!.update() ctx!!.update()
},
drawArcTo() {
let ctx = (this.$refs['draw-arcto'] as INode).getDrawableContext()
ctx!.reset()
ctx!.beginPath();
ctx!.moveTo(50, 20);
ctx!.bezierCurveTo(230, 30, 150, 60, 50, 100);
ctx!.stroke();
ctx!.fillStyle = "blue";
// start point
ctx!.fillRect(50, 20, 10, 10);
// end point
ctx!.fillRect(50, 100, 10, 10);
ctx!.fillStyle = "red";
// control point one
ctx!.fillRect(230, 30, 10, 10);
// control point two
ctx!.fillRect(150, 70, 10, 10);
ctx!.update()
} }
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册