国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

javascript30 | 08.彩虹畫板 | Github爆火項(xiàng)目 | 30

2023-08-10 23:00 作者:He_Atom  | 我要投稿


簡單修改了一下,看看效果

<!DOCTYPE html>

<html lang="en">


<head>

? <meta charset="UTF-8">

? <meta name="viewport" content="width=device-width, initial-scale=1.0">

? <style>

? ? * {

? ? ? padding: 0;

? ? ? margin: 0;

? ? }

? </style>

? <title>彩虹筆繪畫板</title>

</head>


<body>

? <canvas id="draw"></canvas>

? <script>

? ? const canvas = document.querySelector('#draw')

? ? const parent = ?canvas.parentElement

? ? parent.style.overflow = 'hidden'

? ? const ctx = canvas.getContext('2d')

? ? // 開啟抗鋸齒

? ? ctx.imageSmoothingEnabled = true

? ? // 設(shè)置像素比例

? ? const pixelRatio = window.devicePixelRatio || 1

? ? canvas.width = window.innerWidth * pixelRatio

? ? canvas.height = window.innerHeight * pixelRatio

? ? // 設(shè)置畫布大小 獲取父元素的大小

? ? canvas.style.width = parent.clientWidth + 'px'

? ? canvas.style.height = parent.clientHeight + 'px'


? ? // 設(shè)置畫筆樣式

? ? ctx.strokeStyle = '#BADA55'

? ? ctx.lineJoin = 'round'

? ? ctx.lineCap = 'round'

? ? ctx.lineWidth = 10


? ? let mode = 'pen'

? ? let isDrawing = false

? ? let maxLineWidth = 10

? ? let minLineWidth = 4

? ? let lastX = 0

? ? let lastY = 0

? ? let hue = 0 // 色相 0-360

? ? let speed = 0


? ? function draw(e) {

? ? ? if (!isDrawing) return


? ? ? if (mode === 'mouse') {

? ? ? ? const x = e.clientX

? ? ? ? const y = e.clientY


? ? ? ? // 計(jì)算鼠標(biāo)速度

? ? ? ? speed = Math.sqrt(Math.pow(x - lastX, 2) + Math.pow(y - lastY, 2)) / 5

? ? ? ? if (speed < 1) speed = 1

? ? ? ? ctx.lineWidth = maxLineWidth / speed + minLineWidth



? ? ? ? ctx.strokeStyle = `hsl(${hue}, 100%, 50%)`

? ? ? ? ctx.beginPath()

? ? ? ? ctx.moveTo(lastX * pixelRatio, lastY * pixelRatio)

? ? ? ? ctx.lineTo(x * pixelRatio, y * pixelRatio)

? ? ? ? ctx.stroke()


? ? ? ? lastX = x

? ? ? ? lastY = y

? ? ? }

? ? ? if (mode === 'pen') {

? ? ? ? const x = e.touches[0].clientX

? ? ? ? const y = e.touches[0].clientY


? ? ? ? ctx.lineWidth = maxLineWidth * e.touches[0].force + minLineWidth


? ? ? ? ctx.strokeStyle = `hsl(${hue}, 100%, 50%)`

? ? ? ? ctx.beginPath()

? ? ? ? ctx.moveTo(lastX * pixelRatio, lastY * pixelRatio)

? ? ? ? ctx.lineTo(x * pixelRatio, y * pixelRatio)

? ? ? ? ctx.stroke()


? ? ? ? lastX = x

? ? ? ? lastY = y

? ? ? }


? ? ? hue += 0.1

? ? ? if (hue >= 360) {

? ? ? ? hue = 0

? ? ? }

? ? }


? ? canvas.addEventListener('mousedown', (e) => {

? ? ? isDrawing = true

? ? ? lastX = e.clientX - canvas.offsetLeft

? ? ? lastY = e.clientY - canvas.offsetTop

? ? })


? ? canvas.addEventListener('mousemove', (e) => {

? ? ? mode = 'mouse'

? ? ? draw(e)

? ? })


? ? canvas.addEventListener('mouseup', () => {

? ? ? isDrawing = false

? ? ? ctx.lineWidth = maxLineWidth

? ? })


? ? canvas.addEventListener('touchstart', (e) => {

? ? ? isDrawing = true

? ? ? lastX = e.touches[0].clientX - canvas.offsetLeft

? ? ? lastY = e.touches[0].clientY - canvas.offsetTop

? ? })


? ? canvas.addEventListener('touchmove', (e) => {

? ? ? mode = 'pen'

? ? ? draw(e)

? ? })


? ? canvas.addEventListener('touchend', () => {

? ? ? isDrawing = false

? ? ? ctx.lineWidth = maxLineWidth

? ? })

? </script>

</body>


</html>


javascript30 | 08.彩虹畫板 | Github爆火項(xiàng)目 | 30的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國家法律
观塘区| 兴隆县| 边坝县| 嘉祥县| 永安市| 新昌县| 开原市| 林口县| 绩溪县| 杭锦旗| 清原| 屯昌县| 广昌县| 晋城| 屏山县| 望江县| 龙川县| 蛟河市| 浪卡子县| 三亚市| 谢通门县| 东山县| 临沂市| 天峻县| 湖北省| 红原县| 钟祥市| 西乌珠穆沁旗| 睢宁县| 岳阳市| 枝江市| 望谟县| 江孜县| 奉节县| 从化市| 栾城县| 五家渠市| 安阳市| 德兴市| 宜君县| 廉江市|