|
|

楼主 |
发表于 2024-5-1 10:48
|
显示全部楼层
本帖最后由 马黑黑 于 2024-5-1 11:38 编辑
代码:
- <canvas id="canv" width="400" height="400" style="border:1px solid gray"></canvas>
- <script>
- var ctx = canv.getContext('2d');
- var x = 50, y = 150, width = 200;
- var points = [
- {x: x + width, y: y}, // 1
- {x: x, y: y}, // 2
- {x: x, y: y + width}, // 3
- {x: x + width, y: y + width}, // 4
- {x: x + width*3/2, y: y + width/2}, // 5
- {x: x + width*3/2, y: y - width/2}, // 6
- {x: x + width/2, y: y - width/2}, // 7
- {x: x + width/2, y: y + width/2} // 8
- ];
- let drawPanel = (p1,p2,p3,p4) => {
- ctx.beginPath();
- ctx.strokeStyle = 'white';
- ctx.fillStyle = 'rgba(0,100,100,.7)';
- ctx.moveTo(p1.x, p1.y);
- ctx.lineTo(p2.x, p2.y);
- ctx.lineTo(p3.x, p3.y);
- ctx.lineTo(p4.x, p4.y);
- ctx.closePath();
- ctx.stroke();
- ctx.fill();
- };
- drawPanel(points[4],points[5], points[6], points[7]); //后
- drawPanel(points[2],points[3], points[4], points[7]); //底
- drawPanel(points[1],points[2], points[7], points[6]); //左
- drawPanel(points[0],points[1], points[6], points[5]); //顶
- drawPanel(points[0],points[3], points[4], points[5]); //右
- drawPanel(points[0],points[1], points[2], points[3]); //前
- </script>
复制代码
|
评分
-
| 参与人数 1 | 威望 +50 |
金钱 +100 |
经验 +50 |
收起
理由
|
红影
| + 50 |
+ 100 |
+ 50 |
赞一个! |
查看全部评分
|