DrawLine1.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <template>
  2. <canvas id="drawLine1" width="800" height="100"/>
  3. </template>
  4. <script lang="ts">
  5. import { SCanvasView, SColor, SPainter } from "@persagy-web/draw/lib";
  6. import { Component, Vue } from "vue-property-decorator";
  7. class TestView extends SCanvasView {
  8. /**
  9. * 构造函数
  10. */
  11. constructor() {
  12. super("drawLine1")
  13. }
  14. /**
  15. * Item 绘制操作
  16. * @param canvas 绘制对象
  17. */
  18. onDraw(canvas: SPainter): void {
  19. // 清除画布
  20. canvas.clearRect(0, 0, 800, 100);
  21. // 在此编写绘制操作相关命令
  22. canvas.drawLine(0, 0, 100, 100);
  23. canvas.pen.lineWidth = 1;
  24. canvas.pen.color = SColor.Blue;
  25. for (let i = 0; i < 360; i += 10) {
  26. let q = i * Math.PI / 180;
  27. // 绘制一条线段
  28. canvas.drawLine(
  29. 200,
  30. 50,
  31. 200 + 50 * Math.cos(q),
  32. 50 + 50 * Math.sin(q));
  33. }
  34. canvas.pen.color = SColor.Red;
  35. for (let i = 0; i < 360; i += 10) {
  36. let q1 = i * Math.PI / 180;
  37. let q2 = (i + 120) * Math.PI / 180;
  38. canvas.drawLine(
  39. 350 + 50 * Math.cos(q1),
  40. 50 + 50 * Math.sin(q1),
  41. 350 + 50 * Math.cos(q2),
  42. 50 + 50 * Math.sin(q2));
  43. }
  44. canvas.pen.color = new SColor('#03a9f4');
  45. canvas.pen.lineWidth = 5;
  46. canvas.drawLine(450, 50, 700, 50);
  47. canvas.pen.lineWidth = 3;
  48. canvas.pen.dashOffset = new Date().getTime() / 50 % 80;
  49. canvas.pen.lineDash = [30, 50];
  50. canvas.pen.color = SColor.White;
  51. canvas.drawLine(450, 50, 700, 50);
  52. this.update();
  53. }
  54. }
  55. @Component
  56. export default class DrawLine1 extends Vue {
  57. mounted(): void {
  58. new TestView();
  59. }
  60. }
  61. </script>