-
慕斯王
在右边在绘制一条直线角度和右边的棱大约25°,要稍微短一些,然后连接;在右边在绘制一条直线角度和右边的棱大约35°;例子如下:<!DOCTYPE HTML><html><title>canvas test</title><head><style>#canvas{width:800px;height:800px;box-shadow: 0px 0px 10px rgba(0, 0, 0, .8);margin: 10px 10px;}</style></head><body><canvas id='canvas' width=800 height=800>unsupport</canvas></body><script>window.onload = function(){var canvas = document.getElementById('canvas');var ctx = canvas.getContext('2d');ctx.strokeColor = 'black';ctx.lineWidth = 3;ctx.shadowOffsetX = 10;ctx.shadowOffsetY = 5;ctx.shadowBlur = 2;ctx.shadowColor = 'rgba(0, 0, 0, 0.5)';ctx.save();ctx.translate(100, 100);ctx.beginPath();ctx.moveTo(0, 0);ctx.lineTo(400, 0);ctx.moveTo(0, 0);for(var i = 0; i < 20; i += 0.1){var x = i * 20;var y = Math.sin(i) * 20;ctx.lineTo(x, y);}ctx.stroke();ctx.restore();ctx.save();ctx.translate(100, 200);ctx.beginPath();ctx.moveTo(0, 0);ctx.lineTo(400, 0);ctx.moveTo(0, 0);ctx.quadraticCurveTo(150, -100, 200, 0);ctx.quadraticCurveTo(250, 200, 400, 0);ctx.stroke();ctx.restore();ctx.save();ctx.translate(100, 400);ctx.beginPath();ctx.moveTo(0, 0);ctx.lineTo(400, 0);ctx.moveTo(0, 0);ctx.bezierCurveTo(50, 0, 100, -50, 150, -100);ctx.bezierCurveTo(175, -75, 150, -25, 100, 0);ctx.bezierCurveTo(300, -75, 600, -100, 400, 0);ctx.stroke();ctx.restore();ctx.save();ctx.translate(100, 600);ctx.beginPath();ctx.moveTo(0, 0);ctx.lineTo(400, 0);ctx.moveTo(0, -124);for(var i = 0; i < 25; i += 0.1){var x = i * 10;var y = -(((i - 12) * (i - 12)) - 20);ctx.lineTo(x, y);}ctx.stroke();ctx.restore();ctx.save();ctx.beginPath();ctx.moveTo(100, 0);ctx.lineTo(100, 800);ctx.stroke();ctx.restore();};</script></html>
-
一只名叫tom的猫
script代码var g=canvas.getContext("2d");g.beginPath();g.strokeStyle="#F00";g.moveTo(0,0);g.bezierCurveTo(300,0, 0,300, 200,200);g.stroke();
-
慕森卡
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576<!DOCTYPE html><html><head> <title>Cos演示</title> <meta charset='utf-8'></head><body style='text-align:center'><canvas width='800' height='600' id='canvas' style='border:1px solid'> </canvas><script> var canvas=document.getElementById('canvas'); var ctx=canvas.getContext('2d'); function drawAxis(){ ctx.translate(400,300); //x 轴 ctx.beginPath(); ctx.moveTo(-380,0); ctx.lineTo(380,0); ctx.lineTo(372,3); ctx.lineTo(372,-3); ctx.lineTo(380,0); ctx.stroke(); //描边 //y 轴 ctx.moveTo(0,200); ctx.lineTo(0,-200); ctx.lineTo(3,-192); ctx.lineTo(-3,-192); ctx.lineTo(0,-200); ctx.stroke(); //描边 //画坐标 ctx.save(); ctx.strokeStyle='rgba(100,100,255,0.5)'; ctx.moveTo(-Math.PI*100,100); ctx.lineTo(-Math.PI*100,-100); ctx.lineTo(Math.PI*100,-100); ctx.lineTo(Math.PI*100,100); ctx.lineTo(-Math.PI*100,100); ctx.stroke(); //描边 ctx.fillStyle='rgba(0,0,0,1)'; ctx.fillText("-π",-Math.PI*100,10); ctx.fillText("π",Math.PI*100,10); ctx.fillText("-1",5,100); ctx.fillText("1",5,-100); ctx.restore(); } function drawCos(){ var x = -Math.PI*100; ctx.beginPath(); ctx.moveTo(x,100); for(x = -Math.PI*100;x<Math.PI*100;x++){ var cx = x/100; var cy = Math.cos(cx); var y = -cy*100; ctx.lineTo(x,y); } ctx.stroke(); //描边 } function draw(){ ctx.clearRect(0,0,canvas.width,canvas.height); ctx.save(); ctx.shadowColor='rgba(0,0,0,0.8)'; ctx.shadowOffsetX=12; ctx.shadowOffsetY=12; ctx.shadowBlur=15; drawAxis(); drawCos(); ctx.restore(); } ctx.fillStyle='rgba(100,140,230,0.5)'; ctx.strokeStyle='rgba(33,33,33,1)'; draw();</script></body></html>