当前位置:网站首页>Canvas drawing -- bingdd
Canvas drawing -- bingdd
2022-07-03 01:12:00 【Blue fatty's Dora A Dream】
```xml
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bing Dwen Dwen</title>
<style> * {
margin: 0; padding: 0; } body {
height: 100vh; } #canvas {
margin: 0 auto; display: block; border: 1px solid #eeeeee; } </style>
</head>
<body>
<canvas id="canvas" width="700" height="600"></canvas>
<script> const canvasEle = document.getElementById('canvas') const ctx = canvasEle.getContext('2d') // Some constants const BODY_LINE_WIDTH = 10 const EYE_FILL_COLOR = '#000000' // Drawing ellipse function drawEllipse(ctxOptions = {
}, ellipseOption = {
}) {
ctx.beginPath() ctx.ellipse(ellipseOption.x, ellipseOption.y, ellipseOption.radiusX, ellipseOption.radiusY, ellipseOption.rotation, ellipseOption.startAngle, ellipseOption.endAngle, ellipseOption.anticlockwise) ctx.strokeStyle = ctxOptions.strokeStyle || '#000000' ctx.lineWidth = ctxOptions.lineWidth || 1 ctx.stroke() if (ctxOptions.fillStyle) {
ctx.fillStyle = ctxOptions.fillStyle ctx.fill() } } // A circle function drawCircle(ctxOptions = {
}, circleOption = {
}) {
ctx.beginPath() ctx.arc(circleOption.x, circleOption.y, circleOption.radius, circleOption.startAngle, circleOption.endAngle, circleOption.anticlockwise) ctx.strokeStyle = ctxOptions.strokeStyle || '#000000' ctx.lineWidth = ctxOptions.lineWidth || 1 ctx.stroke() if (ctxOptions.fillStyle) {
ctx.fillStyle = ctxOptions.fillStyle ctx.fill() } } // Draw two ellipses of the body drawEllipse( {
lineWidth: BODY_LINE_WIDTH, }, {
x: 250, y: 300, radiusX: 180, radiusY: 200, rotation: 0, startAngle: 0, endAngle: 2 * Math.PI, anticlockwise: false, } ) drawEllipse({
lineWidth: BODY_LINE_WIDTH, }, {
x: 250, y: 250, radiusX: 130, radiusY: 90, rotation: 0, startAngle: 0, endAngle: 2 * Math.PI, anticlockwise: false, }) // Draw a rainbow drawEllipse({
strokeStyle: 'rgb(0, 183, 222)', lineWidth: 5 }, {
x: 250, y: 250, radiusX: 135, radiusY: 95, rotation: 0, startAngle: 0, endAngle: 2 * Math.PI, anticlockwise: false, }) drawEllipse({
strokeStyle: 'rgb(221, 108, 155)', lineWidth: 5 }, {
x: 250, y: 250, radiusX: 140, radiusY: 100, rotation: 0, startAngle: 0, endAngle: 2 * Math.PI, anticlockwise: false, }) drawEllipse({
strokeStyle: 'rgb(223, 192, 79)', lineWidth: 5 }, {
x: 250, y: 250, radiusX: 145, radiusY: 105, rotation: 0, startAngle: 0, endAngle: 2 * Math.PI, anticlockwise: false, }) drawEllipse({
strokeStyle: 'rgb(148, 204, 95)', lineWidth: 5 }, {
x: 250, y: 250, radiusX: 150, radiusY: 110, rotation: 0, startAngle: 0, endAngle: 2 * Math.PI, anticlockwise: false, }) // Draw eyes drawEllipse({
fillStyle: EYE_FILL_COLOR, }, {
x: 180, y: 240, radiusX: 50, radiusY: 35, rotation: -70, startAngle: 0, endAngle: 2 * Math.PI, anticlockwise: false, }) drawEllipse({
fillStyle: EYE_FILL_COLOR }, {
x: 320, y: 240, radiusX: 50, radiusY: 35, rotation: 70, startAngle: 0, endAngle: 2 * Math.PI, anticlockwise: false, }) // Eyes drawCircle({
strokeStyle: '#ffffff', fillStyle: '#ffffff' }, {
x: 190, y: 230, radius: 20, startAngle: 0, endAngle: 2 * Math.PI, anticlockwise: false, }) drawCircle({
strokeStyle: '#ffffff', fillStyle: '#ffffff' }, {
x: 310, y: 230, radius: 20, startAngle: 0, endAngle: 2 * Math.PI, anticlockwise: false, }) drawCircle({
fillStyle: EYE_FILL_COLOR }, {
x: 190, y: 230, radius: 16, startAngle: 0, endAngle: 2 * Math.PI, anticlockwise: false, }) drawCircle({
fillStyle: EYE_FILL_COLOR }, {
x: 310, y: 230, radius: 16, startAngle: 0, endAngle: 2 * Math.PI, anticlockwise: false, }) drawCircle({
strokeStyle: '#ffffff', fillStyle: '#ffffff' }, {
x: 187, y: 225, radius: 6, startAngle: 0, endAngle: 2 * Math.PI, anticlockwise: false, }) drawCircle({
strokeStyle: '#ffffff', fillStyle: '#ffffff' }, {
x: 307, y: 225, radius: 6, startAngle: 0, endAngle: 2 * Math.PI, anticlockwise: false, }) // nose function drawNose() {
ctx.beginPath() ctx.moveTo(230, 270) ctx.lineTo(270, 270) ctx.lineTo(250, 290) ctx.lineTo(230, 270) ctx.strokeStyle = '#000000' ctx.lineJoin = 'round' ctx.stroke() ctx.fillStyle = '#000000' ctx.fill() } drawNose() // mouth function drawMouth() {
ctx.beginPath() ctx.arc(250, 270, 40, 45 * Math.PI / 180, 135 * Math.PI / 180) ctx.lineWidth = 5 ctx.lineCap = 'round' ctx.stroke() } drawMouth() // Ears function drawLeftEar() {
ctx.beginPath() ctx.rotate(-20 * Math.PI / 180) ctx.arc(80, 170, 50, 0, 4 / 5 * Math.PI, true) ctx.fillStyle = '#000000' ctx.fill() } function drawRightEar() {
ctx.beginPath(); ctx.rotate(10 * Math.PI / 180) ctx.beginPath(); ctx.arc(330, 185, 50, (60 * Math.PI / 180), 200 * Math.PI / 180, true); ctx.fill(); } drawLeftEar() drawRightEar() // Draw hands function drawLeftHand() {
ctx.beginPath(); ctx.moveTo(17, 350); ctx.bezierCurveTo(5, 100, -150, 350, 20, 380); ctx.stroke(); ctx.fillStyle = '#000000'; ctx.fill(); } function drawRightHand() {
ctx.beginPath(); ctx.moveTo(370, 400); ctx.bezierCurveTo(420, 440, 470, 600, 340, 460); ctx.stroke(); ctx.fillStyle = '#000000'; ctx.fill(); } drawLeftHand() drawRightHand() // Draw feet function drawLeftFoot() {
ctx.beginPath(); ctx.moveTo(70, 490); ctx.bezierCurveTo(-10, 680, 140, 620, 130, 525); ctx.stroke(); ctx.fillStyle = '#000000'; ctx.fill(); } function drawRightFoot() {
ctx.beginPath(); ctx.moveTo(220, 540); ctx.bezierCurveTo(200, 740, 340, 620, 270, 520); ctx.stroke(); ctx.fillStyle = '#000000'; ctx.fill(); } drawLeftFoot() drawRightFoot() // Write words function drawText(text, x, y, color = '#000000') {
ctx.beginPath(); ctx.fillStyle = color; ctx.font = 'bold 30px Arial'; ctx.fillText(text, x, y); } drawText('Hi ~', -10, 200) // load logo const img = new Image() img.src = './2022-logo.jpg' img.onload = function () {
ctx.beginPath(); ctx.restore(); ctx.drawImage(img, 130, 410, 100, 100) } // Draw love function drawHeart() {
ctx.save(); ctx.beginPath(); ctx.scale(0.5, 0.5); ctx.translate(-120, 500); const centerX = 75; const centerY = 40; ctx.moveTo(centerX, centerY); ctx.bezierCurveTo(centerX, 37, 70, 25, 50, 25); ctx.bezierCurveTo(20, 25, 20, 62.5, 20, 62.5); ctx.bezierCurveTo(20, 80, centerY, 102, centerX, 120); ctx.bezierCurveTo(110, 102, 130, 80, 130, 62.5); ctx.bezierCurveTo(130, 62.5, 130, 25, 100, 25); ctx.bezierCurveTo(85, 25, centerX, 37, centerX, centerY); ctx.fillStyle = 'red'; ctx.fill(); ctx.closePath(); } drawHeart() </script>
</body>
</html>
边栏推荐
- 【FPGA教程案例5】基于vivado核的ROM设计与实现
- Usage of using clause in kingbases alter table
- 按键精灵打怪学习-多线程后台坐标识别
- kivy教程之在 Kivy App 中使用 matplotlib 的示例
- matlab将数字矩阵保存为地理空间数据出错,显示下标索引必须为正整数类型或逻辑类型,解决
- [AUTOSAR + IO Architecture]
- Matlab saves the digital matrix as geospatial data, and the display subscript index must be of positive integer type or logical type. Solve the problem
- [case sharing] let the development of education in the new era advance with "number"
- [flutter] icons component (load the built-in icon of flutter | display the material design icon completely)
- Excel calculates the difference between time and date and converts it into minutes
猜你喜欢

Basic concept and implementation of overcoming hash

Lu Zhe, chief scientist of Shiping information: building data and personnel centered security capabilities

Explain the basic concepts and five attributes of RDD in detail

RISA rz/g2l processor introduction | frame diagram | power consumption | schematic diagram and hardware design guide

Daily topic: movement of haystack

数据分析思维分析犯法和业务知识——分析方法(一)

Win10 can't be installed in many ways Problems with NET3.5

安全运营四要素之资产、脆弱性、威胁和事件

matlab将数字矩阵保存为地理空间数据出错,显示下标索引必须为正整数类型或逻辑类型,解决

Esp32 simple speed message test of ros2 (limit frequency)
随机推荐
Foundations of data science is free to download
按键精灵打怪学习-自动寻路回打怪点
Excel calculates the difference between time and date and converts it into minutes
MySQL
【FPGA教程案例6】基于vivado核的双口RAM设计与实现
Deep analysis of data storage in memory
leetcode:871. 最低加油次数【以前pat做过 + 最大堆 +贪心】
Merge K sorted linked lists
【FPGA教程案例5】基于vivado核的ROM设计与实现
关于Fibonacci数列
递归处理组织的几种情况
异步、郵件、定時三大任務
JS inheritance and prototype chain
Understanding and distinguishing of some noun concepts in adjustment / filtering
2022.2.14 resumption
leetcode:701. 二叉搜索树中的插入操作【bst的插入】
[AUTOSAR VI description document]
FPGA - 7系列 FPGA内部结构之Clocking -04- 多区域时钟
Assets, vulnerabilities, threats and events of the four elements of safe operation
基于ARM RK3568的红外热成像体温检测系统