DrawLine1.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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.color = new SColor('#03a9f4');
  36. canvas.pen.lineWidth = 5;
  37. canvas.drawLine(450, 50, 700, 50);
  38. canvas.pen.lineWidth = 3;
  39. canvas.pen.dashOffset = new Date().getTime()/50%80;
  40. canvas.pen.lineDash = [30,50];
  41. canvas.pen.color = SColor.White;
  42. canvas.drawLine(450, 50, 700, 50);
  43. this.update();
  44. }
  45. }
  46. export default {
  47. mounted() {
  48. new TestView();
  49. }
  50. }
  51. </script>