溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

html5 canvas 涂鴉

發(fā)布時間:2020-07-19 19:40:13 來源:網(wǎng)絡(luò) 閱讀:230 作者:antlove 欄目:移動開發(fā)

html5 canvas 涂鴉

<!DOCTYPE HTML>
<html>
<body>

<canvas id="myCanvas" width="800" height="600" ></canvas>

<script type="text/javascript">
	// get canvas instance
	var canvas=document.getElementById("myCanvas");
	var ctx=canvas.getContext("2d");

	// draw a line 
	ctx.moveTo(10,10);
	ctx.lineTo(150,50);
	ctx.lineTo(10,50);
	ctx.stroke();

	// draw a circle
	ctx.beginPath();
	ctx.arc(100,100,30,0,Math.PI*2,true);
	ctx.closePath();
	ctx.stroke();

	// fill a circle
	ctx.fillStyle="#FF0000";
	ctx.beginPath();
	ctx.arc(100,200,30,0,Math.PI*2,true);
	ctx.closePath();
	ctx.fill();


	// create linear gradient
	var linearGrd=ctx.createLinearGradient(0,0,270,0);
	linearGrd.addColorStop(0,"black");
	linearGrd.addColorStop(0.5,"red");
	linearGrd.addColorStop(1,"white");

	ctx.fillStyle=linearGrd;
	ctx.fillRect(120,230,140,40);

	// create radial gradient
	var radialGrd = ctx.createRadialGradient(400,400,50,400,400,100);
	radialGrd.addColorStop(0,"red");
	radialGrd.addColorStop(1,"white");
	ctx.fillStyle=radialGrd;
	ctx.fillRect(300,300,500,500);


	// draw p_w_picpath
	var img=new Image();
	img.src="e.jpg";
	img.onload=function(){
		ctx.drawImage(img,0,0,50,50,0,400,50,50);
	};
</script>
</body>
</html>



向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI