Canvas

@Entry
@Component
struct LikePage {
  @State message: string = 'Hello World'

  //设置
  setting: RenderingContextSettings = new RenderingContextSettings(true)
  //画笔
  paint: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.setting)

  build() {
    Canvas(this.paint).width("100%").height("100%").backgroundColor(Color.Pink)
      .onReady(() => {
        this.draw()
      })
  }

  draw() {
    //当前的弧度
    var currentRadian = 0
    //每一次增加的弧度
    var add_radian = Math.PI / 180

    //将画布的圆心坐标移动到其他位置
    this.paint.translate(180, 180)
    //设置画笔颜色
    this.paint.strokeStyle = "#ff0000"
    this.paint.lineWidth = 10
    //将画笔移动到起点
    this.paint.moveTo(this.call_x(currentRadian), this.call_y(currentRadian))

    //周期执行方法
    setInterval(()=>{
      //绘制
      if (currentRadian <= Math.PI * 2) {
        //获取当前的弧度
        currentRadian = currentRadian + add_radian
        var endX = this.call_x(currentRadian)
        var endY = this.call_y(currentRadian)
        this.paint.lineTo(endX, endY)
        //绘制
        this.paint.stroke()
      }else {
        //填充
        this.paint.fillStyle="#ff0000"
        this.paint.fill()
      }
    },30)

  }
  //获取x值
  x=16(sint)3
  call_x(t) {
    return 10*(16 * Math.sin(t) * Math.sin(t) * Math.sin(t))
  }
  y=13cost- 5cos2t-2cos3t-cos4t
  //获取y值
  call_y(t) {
    return -10*(13 * Math.cos(t) - 5 * Math.cos(2 * t) - 2 * Math.cos(3 * t) - Math.cos(4 * t))
  }
}