DrawLine1.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <template>
  2. <canvas id="drawLine1" width="800" height="100" />
  3. </template>
  4. <script lang="ts">
  5. import { SCanvasView, SColor, SPainter } from "@saga-web/draw/lib";
  6. class TestView extends SCanvasView {
  7. constructor() {
  8. super("drawLine1")
  9. }
  10. onDraw(canvas: SPainter): void {
  11. // 清除画布
  12. canvas.clearRect(0,0,800,100);
  13. // 在此编写绘制操作相关命令
  14. canvas.drawLine(0,0, 100, 100);
  15. canvas.pen.lineWidth = 1;
  16. canvas.pen.color = SColor.Blue;
  17. for (let i = 0; i < 360; i += 10) {
  18. let q = i * Math.PI / 180;
  19. canvas.drawLine(
  20. 200,
  21. 50,
  22. 200 + 50 * Math.cos(q),
  23. 50 + 50 * Math.sin(q));
  24. }
  25. canvas.pen.color = SColor.Red;
  26. for (let i = 0; i < 360; i += 10) {
  27. let q1 = i * Math.PI / 180;
  28. let q2 = (i + 120) * Math.PI / 180;
  29. canvas.drawLine(
  30. 350 + 50 * Math.cos(q1),
  31. 50 + 50 * Math.sin(q1),
  32. 350 + 50 * Math.cos(q2),
  33. 50 + 50 * Math.sin(q2));
  34. }
  35. canvas.pen.lineWidth = 1;
  36. canvas.pen.dashOffset = new Date().getTime()/50%60;
  37. canvas.pen.lineDash = [10,50];
  38. canvas.drawLine(400, 50, 700, 50);
  39. this.update();
  40. }
  41. }
  42. export default {
  43. mounted() {
  44. new TestView();
  45. }
  46. }
  47. </script>