html&JS学习笔记(4)

<!DOCTYPE html> 
<html>
<body>
<meta charset="utf-8">
<canvas id="myCanvas" width="500" height="500">
你的浏览器不支持HTML5
</canvas>
<script type="text/javascript">
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");

var grd=ctx.createRadialGradient(100,100,10,100,100,50);
grd.addColorStop(0,"#00ff00");
grd.addColorStop(1,"#ff0000");
ctx.fillStyle=grd;
ctx.fillRect(0,0,200,200);
</script>
</body>
</html

html&JS学习笔记(4)_第1张图片



本博客所有内容是原创,如果转载请注明来源

http://blog.csdn.net/myhaspl/





<!DOCTYPE html> 
<html>
<body>
<meta charset="utf-8">
<canvas id="myCanvas" width="500" height="500">
你的浏览器不支持HTML5
</canvas>
<script type="text/javascript">
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");

var grd=ctx.createLinearGradient(0,0,200,0);
grd.addColorStop(0.1,"#00ff00");
grd.addColorStop(0.8,"#ff0000");
ctx.fillStyle=grd;
ctx.fillRect(0,0,200,100);
</script>
</body>
</html>

html&JS学习笔记(4)_第2张图片

 阴影羽化

通过 ctx.shadowBlur=100羽化

通过ctx.shadowColor="#ff0000"制作阴影


<!DOCTYPE html> 
<html>
<body>
<meta charset="utf-8">
<canvas id="myCanvas" width="500" height="500">
你的浏览器不支持HTML5
</canvas>
<script type="text/javascript">
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");

ctx.shadowColor="#ff0000";
ctx.shadowBlur=100;
ctx.shadowOffsetX=50;
ctx.shadowOffsetY=80;
var image =new Image();
image.src="pic1.jpg";
image.onload=function(){
	ctx.drawImage(image,0,0);
}
</script>
</body>
</html


本博客所有内容是原创,如果转载请注明来源

http://blog.csdn.net/myhaspl/

涂鸦
<!DOCTYPE html> 
<html>
<body>
<meta charset="utf-8">
<canvas id="myCanvas" width="500" height="500">
你的浏览器不支持HTML5
</canvas>
<script type="text/javascript">
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.fillStyle="blue";
ctx.fillRect(0,0,400,400);

var onoff=false;
var oldx=-5;
var oldy=-5;
var linecolor="white";
var linw=3; 
c.addEventListener("mousemove",draw,true);
c.addEventListener("mousedown",down,false);
c.addEventListener("mouseup",up,false);
function down(event){
	onoff=true;
	oldx=event.pageX-5;
	oldy=event.pageY-5;
}
function up(){
	onoff=false;
}
function draw(event){
	if(onoff==true){
		var newx=event.pageX-5;
		var newy=event.pageY-5;
		ctx.beginPath();
		ctx.moveTo(oldx,oldy);
		ctx.lineTo(newx,newy);
		ctx.strokeStyle=linecolor;
		ctx.lineWidth=linw;
		ctx.lineCap="round";
		ctx.stroke();
		oldx=newx;
		oldy=newy;
	}
}
</script>
</body>
</html>
html&JS学习笔记(4)_第3张图片

你可能感兴趣的:(js,html5)