|
<! DOCTYPE html> |
|
|
|
lang= "en" > |
|
<meta charset= "UTF-8" > |
|
<title></title> |
|
|
|
<body> |
|
<canvas id= "mycas" width= "height=" ></canvas> |
|
<div> |
|
<input type= "button" value= " Draw path 1" onclick= "lujing1 ()"/> |
|
|
|
<input type= "button" value= " draw gradient 1" onclick= "jianbian1 ()"/> |
|
<input type= "button" value= " draw gradient 2" onclick= "jianbian2 ()"/> |
|
|
|
<input type= "button" value= " draw gradient 3" onclick= "jianbian3 ()"/> |
|
<input type= "button" value= " draw gradient 4" onclick= "jianbian4 ()"/> |
|
</div> |
|
<div> |
|
<input type= "button" value= " Draw line weight 1" onclick= "xiantiao ()"/> |
|
|
|
<input type= "button" value= " plot the changed coordinates" onclick= "Bianhua ()"/> |
|
<input type= "button" value= " Draw Zoom Effect" onclick= "bianhua2 ()"/> |
|
<input type= "button" value= " draw rotation effect" onclick= "bianhua3 ()"/> |
|
</div> |
|
<script> |
|
function Bianhua3 () { |
|
var cas = document.getElementById ("Mycas"); |
|
var g = Cas.getcontext ("2d"); |
|
|
|
G.translate (200, 200); |
|
|
|
for (var i=0; i<36; i++) { |
|
G.rotate (10*math.pi/180); |
|
G.fillrect (100, 100, 100,100); |
|
} |
|
|
|
} |
|
function Bianhua2 () { |
|
var cas = document.getElementById ("Mycas"); |
|
var g = Cas.getcontext ("2d"); |
|
|
|
G.fillrect (20, 20, 50,50); |
|
|
|
G.fillstyle= "Blue"; |
|
G.translate (50, 10); |
|
G.scale (2,0.5); |
|
G.fillrect (20, 20, 50,50); |
|
|
|
G.fillstyle= "Yellow"; |
|
G.translate (50, 10); |
|
G.scale (2,2); |
|
G.fillrect (20, 20, 50,50); |
|
|
|
|
|
} |
|
function Bianhua () { |
|
var cas = document.getElementById ("Mycas"); |
|
var g = Cas.getcontext ("2d"); |
|
|
|
G.fillrect (20, 20, 50,50); |
|
|
|
G.fillstyle= "Blue"; |
|
G.translate (100,-10); |
|
G.fillrect (20, 20, 50,50); |
|
|
|
} |
|
function Xiantiao () { |
|
var cas = document.getElementById ("Mycas"); |
|
var g = Cas.getcontext ("2d"); |
|
|
|
G.moveto (10,10); |
|
G.lineto (200, 300); |
|
|
|
g.linewidth=30; |
|
G.stroke (); |
|
|
|
} |
|
function Jianbian4 () { |
|
var cas = document.getElementById ("Mycas"); |
|
var g = Cas.getcontext ("2d"); |
|
|
|
var CG = G.createradialgradient (100,100, 50, 60, 80, 100); |
|
Cg.addcolorstop (0, "blue"); |
|
Cg.addcolorstop (1, "yellow"); |
|
|
|
G.FILLSTYLE=CG; |
|
|
|
G.arc (0, math.pi*2); |
|
|
|
G.fill (); |
|
} |
|
function Jianbian3 () { |
|
var cas = document.getElementById ("Mycas"); |
|
var g = Cas.getcontext ("2d"); |
|
|
|
var CG = G.createradialgradient (100,100, 50, 100,100, 100); |
|
Cg.addcolorstop (0, "blue"); |
|
Cg.addcolorstop (1, "yellow"); |
|
|
|
G.FILLSTYLE=CG; |
|
|
|
G.arc (0, math.pi*2); |
|
G.stroke (); |
|
G.fill (); |
|
G.fillrect (0, 0, 300, 300); |
|
} |
|
function Jianbian2 () { |
|
var cas = document.getElementById ("Mycas"); |
|
var g = Cas.getcontext ("2d"); |
|
|
|
var CG = g.createlineargradient (50,50, 250,250); |
|
Cg.addcolorstop (0, "blue"); |
|
Cg.addcolorstop (1, "yellow"); |
|
|
|
G.FILLSTYLE=CG; |
|
|
|
G.fillrect (30, 30, 300, 300); |
|
} |
|
function Jianbian1 () { |
|
var cas = document.getElementById ("Mycas"); |
|
var g = Cas.getcontext ("2d"); |
|
|
|
var CG = g.createlineargradient (50,50, 300,50); |
|
Cg.addcolorstop (0, "blue"); |
|
Cg.addcolorstop (0.6, ' gray '); |
|
Cg.addcolorstop (1, "yellow"); |
|
|
|
G.FILLSTYLE=CG; |
|
|
|
G.fillrect (0, 50, 400, 200); |
|
} |
|
function Lujing1 () { |
|
var cas = document.getElementById ("Mycas"); |
|
var g = Cas.getcontext ("2d"); |
|
|
|
G.beginpath (); |
|
G.arc (100,100, MATH.PI*4/3, MATH.PI*2/3, false); |
|
G.lineto (100, 100); |
|
G.closepath (); |
|
G.stroke (); |
|
G.fill (); |
|
|
|
G.beginpath (); |
|
G.fillstyle= ' Blue '; |
|
G.arc (95,100, MATH.PI*4/3, MATH.PI*2/3, true); |
|
G.lineto (95, 100); |
|
G.closepath (); |
|
G.stroke (); |
|
G.fill (); |
|
} |
|
</script> |
|
</body> |
|
|