HTML5ÈëÃÅ

HTML5ʵÑ飺JavaScriptÄ£ÄâÁ÷ÌåЧ¹û

×ÖºÅ+ ×÷Õߣº À´Ô´£º 2014-11-16 20:49 ÎÒÒªÆÀÂÛ( )

µÚ1Ò³»æÖÆÍÖÔ² °ÑÏÖʵÊÀ½çµ±ÖеÄÎïÌåÄ£Äâµ½¼ÆËã»úµ±ÖУ¬Ò»Ð©¼òµ¥µÄÎïÀíʵÑé¡¢ÅöײÐýתµÈµÈÄѶȻ¹ÊDz»ËãºÜ´ó£¬ÄѶȽϴóµÄÓ¦µ±ËãÁ÷ÌåÄ£Äâ¡£ ±¾ÎĽ«ÔÚCanvasµ±ÖÐÄ£Äâ³öÒ»¸ö2DƽÃæÄÚ

 µÚ1Ò³»æÖÆÍÖÔ²

°ÑÏÖʵÊÀ½çµ±ÖеÄÎïÌåÄ£Äâµ½¼ÆËã»úµ±ÖУ¬Ò»Ð©¼òµ¥µÄÎïÀíʵÑé¡¢ÅöײÐýתµÈµÈÄѶȻ¹ÊDz»ËãºÜ´ó£¬ÄѶȽϴóµÄÓ¦µ±ËãÁ÷ÌåÄ£Äâ¡£

±¾ÎĽ«ÔÚCanvasµ±ÖÐÄ£Äâ³öÒ»¸ö2DƽÃæÄÚµÄË®Ö飬Éæ¼°µÄ֪ʶµãºÍ¼¼ÇÉ°üÀ¨£ºJscex»ù´¡ÖªÊ¶£¬±´Èû¶ûÇúÏߵĻæÖÆ£¬ºÏÀíÀûÓÃCanvasRenderingContext2DµÄtranslateºÍrotateµÈAPI¡£

»æÖÆÍÖÔ²

ÔÚÄ£ÄâË®µÎ֮ǰ£¬ÎÒÃÇÏÈ˼¿¼Ò»ÏÂÔõôÔÚcanvasµ±ÖлæÖÆÒ»¸öÍÖÔ²¡£

´ó¼Ò¿ÉÒÔºÜÈÝÒ×Ïëµ½ ÏÂÃ漸ÖÖ·½°¸£º

1.¸ù¾ÝÍÖÔ²µÑ¿¨¶û×ø±êϵ·½³Ì»æÖÆ

2.¸ù¾ÝÍÖÔ²¼«×ø±ê·½³Ì»æÖÆ

3.¸ù¾ÝÍÖÔ²ÇúÂʱ仯»æÖÆ

4.ÀûÓÃËÄÌõ±´Èû¶ûÇúÏß»æÖÆ

µÚËÄÖÖ£¬Ò²ÊÇÐÔÄÜ×îºÃµÄÒ»ÖÖ£¬ÕâÑù¿ÉÒÔ±ÜÃ⸴ÔӵļÆË㣬³ä·ÖÀûÓÃCanvasRenderingContext2DµÄAPI(APIµÄÐÔÄÜÊÇͨ¹ýÑϸñ²âÊÔ£¬Ò»°ãÇé¿öϱȽϿ¿Æ×).

ËùÒÔÎÒÃDzÉÓõÚËÄÖÖ·½Ê½À´»æÖÆÍÖÔ²¡£

var canvas;

var ctx;

ctx = canvas.getContext(“2d”);

ctx.strokeStyle = “#fff”;

function drawEllipse(x, y, w, h) {

var k = 0.5522848;

var ox = (w / 2) * k;

var oy = (h / 2) * k;

var xe = x + w;

var ye = y + h;

var xm = x + w / 2;

var ym = y + h / 2;

ctx.beginPath();

ctx.moveTo(x, ym);

ctx.bezierCurveTo(x, ym – oy, xm – ox, y, xm, y);

ctx.bezierCurveTo(xm + ox, y, xe, ym – oy, xe, ym);

ctx.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);

ctx.bezierCurveTo(xm – ox, ye, x, ym + oy, x, ym);

ctx.stroke();

ctx.clearRect(0,0,canvas.width,canvas.border=”1″ Height);

drawEllipse(10, 10, 40, 82);

(¸Ä±ädrawEllipseµÄËĸö²ÎÊýÊÔÊÔ)

ÐýתÍÖÔ²

ÕâÀïµÄÐýת²»ÊÇÈÆÉÏÃæµÄdrawEllipseµÄÇ°Á½¸ö²ÎÊýx,yÐýת£¬¶þÊÇÈÆÍÖÔ²µÄÖÐÐÄÐýת¡£ËùÒÔ½ö½ö CanvasRenderingContext2D.rotateÊDz»¹»µÄ£¬ÒòΪCanvasRenderingContext2D.rotateÊÇÈÆ»­ ²¼µÄ×óÉϽÇ(0£¬0)Ðýת¡£ËùÒÔÎÒÃÇÏÈÒª°Ñ(0£¬0)ͨ¹ýCanvasRenderingContext2D.translateµ½ÍÖÔ²µÄÖÐÐÄ£¬È»ºóÔÙ drawEllipse(-a/2, –b/2, a, b).

ÉÏÃæÕâ¾ä»°£¬¾ÍÊÇÈÆÖÐÐÄÐýתµÄºËÐÄ¡£ÕâÀﻹ¿ÉÒÔÍƹ㵽ÈÎÒâͼÐλòÕßͼƬ(¼ÙÉèÓÐÔ¼¶¨µÄÖÐÐÄ)¡£Èçͼ£º

HTML5ʵÑ飺JavaScriptÄ£ÄâÁ÷ÌåЧ¹û

µÚ2Ò³ÐýתÍÖÔ²

È»ºóÎÒÃǾͿÉÒÔÏÈ»æÖÆÒ»¸öÄñ³²³öÀ´£º

html>

head>

script src=”http://files.cnblogs.com/iamzhanglei/jscex.jscexRequire.min.js” type=”text/javascript”>script>

head>

body>

style type=”text/css”>

input.css3btn

background: -moz-linear-gradient(270deg, #d2ebf8, #0c8ab5);

background: -webkit-linear-gradient(top, #d2ebf8, #0c8ab5);

background: -o-linear-gradient(top, #d2ebf8, #0c8ab5);

filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=”#000099CC”, EndColorStr=”#FF0087B4″);

border-top: 1px solid #38538c;

border-right: 1px solid #1f2d4d;

border-bottom: 1px solid #151e33;

border-left: 1px solid #1f2d4d;

border-radius: 4px;

box-shadow: inset 0 1px 10px 1px #5c8bee, 0px 1px 0 #1d2c4d, 0 2px 0px #1f3053, 0 4px 4px 1px #111111;

color: #f0f0f0;

font: bold 20px “helvetica neue” , helvetica, arial, sans-serif;

padding: 10px 0 10px 0;

text-align: center;

text-shadow: 0px -1px 1px #1e2d4d;

width: 150px;

background-clip: padding-box;

input.css3btn:hover

box-shadow: inset 0 0px 20px 1px #87adff, 0px 1px 0 #1d2c4d, 0 3px 0px #1f3053, 0 4px 4px 1px #111111;

cursor: pointer;

input.css3btn:active

box-shadow: inset 0 1px 10px 1px #5c8bee, 0 1px 0 #1d2c4d, 0 2px 0 #1f3053, 0 4px 3px 0 #111111;

style>

canvas width=”350″ border=”1″ height=”350″ style=”border: solid 15px #222; background-color: #111;

color: #CCC;”>

Your browser does not support the canvas element.

canvas>

script>

var canvas;

var ctx;

var px = 0;

var py = 0;

function init() {

ctx = canvas.getContext(“2d”);

ctx.strokeStyle = “#fff”;

ctx.translate(70, 70);

init();

var i = 0;

function drawEllipse(x, y, w, h) {

var k = 0.5522848;

var ox = (w / 2) * k;

var oy = (h / 2) * k;

var xe = x + w;

var ye = y + h;

var xm = x + w / 2;

var ym = y + h / 2;

ctx.beginPath();

ctx.moveTo(x, ym);

ctx.bezierCurveTo(x, ym – oy, xm – ox, y, xm, y);

ctx.bezierCurveTo(xm + ox, y, xe, ym – oy, xe, ym);

ctx.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);

ctx.bezierCurveTo(xm – ox, ye, x, ym + oy, x, ym);

ctx.stroke();

ctx.translate(x + 70, y + 100);

px = -70;

py = -100;

ctx.rotate(10 * Math.PI * 2 / 360);

var ct;

var drawAsync = eval(Jscex.compile(“async”, function (ct) {

while (true) {

drawEllipse(px, py, 140, 200)

$await(Jscex.Async.sleep(200, ct));

}))

function Button1_onclick() {

ct.cancel();

function Button2_onclick() {

ct = new Jscex.Async.CancellationToken();

drawAsync(ct).start();

script>

br />

input type=”button” value=”run” onclick=”return Button2_onclick()” />

input type=”button” value=”stop” onclick=”return Button1_onclick()” />

body>

html>

µÚ3Ò³»æÖÆË®µÎ

HTML5ʵÑ飺JavaScriptÄ£ÄâÁ÷ÌåЧ¹û

 

»æÖÆË®µÎ

ÐýתµÄÍÖÔ²ºÍÄñ³²ÉñÂíµÄºÍË®µÎÓÐʲô¹ØϵÄØ?

ÎÒÃÇͨ¹ý¸Ä±äÍÖÔ²µÄ³¤ÖáºÍ¶ÌÖᣬÁîÆä·Ç³£½Ó½üÔ²ÐÎ(Ö»Äܽӽü£¬²»ÄܵÈÓÚÔ²ÐÎ)£¬È»ºóÿ´ÎÐýת²Á³ý»­²¼£¬¾Í¿ÉÒÔ´ïÄãÔ¤Ïë²»µ½µÄЧ¹û!

ÕâÀïÐèҪעÒâµÄÊÇ£¬²Á³ý»­²¼²»ÔÙÊÇÒ»¾ä CanvasRenderingContext2D.clearRect(0,0,canvas.width,canvas.border=”1″ Height)¾Í¿ÉÒÔ£¬ÒòΪ»­²¼ÒѾ­ÐýתºÍ»­²¼Ô­µãÒѾ­translate£¬ËùÒÔÎÒÃÇʹÓà ctx.clearRect(-canvas.width, -canvas.border=”1″ Height, 2 * canvas.width, 2 * canvas.border=”1″ Height)À´²Á³ý»­²¼¡£

ÎÒÃÇ»­Ò»¸ö³¤Öá42£¬¶ÌÖá40µÄÍÖÔ²£¬Ðýת²¢²Á³ý»­²¼£º

function drawEllipse(x, y, w, h) {

ctx.clearRect(-canvas.width, -canvas.border=”1″ Height, 2 * canvas.width, 2 * canvas.border=”1″ Height);

var k = 0.5522848;

var ox = (w / 2) * k;

var oy = (h / 2) * k;

var xe = x + w;

var ye = y + h;

var xm = x + w / 2;

var ym = y + h / 2;

ctx.beginPath();

ctx.moveTo(x, ym);

ctx.bezierCurveTo(x, ym – oy, xm – ox, y, xm, y);

ctx.bezierCurveTo(xm + ox, y, xe, ym – oy, xe, ym);

ctx.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);

ctx.bezierCurveTo(xm – ox, ye, x, ym + oy, x, ym);

ctx.stroke();

ctx.translate(x + 20, y + 21);

px = -20;

py = -21;

ctx.rotate(10 * Math.PI * 2 / 360);

var ct;

var drawAsync = eval(Jscex.compile(“async”, function (ct) {

while (true) {

drawEllipse(px, py, 40, 42)

$await(Jscex.Async.sleep(10, ct));

}))

»áÊÇʲôЧ¹ûÄØ?

ÔÚÏßÑÝʾЧ¹û²é¿´

http://www.cnblogs.com/iamzhanglei/archive/2011/12/12/2284188.html

ÏÖÔÚ´ó¼Ò¿ÉÒÔ¿´µ½Ò»¸ö»Î¶¯µÄË®ÖéÁË

¡¡

1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

Ïà¹ØÎÄÕÂ
  • HTML5µÄÊÓƵ¸ñʽ֮Õù

    HTML5µÄÊÓƵ¸ñʽ֮Õù

    2014-11-16 20:49

  • Windows Internet Explorer 10 ¿ª·¢ÕßÖ¸ÄÏ

    Windows Internet Explorer 10 ¿ª·¢ÕßÖ¸ÄÏ

    2014-11-16 20:49

  • 16 ¸öÓ¡ÏóÉî¿ÌµÄ HTML5/CSS3/JavaScript ÌåÑé

    16 ¸öÓ¡ÏóÉî¿ÌµÄ HTML5/CSS3/JavaScript ÌåÑé

    2014-11-16 20:49

  • Òƶ¯¿ª·¢ÖÐHTML5ÄÜ·ñÌæ´ú±¾µØ³ÌÐò£¿

    Òƶ¯¿ª·¢ÖÐHTML5ÄÜ·ñÌæ´ú±¾µØ³ÌÐò£¿

    2014-11-16 20:49

ÍøÓѵãÆÀ
£