欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

HTML5 Canvas實(shí)現(xiàn)玫瑰曲線和心形圖案的代碼實(shí)例

  發(fā)布時(shí)間:2014-04-10 23:08:26   作者:佚名   我要評(píng)論
這篇文章主要介紹了HTML5 Canvas實(shí)現(xiàn)玫瑰曲線和心形圖案的代碼實(shí)例,需要的朋友可以參考下

效果圖:
 

提示:把代碼復(fù)制到一個(gè)html文件中并保存,直接打開即可看到效果。

實(shí)現(xiàn)代碼:
 

 

<!DOCTYPE html>
<html>
<head>
<meta charset = "gbk">
<title>HTML5 Demo</title>
<style type="text/css">
#apDiv1 {
position:absolute;
width:120px;
height:300px;
z-index:1;
left: 840px;
top: 80px;
}
</style>
</head>
<body>
<canvas id="canvas" width="800" height="600" style="border:1px solid #c3c3c3;"> 
Your browser does not support the canvas element. </canvas> 
<div id="apDiv1">
<form>
玫瑰曲線方程:<br>
r=a+bsin(m/n*x)<br><br>
選擇參數(shù):<br><br>
m: <input type="number" name="m" min="2" max="29" value="29"/><br><br>
n: <input type="number" name="n" min="1" max="12" value="11"/><br><br>
a: <input type="number" name="a" min="0" max="5" value="1"/><br><br>
b: <input type="number" name="b" min="1" max="7" value="5"/><br><br>
<input type="button" value=" 畫 圖 " onClick="draw();"><br><br>
<hr><br>
<input type="button" value=" 畫 圖 2 " onClick="draw2();"><br><br>
<hr><br>
<input type="button" value=" 心形圖 " onClick="draw3();"><br>
</form>
</div>
<script type="text/javascript"> 
function draw() { 
var ctx = document.getElementById('canvas').getContext('2d'); 
ctx.save(); 
ctx.translate(400,300); 
ctx.clearRect(-400,-300,800,600);
ctx.strokeStyle = "#cc0000"; 
var a = 0, b = 1, m = 6, n = 1;
m = document.forms[0].m.value;
n = document.forms[0].n.value;
a = document.forms[0].a.value; 
b = document.forms[0].b.value; 
drawRose(ctx,a,b,m,n); 
ctx.restore(); 
} 
function drawRose(ctx,a,b,m,n){ 
ctx.beginPath(); 
var e = 0, c = 120; 
var k = 2 * Math.PI / 360;
do { 
var r = a/b + Math.sin( m * e / n * k);
r = r * c; 
var x = r * Math.cos( e * k );
var y = r * Math.sin( e * k );
e += 0.1; 
ctx.lineTo(x,y); 
} while ( e <= 4320 ); 
ctx.stroke(); 
} 
function draw2(){ 
var ctx = document.getElementById('canvas').getContext('2d'); 
ctx.save(); 
ctx.translate(400,300); 
ctx.clearRect(-400,-300,800,600);
ctx.strokeStyle = "#cc0000"; 
ctx.beginPath(); //ctx.moveTo(0,0);
var e = 0, c = 150; 
var k = 2 * Math.PI / 360;
do { 
x = 150*Math.cos( 5/2 * e*k ) + 50*Math.cos( 15/16 * 5/2 * e*k ); 
y = 150*Math.sin( 5/2 * e*k ) - 50*Math.sin( 15/16 * 5/2 * e*k ); 
e += 0.1; 
ctx.lineTo(x,y); 
} while ( e <= 3600 ); 
ctx.stroke(); 
ctx.restore();
} 
function draw3(){ 
var ctx = document.getElementById('canvas').getContext('2d'); 
ctx.save(); 
ctx.translate(400,300); 
ctx.clearRect(-400,-300,800,600);
ctx.strokeStyle = "#ff0000"; 
ctx.beginPath(); 
var x = 1, y;
do { 
y = -80*(Math.sqrt(1-x*x) + Math.pow(x*x,1/3)); 
x -= 0.001; 
ctx.lineTo(100*x,y); 
} while ( x >= -1 ); 

do { 
y = 80*(Math.sqrt(1-x*x) - Math.pow(x*x,1/3)); 
x += 0.001; 
ctx.lineTo(100*x,y); 
} while ( x <= 1 );
ctx.closePath(); 

var grad = ctx.createRadialGradient(-40,-60,10,-40,-40,200);
grad.addColorStop(0, "#ffcc00"); 
grad.addColorStop(1, "#ff0000"); 
ctx.fillStyle = grad;
ctx.fill();
// ctx.stroke(); 
ctx.restore();
} 
window.onload = function (){ 
draw();
} 
</script>
</body>
</html>

 

相關(guān)文章

  • html5 canvas實(shí)現(xiàn)的收益率曲線進(jìn)度條動(dòng)畫效果源碼

    這是一款基于html5 canvas實(shí)現(xiàn)的收益率曲線進(jìn)度條動(dòng)畫效果源碼。曲線進(jìn)度條上顯示數(shù)值的節(jié)點(diǎn)隨著進(jìn)度的推進(jìn)而呈現(xiàn)出相應(yīng)的上升狀態(tài),并實(shí)時(shí)顯示相應(yīng)的數(shù)值
    2017-02-23
  • HTML5 canvas基本繪圖之繪制曲線

    <canvas></canvas>是HTML5中新增的標(biāo)簽,用于繪制圖形,這篇文章主要為大家詳細(xì)介紹了HTML5 canvas基本繪圖之繪制曲線方法,感興趣的小伙伴們可以參考一下
    2016-06-27
  • 使用HTML5的Canvas繪制曲線的簡(jiǎn)單方法

    這篇文章主要介紹了使用HTML5的Canvas繪制曲線的簡(jiǎn)單方法,是HTML5入門學(xué)習(xí)中的基礎(chǔ)知識(shí),需要的朋友可以參考下
    2015-09-08
  • HTML5 Canvas中使用路徑描畫二階、三階貝塞爾曲線

    這篇文章主要介紹了HTML5 Canvas中使用路徑描畫二階、三階貝塞爾曲線,本文給出實(shí)現(xiàn)代碼、效果圖例和解釋說明,需要的朋友可以參考下
    2015-01-01
  • 用html5的canvas畫布繪制貝塞爾曲線完整代碼

    html5的canvas很強(qiáng)大利用其畫布可輕松繪制貝塞爾曲線,為大家以后使用方便,特于此分享實(shí)現(xiàn)代碼,有此需求的朋友可以參考下
    2013-08-14
  • html5 canvas繪制曲線動(dòng)畫特效源碼

    html5 canvas繪制曲線動(dòng)畫特效源碼是一款效果非常不錯(cuò)的曲線動(dòng)畫效果。本段代碼可以在各個(gè)網(wǎng)頁(yè)使用,有需要的朋友可以直接下載使用
    2017-09-15

最新評(píng)論