当前位置:网站首页>Canvas Bezier Bezier curve
Canvas Bezier Bezier curve
2022-07-24 05:34:00 【Plum blossom three】
Twice Bessel :quadraticCurveTo(cpx, cpy, x, y)
Three times Bessel :bezierCurveTo(cpx1, cpy1, cpx2, cpy2, x, y)
cpx and cpy Is the control point coordinates ,x and y Is the coordinate of the end point
design sketch :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
#cvs {
background-color: #ccc;
}
</style>
</head>
<body>
<div id='container'>
<canvas id='cvs'>
sorry, your browser doesn't support canvas API.
</canvas>
</div>
</body>
<script>
window.onload = function() {
// Get canvas
const cvs = document.querySelector('#cvs')
cvs.width = 800
cvs.height = 600
// Get the brush
const ctx = cvs.getContext('2d')
// The prairie
drawPrairie(ctx)
// sky
drawSky(ctx)
// The clouds
drawClouds(ctx)
function drawPrairie(ctx) {
ctx.save()
ctx.beginPath()
ctx.moveTo(0, 420)
ctx.bezierCurveTo(250, 300, 350, 550, 800, 400)
ctx.lineTo(800, 600)
ctx.lineTo(0, 600)
ctx.closePath()
const grd = ctx.createLinearGradient(0, 600, 600, 0)
grd.addColorStop(0, '#00aa58')
grd.addColorStop(0.3, '#63aa7b')
grd.addColorStop(1, '#04aa00')
ctx.fillStyle = grd
ctx.fill()
ctx.restore()
}
function drawSky(ctx) {
ctx.save()
ctx.beginPath()
ctx.moveTo(0, 420)
ctx.bezierCurveTo(250, 300, 350, 550, 800, 400)
ctx.lineTo(800, 0)
ctx.lineTo(0, 0)
ctx.closePath()
const grd = ctx.createRadialGradient(400, 0, 50, 400, 0, 200)
grd.addColorStop(0, '#42a9aa')
grd.addColorStop(1, '#2491aa')
ctx.fillStyle = grd
ctx.fill()
ctx.restore()
}
function drawClouds(ctx) {
for(let i = 0; i < 5; i++) {
const x0 = 500 * Math.random() + 50
const y0 = 200 * Math.random() + 50
const c0 = 100 * Math.random() + 50
// Single cloud
drawCloud(ctx, x0, y0, c0)
}
}
function drawCloud(ctx, cx, cy, cw) {
const maxWidth = 800
cx = cx % maxWidth
const ch = cw * 0.6
ctx.beginPath()
const grd = ctx.createLinearGradient(0, 0, 0, cy)
grd.addColorStop(0, 'rgba(255, 255, 255, 0.8')
grd.addColorStop(1, 'rgba(255, 255, 255, 0.5')
ctx.arc(cx, cy, cw * 0.19, 0, 360)
ctx.arc(cx + cw * 0.08, cy - ch * 0.3, cw * 0.11, 0, 360)
ctx.arc(cx + cw * 0.3, cy - ch * 0.25, cw * 0.25, 0, 360)
ctx.arc(cx + cw * 0.6, cy, cw * 0.21, 0, 360)
ctx.arc(cx + cw * 0.3, cy - ch * 0.1, cw * 0.28, 0, 360)
ctx.fillStyle = grd
ctx.fill()
}
}
</script>
</html>
边栏推荐
猜你喜欢

canvas - 填充

MySQL之CRUD

flex布局

LaTeX学习笔记(一)——安装配置

Hurry in!! Take you to understand what is multi file, and easily master the usage of extern and static C language keywords!!!

【百度地图API】您所使用的地图JS API版本过低,已不再维护,为保证地图基本功能 正常使用,请尽快升级到最新版地图JS API

解决:控制台使用nvm控制node版本时出现exit status 1与exit status 145

select_ Render small phenomena

网页播放rtsp视频流

pycharm 配置局域网访问,局域网无法访问解决办法
随机推荐
4. Draw a red triangle and a yellow square on the screen. Triangle in the back, small; Square in front, big. Using the fusion technology, the triangle can be seen through the square, and the source an
What is the function of key
libevent多线程服务端+客户端源码
构造函数_Map构造函数
微信小程序报错request:fail -2:net::ERR_FAILED
JS链表中的快慢指针
Scikit learn notes
函数_概括
jsp标签02
Constructor_ Date constructor
special effects - 鼠标移动,出现星星拖尾
6. Draw a Bezier curve and a Bezier surface on the screen
Hurry in!! Take you to understand what is multi file, and easily master the usage of extern and static C language keywords!!!
Pure white tutorial using Druid database connection pool in idea
Neo4j修改标签名
[[[recursion]]]
select_ Render small phenomena
【百度地图API】您所使用的地图JS API版本过低,已不再维护,为保证地图基本功能 正常使用,请尽快升级到最新版地图JS API
JS - 计算直角三角形的边长及角度
JS输出字符串中出现最多次数的字符