请教各位大神,此类效果如何实现
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <canvas></canvas> <script> window.onload = function () { const canvas = document.getElementsByTagName('canvas')[0] const ctx = canvas.getContext("2d"); const w = document.documentElement.clientWidth; const h = document.documentElement.clientHeight; canvas.width = w; canvas.height = h; let mols = [] function init() { let mol = new generate_mol(1) mols.push(mol); } function draw(){ canvas.width = canvas.width; for(var i=0;i<mols.length;i++){ var m = mols[i]; m.draw(); } } function generate_mol(mol) { this.x = w*0.3; this.y = h*0.3; // this.vx = Math.random()*-2; // this.vy = Math.random()*2; // this.vr = 0.1; this.r = Math.random()*Math.PI; this.draw = function() { // ctx.save(); // ctx.translate(this.x + 20, this.y + 80); // ctx.rotate(Math.PI * 0.17); // ctx.translate(-this.x + 20, -this.y - 80); // ctx.beginPath(); // ctx.moveTo(this.x, this.y + 30); // ctx.lineTo(this.x - 26, this.y + 45); // ctx.lineTo(this.x - 26, this.y + 75); // ctx.lineTo(this.x, this.y + 90); // ctx.lineTo(this.x + 26, this.y + 75); // ctx.lineTo(this.x + 26, this.y + 45); // ctx.lineTo(this.x, this.y + 30); // ctx.moveTo(this.x - 20, this.y + 47); // ctx.strokeStyle = "rgba(0,0,0,0.2)"; // ctx.lineWidth = 3; // ctx.stroke(); // ctx.closePath(); // ctx.restore() ctx.fillStyle = "rgba(0,0,0,0.5)"; ctx.font = "15px Arial"; ctx.fillText("A", this.x+40 , this.y+80); ctx.save(); ctx.translate(this.x + 20, this.y + 30); ctx.rotate(Math.PI * 0.17); ctx.translate(-this.x + 20, -this.y - 80); ctx.beginPath(); ctx.moveTo(this.x, this.y + 30); ctx.lineTo(this.x - 26, this.y + 45); ctx.lineTo(this.x - 26, this.y + 75); ctx.lineTo(this.x, this.y + 90); ctx.lineTo(this.x + 26, this.y + 75); ctx.lineTo(this.x + 26, this.y + 45); ctx.lineTo(this.x, this.y + 30); ctx.moveTo(this.x - 20, this.y + 47); ctx.strokeStyle = "rgba(0,0,0,0.2)"; ctx.lineWidth = 3; ctx.stroke(); ctx.fillStyle = "rgba(0,0,0,0.5)"; ctx.font = "15px Arial"; ctx.fillText("B", this.x , this.y+70); ctx.closePath(); ctx.restore() ctx.save(); ctx.translate(this.x + 68, this.y + 56); ctx.rotate(Math.PI * 0.17); ctx.translate(-this.x + 20, -this.y - 80); ctx.beginPath(); ctx.moveTo(this.x, this.y + 30); ctx.lineTo(this.x - 26, this.y + 45); ctx.lineTo(this.x - 26, this.y + 75); ctx.lineTo(this.x, this.y + 90); ctx.lineTo(this.x + 26, this.y + 75); ctx.lineTo(this.x + 26, this.y + 45); ctx.lineTo(this.x, this.y + 30); ctx.moveTo(this.x - 20, this.y + 47); ctx.strokeStyle = "rgba(0,0,0,0.2)"; ctx.lineWidth = 3; ctx.stroke(); ctx.closePath(); ctx.restore() ctx.save(); ctx.translate(this.x + 66, this.y + 110); ctx.rotate(Math.PI * 0.17); ctx.translate(-this.x + 20, -this.y - 80); ctx.beginPath(); ctx.moveTo(this.x, this.y + 30); ctx.lineTo(this.x - 26, this.y + 45); ctx.lineTo(this.x - 26, this.y + 75); ctx.lineTo(this.x, this.y + 90); ctx.lineTo(this.x + 26, this.y + 75); ctx.lineTo(this.x + 26, this.y + 45); ctx.lineTo(this.x, this.y + 30); ctx.moveTo(this.x - 20, this.y + 47); ctx.strokeStyle = "rgba(0,0,0,0.2)"; ctx.lineWidth = 3; ctx.stroke(); ctx.closePath(); ctx.restore() ctx.save(); ctx.translate(this.x + 20, this.y + 135); ctx.rotate(Math.PI * 0.17); ctx.translate(-this.x + 20, -this.y - 80); ctx.beginPath(); ctx.moveTo(this.x, this.y + 30); ctx.lineTo(this.x - 26, this.y + 45); ctx.lineTo(this.x - 26, this.y + 75); ctx.lineTo(this.x, this.y + 90); ctx.lineTo(this.x + 26, this.y + 75); ctx.lineTo(this.x + 26, this.y + 45); ctx.lineTo(this.x, this.y + 30); ctx.moveTo(this.x - 20, this.y + 47); ctx.strokeStyle = "rgba(0,0,0,0.2)"; ctx.lineWidth = 3; ctx.stroke(); ctx.closePath(); ctx.restore() // ctx.save(); ctx.translate(this.x -27,this.y + 108); ctx.rotate(Math.PI * 0.17); ctx.translate(-this.x + 20, -this.y - 80); ctx.beginPath(); ctx.moveTo(this.x, this.y + 30); ctx.lineTo(this.x - 26, this.y + 45); ctx.lineTo(this.x - 26, this.y + 75); ctx.lineTo(this.x, this.y + 90); ctx.lineTo(this.x + 26, this.y + 75); ctx.lineTo(this.x + 26, this.y + 45); ctx.lineTo(this.x, this.y + 30); ctx.moveTo(this.x - 20, this.y + 47); ctx.strokeStyle = "rgba(0,0,0,0.2)"; ctx.lineWidth = 3; ctx.stroke(); ctx.closePath(); ctx.restore() ctx.save(); ctx.translate(this.x -26, this.y + 56); ctx.rotate(Math.PI * 0.17); ctx.translate(-this.x + 20, -this.y - 80); ctx.beginPath(); ctx.moveTo(this.x, this.y + 30); ctx.lineTo(this.x - 26, this.y + 45); ctx.lineTo(this.x - 26, this.y + 75); ctx.lineTo(this.x, this.y + 90); ctx.lineTo(this.x + 26, this.y + 75); ctx.lineTo(this.x + 26, this.y + 45); ctx.lineTo(this.x, this.y + 30); ctx.moveTo(this.x - 20, this.y + 47); ctx.strokeStyle = "rgba(0,0,0,0.2)"; ctx.lineWidth = 3; ctx.stroke(); ctx.closePath(); ctx.restore() } } init() draw() } </script> </body> </html>
没画好 画偏了应该还要加算法 来生成指定个数的预览地址
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
暂无简介
文章 0 评论 0
接受
发布评论
评论(1)
没画好 画偏了
应该还要加算法 来生成指定个数的
预览地址