当前位置:网站首页>初鉴canvas,展示个小小的小案例
初鉴canvas,展示个小小的小案例
2022-04-23 13:04:00 【孤身不觉晚】
今天工作量不大,得空了解了一下canvas,顺便画出了一个“丁”老头,特此展示,以待大众取乐而已!

好不好看????
算了,辣眼就辣眼吧,看代码吧。
<canvas id="canvas" width="500" height="500"></canvas>
var canvas = document.getElementById("canvas");
var context = canvas.getContext('2d');
//先画一个头
context.beginPath();
context.arc(250,250,50,0,Math.PI*2);
context.stroke();
//再画两个耳朵
context.beginPath();
context.arc(200,200,20,0,Math.PI*2);
context.fill();
context.beginPath();
context.arc(300,200,20,0,Math.PI*2);
context.fill();
//再画两只眼
context.beginPath();
context.arc(230,240,10,0,Math.PI*2);
context.stroke();
context.beginPath();
context.arc(270,240,10,0,Math.PI*2);
context.stroke();
//补上两个眼珠子
context.beginPath();
context.arc(230,240,2,0,Math.PI*2);
context.fill();
context.beginPath();
context.arc(270,240,2,0,Math.PI*2);
context.fill();
//再画一个三角鼻子
context.beginPath();
context.moveTo(250,250);//画布中指点一个点,不创建线条
context.lineTo(240,260);//添加一个新点,然后创建从该点到画布中最后指定点的线条(该方法并不会创建线条)
context.lineTo(260,260);//添加一个新点,然后创建从该点到画布中最后指定点的线条(该方法并不会创建线条)
context.closePath();//末点回到起点
context.stroke();
//再画一个嘴巴
context.beginPath();
context.arc(250,270,15,0,Math.PI,false);
context.stroke();
这么一看,canvas还是很好玩的哦
版权声明
本文为[孤身不觉晚]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_40043424/article/details/103633512
边栏推荐
- Packet capturing and sorting -- TCP protocol [8]
- [untitled] PID control TT encoder motor
- Common problems of unity (1)
- STM32 tracking based on open MV
- Customize classloader and implement hot deployment - use loadclass
- Date time type in database
- Summary of JVM knowledge points - continuously updated
- MySQL -- 16. Data structure of index
- 1130 - host XXX is not allowed to connect to this MySQL server error in Navicat remote connection database
- 产品开发都应该知道的8个网站,增强工作体验
猜你喜欢

Unable to create servlet under SRC subfile of idea

Homomorphic encryption technology learning

Jupiter notebook installation

Introduction to servlet listener & filter

Deploying MySQL in cloud native kubesphere

How to click an object to play an animation

Important knowledge of network layer (interview, reexamination, term end)

如何实现点击一下物体播放一次动画

jmeter操作redis

软件测试周刊(第68期):解决棘手问题的最上乘方法是:静观其变,顺水推舟。
随机推荐
31. 下一个排列
Connect orcale
AUTOSAR from introduction to mastery 100 lectures (87) - key weapon of advanced EEA - AUTOSAR and DDS
8 websites that should be known for product development to enhance work experience
Temperature and humidity monitoring + timing alarm system based on 51 single chip microcomputer (C51 source code)
「玩转Lighthouse」轻量应用服务器自建DNS解析服务器
JMeter operation redis
The accuracy and speed are perfectly balanced, and the latest image segmentation SOTA model is released!!!
CVPR 2022&NTIRE 2022|首个用于高光谱图像重建的 Transformer
MySQL -- 16. Data structure of index
JDBC connection pool
进程虚拟地址空间区域划分
22. Bracket generation
软件测试周刊(第68期):解决棘手问题的最上乘方法是:静观其变,顺水推舟。
8086 of x86 architecture
SSM framework series - data source configuration day2-1
100 GIS practical application cases (51) - a method for calculating the hourly spatial average of NC files according to the specified range in ArcGIS
Important knowledge of transport layer (interview, retest, final)
Van uploader upload picture implementation process, using native input to upload pictures
unity常见的问题(一)