canvas绘制城堡效果
代码语言:html
所属分类:布局界面
代码描述:canvas绘制城堡效果
代码标签: 效果
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <style> html, body { height: 100%; display: flex; justify-content: center; align-items: center; background-color: #ddd; } </style> </head> <body translate="no"> <canvas id="canvas"></canvas> <script> const canvas = document.getElementById("canvas"); const ctx = canvas.getContext("2d"); canvas.width = 400; canvas.height = 400; let time = 0; function draw() { time++; ctx.clearRect(0, 0, 400, 400); /* // Rules ctx.beginPath(); for (var i = 0; i < 10; i++) { let pos = i * 50; ctx.moveTo(pos, 0); ctx.lineTo(pos, 400); ctx.fillText(pos, pos, 10); ctx.moveTo(0, pos); ctx.lineTo(400, pos); ctx.fillText(pos, 10, pos); } ctx.strokeStyle = "rgba(0, 0, 0, .1)"; ctx.stroke(); */ ctx.beginPath(); ctx.moveTo(25, 350); ctx.lineTo(375, 350); ctx.lineWidth = 2; ctx.strokeStyle = "#000"; ctx.stroke(); ctx.fillStyle = "#ed5a2a"; ctx.fillRect(300, 300, 50, 50); ctx.strokeRect(300, 300, 50, 50); ctx.beginPath(); ctx.rect(250, 250, 50, 100); ctx.rect(50, 300, 50, 50); ctx.fillStyle = &q.........完整代码请登录后点击上方下载按钮下载查看
网友评论0