画布画头猪

在这里插入图片描述

<template>
  <div class="a">
    <canvas id="myCanvas"></canvas>
  </div>
</template>
<script>
import chat from "./chat.vue";
export default {
  components: { chat },
  name: "trainCity",
  data() {
    return {
      canvas: null,
      context: null,
    };
  },
  mounted() {
    this.doew();
  },
  methods: {
    doew() {
      this.canvas = document.getElementById("myCanvas"); //创建一个画布
      this.canvas.width = "800"; //注意:没有单位
      this.canvas.height = "800"; //注意:没有单位
      this.context = this.canvas.getContext("2d"); //canvas现在还是一个小孩子,不能支持3D
      //准备画个圆
      this.context.beginPath(); //设置弧形,因为这里圆是属于弧形
      this.context.arc(150, 75, 70, 0, 2 * Math.PI); //画弧的方法
      this.context.stroke(); //在页面是实际画的方式、
      //内左眼睛
      this.context.beginPath(); //设置弧形,因为这里圆是属于弧形
      this.context.arc(120, 55, 5, 0, 2 * Math.PI); //画弧的方法
      this.context.stroke(); //在页面是实际画的方式、
      //内右眼睛
      this.context.beginPath(); //设置弧形,因为这里圆是属于弧形
      this.context.arc(180, 55, 5, 0, 2 * Math.PI); //画弧的方法
      this.context.stroke(); //在页面是实际画的方式、
      //外左眼睛
      this.context.beginPath(); //设置弧形,因为这里圆是属于弧形
      this.context.arc(120, 55, 10, 0, 2 * Math.PI); //画弧的方法
      this.context.stroke(); //在页面是实际画的方式、
      //外右眼睛
      this.context.beginPath(); //设置弧形,因为这里圆是属于弧形
      this.context.arc(180, 55, 10, 0, 2 * Math.PI); //画弧的方法
      this.context.stroke(); //在页面是实际画的方式、
      //左耳朵
      this.context.beginPath(); //设置弧形,因为这里圆是属于弧形
      this.context.moveTo(120, 10);
      this.context.quadraticCurveTo(20, 0, 80, 80);
      this.context.stroke(); //在页面是实际画的方式、
      //右耳朵
      this.context.beginPath(); //设置弧形,因为这里圆是属于弧形
      this.context.moveTo(180, 10);
      this.context.quadraticCurveTo(280, 0, 220, 75);
      this.context.stroke(); //在页面是实际画的方式、
      //外鼻子
      this.context.beginPath(); //设置弧形,因为这里圆是属于弧形
      this.context.ellipse(150, 100, 45, 30, 0, 10, Math.PI, true);
      this.context.stroke();
      //左鼻空
      this.context.beginPath(); //设置弧形,因为这里圆是属于弧形
      this.context.ellipse(120, 100, 5, 10, 0, 10, Math.PI, true);
      this.context.stroke();
      //右鼻空
      this.context.beginPath(); //设置弧形,因为这里圆是属于弧形
      this.context.ellipse(180, 100, 5, 10, 0, 10, Math.PI, true);
      this.context.stroke();
    },
  },
};
</script>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值