KEMBAR78
HTML5って必要? | PDF
ZENER NET WORKS
  2013/02/28
     sanoh
1.HTML5に将来はあるのか?
2.Webアプリ開発
3.開発環境準備
4.開発サンプル
1.HTML5に将来はあるのか?
2.WEBアプリ開発
3.開発環境準備
4.開発サンプル
スマートフォン(iPhone、Android、
WindowsPhone8)
スレートPC(iPad、Kindol)
スマートTV(AppleTV、GoogleTV、
KindolTV)
ディスクトップ(Windows、Mac)
コンシューマ(PS3、XBOX360、WiiU)
携帯ゲーム機(PSP、3DS)
課金
ストア   ストア     ストア
 課金    課金      課金



      ソーシャル
      グラフ     リアル
              グラフ   利益

利益

       利益
              利益
ブラウザで
 動作する
コンテンツ
チッリなコンテンツ

Flash? VS HTML5?
1.HTML5に将来はあるのか?
2.Webアプリ開発
3.開発環境準備
4.開発サンプル
FLASH               Java          Silverlight


HTML5               Ajax                CSS

          JavaScrpt(JQuery,Json・・・)


                    HTML


       HTTP                      XML


Perl           PHP(Cake,Zend)     C#(ASP・・)


MySQL             SQL Azure            Postgre

Linux             クラウド(Amazon,Azure・・・・)
HTML5

        JavaScrpt


          HTML
Canvas
SVG
Audio
Video
WebSocket
WebWorker
WegStorage
WebGL
Desktop                     iPhone          Android2.3
            IE9   FireFox   Chrome   Safari   Safari   Chrome   標準   FireFox
                  15.0.1     21.0    5.1.7     5.1       12           15.0.1

Canvas      ○       ○        ○        ○        ○        ○       ○      ○
SVG         ○       ○        ○        ○        ○        ○       ○      ○
Audio       ○       ○        ○        ○        ○        ○       ○      ○
Video       ○       ○        ○        ○        ○        ○       ○      ○
WebSocket   X       ○        ○        ○        ○        ○       X      ○
WebWorker   X       ○        ○        ○        ○        ○       X      ○
WebStrage   ○       ○        ○        ○         -        -      -      -
WebGL       X       X        ○         X        X        X      X      ○
1.HTML5に将来はあるのか?
2.Webアプリ開発
3.開発環境準備
4.開発サンプル
3.1 デバッグ環境
3.2 ローカルサーバ環境
3.3 環境の選定
IE9
F12
Firefox
Firebug(エクステンション)
Safari
Web   Inspector
Chrome
 Chromeデベロッパーツール
VisualStudio2010 / WebMatrix2
XAMPP
VirtualPC
VMware
Azure
IIS
Apache
HTML5                HTML5

 JavaScript(JQuery)   JavaScript(JQuery)



Apache      CakePHP    IIS          MVC-3、4


              PHP                   ASP.NET

             MySQL            WindowsServer
1.HTML5に将来はあるのか?
2.Webアプリ開発
3.開発環境準備
4.開発サンプル
4.1   表示
4.2   動きのある表示
4.3   色加算
4.4   パフォーマンス
4.5   Lib化
4.6   入力
4.7   ブラウザ互換
4.8   ページ遷移
4.9   バグの出にくいソース?
HTMK5
http://ie.microsoft.com/testdrive/


http://worldsbiggestpacman.com/play/#-7,6
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8"/>
<title>Sample001.html</title>

<script>
function draw() {
    var canvas = document.getElementById("canvas1");
    var c = canvas.getContext("2d");
}
</script>

</head>
<body onload="draw()">
<canvas id="canvas1" width="300" height="300"></canvas>
</body>
</html>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8"/>
<title>Sample002.html</title>

<script>
function draw() {
    var canvas = document.getElementById("canvas1");
    var c = canvas.getContext("2d");
    c.font = "38px 'MS Gothic'";
    c.fillStyle = "#666666";
    c.fillText("こんにちは", 100, 100);
}
</script>

</head>
<body onload="draw()">
<canvas id="canvas1" width="300" height="300"></canvas>
</body>
</html>
:
function draw() {
    var canvas = document.getElementById("canvas1");
    var c = canvas.getContext("2d");

        c.fillStyle = "#0099ff";
        c.fillRect (15, 15, 50, 45);

        c.fillStyle = "rgba(0, 0, 200, 0.5)";
        c.fillRect (30, 30, 50, 45);
}
    :
function draw() {
    var canvas = document.getElementById("canvas1");
    var c = canvas.getContext("2d");

    c.strokeStyle = "#ff9900";
    c.beginPath();
    c.arc(70, 70, 60, 0, Math.PI*2, false);
    c.stroke();
}

function draw() {
    var canvas = document.getElementById("canvas1");
    var c = canvas.getContext("2d");

    c.fillStyle = "#990099";
    c.beginPath();
    c.arc(70, 70, 60, 0, Math.PI*2, false);
    c.fill();
}
function draw() {
    var canvas = document.getElementById("canvas1");
    var c = canvas.getContext("2d");

    c.fillStyle = "#999999";
    c.beginPath();
    c.moveTo(10,10);
    c.lineTo(200,50);
    c.lineTo(100,120);
    c.closePath();
    c.fill();
}
function draw() {
                                                       Onloadなので読み込み終
    var canvas = document.getElementById("canvas1");
    var c = canvas.getContext("2d");
                                                       了してない

    var img = new Image();
    img.src = "img/grand001.png";
    c.drawImage(img, 0, 0);
}
function draw() {
    var canvas = document.getElementById("canvas1");
    var c = canvas.getContext("2d");

    var img = new Image();
    img.src = "img/grand001.png";
    c.drawImage(img, 0, 0, 640, 480);
}
function draw() {
    var canvas = document.getElementById("canvas1");
    var c = canvas.getContext("2d");

    var img = new Image();
    img.src = "img/tree001.png";
    c.drawImage(img, 10, 10, 64, 64, 100, 100, 128, 32);
}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8"/>
<title>Sample002.html</title>
<script>//<![CDATA[

var timerInterval = 25; //25msec
var timer1;
var c;

function draw() {
}

function init(){
    var canvas = document.getElementById("canvas1");
    c = canvas.getContext("2d");

    timer1 = setInterval("draw()", timerInterval);
}

//]]></script>
</head>
<body onload="init()">
<canvas id="canvas1" width=“300" height=“300"></canvas>
</body>
</html>
<script>//<![CDATA[

var   timerInterval = 25; //25msec                         イメージの読み
var   timer1;
var   c;                                                   込み終了を待つ
var   img;

function draw() {
}

function init(){
    var canvas = document.getElementById("canvas1");
    c = canvas.getContext("2d");

      img = new Image();
      img.src = "img/grand001.png";

      img.onload = function(){
          draw();
          timer1 = setInterval("draw()", timerInterval);
      }
}

//]]></script>
<script>//<![CDATA[

var timerInterval = 25; //25msec
var timer1;

var c;
var img;

var angle = 3;
function draw() {
  c.fillStyle = "#c0c0c0";
  c.fillRect (0, 0, 300, 300);

    c.rotate(angle * Math.PI / 180);
    c.drawImage(img, 0, 0);
}

function init(){
    var canvas = document.getElementById("canvas1");
    c = canvas.getContext("2d");

     img = new Image();
     img.src = "img/grand001.png";
     img.onload = function(){
         draw();
         timer1 = setInterval("draw()", timerInterval);
      }
}

//]]></script>
<script>                                                     function Draw(){
Var draw;                                                        draw.clearRect(0, 0, windWidth, windHeight);
Var img;
                                                                 draw.fillStyle         = "#000000";
Var partX;
                                                                 draw.fillRect(0, 0, windWidth, windHeight);
Var partY;
Var partAX;
Var partAY;                                                      draw.globalCompositeOperation        = "lighter";
                                                                 for( var i = 0 ; i < partX.length ; i++ ){
function init() {                                                    draw.drawImage(img, partX[i], partY[i]);
    var max = 60;                                                    //-----------------------------------------
    var outputcanvas = document.getElementById("canvas1");           partX[i]           += partAX[ i ];
    var ang;                                                         if( partX[i] < -128 )
                                                                     partAX[i]          = -partAX[i];
    per = new Performance();                                         if( partX[i] > windWidth-128 )
    draw = outputcanvas.getContext("2d");                                partAX[i]      = -partAX[i];
    setInterval(“Draw()", 16.7);
                                                                     partY[i]           += partAY[ i ];
    windWidth = outputcanvas.width;
    windHeight = outputcanvas.height;                                if( partY[i] < -128 )
    //--------------------------------------                             partAY[i]      = -partAY[i];
    img = new Image();                                               if( partY[i] > windHeight-128 )
    img.src = "../img/ball.png";                                         partAY[i]      = -partAY[i];
    //--------------------------------------                     }
    partX = Array( max );                                        draw.globalCompositeOperation        = "source-over";
    partY = Array( max );
    partAX = Array( max );                                   }
    partAY = Array( max );
    for( var i = 0 ; i < max ; i++ ){                        </script>
        partX[i] = Math.random() * (windWidth-128);
                                                             </head>
        partY[i] = Math.random() * (windHeight-128);
                                                             <body onload="init()">
        Ang   = Math.random() * Math.PI * 2;
        partAX[i] = Math.sin( ang );                         <canvas id="canvas1" width="640" height="400"></canvas>
        partAY[i] = Math.sin( ang );                         </body>
    }                                                        </html>
}
<script language="JavaScript“
                    src="./Performance.js"></script>

                                                       function     Performance(){
                                                           this.startTime = new Date();
var            per;                                        this.endTime = new Date();
                                                           this.fpsTime = 0;
function init() {
                                                           this.Start = function(){
      per      = new Performance();                            this.startTime = new Date();
                                                               this.fpsTime = this.startTime - this.endTime;
                                                               this.endTime = this.startTime;
                                                           }
function Draw(){                                           this.GetFPS = function( fr ){
    var      fps;                                              return Math.min(Math.floor(1000/this.fpsTime), fr )
    per.Start();                                           }
    fps      = per.GetFPS(60);                         }

             : 描画

      draw.font = "128px 'MS Gothic'";
      draw.fillStyle = "#ff0000";
      draw.fillText("FPS="+fps, 100, 150);
}
Var     Glib        = function(name){                            this.DrawPolygon3 = function(   x1, y1, x2, y2, x3, y3 ){
      this.canvas = document.getElementById(name);                   this.g.beginPath();
      this.g        = this.canvas.getContext("2d");                  this.g.moveTo(x1,y1);
      this.canvasW = this.canvas.width;                              this.g.lineTo(x2,y2);
      this.canvasH = this.canvas.height;                             this.g.lineTo(x3,y3);
      this.g.lineWidth = 1;                                          this.g.closePath();
      this.Cls = function() {                                        this.g.fill();
           this.g.clearRect(0, 0, this.canvasW, this.canvasH);   }
           this.Push();                                          this.DrawPolygon3 = function(   x1, y1, x2, y2, x3, y3, s ){
      }                                                              this.g.fillStyle = s;
      this.Cls = function(s) {                                       this.g.beginPath();
           this.g.fillStyle = s;                                     this.g.moveTo(x1,y1);
           this.g.fillRect(0, 0, this.canvasW, this.canvasH);        this.g.lineTo(x2,y2);
           this.Push();                                              this.g.lineTo(x3,y3);
      }                                                              this.g.closePath();
      this.Draw = function() {                                       this.g.fill();
           this.Pop();                                           }
      }                                                          this.DrawPolygon4 = function(   x1, y1, x2, y2, x3, y3, x4, y4 ){
      this.SetColor = function( s ){                                 this.g.beginPath();
           this.g.fillStyle = s;                                     this.g.moveTo(x1,y1);
      }                                                              this.g.lineTo(x2,y2);
      this.DrawBox = function( x, y, w, h ){                         this.g.lineTo(x3,y3);
           this.g.fillRect ( x, y, w, h);                            this.g.lineTo(x4,y4);
      }                                                              this.g.closePath();
      this.DrawBox = function( x, y, w, h, s ){                      this.g.fill();
           this.g.fillStyle = s;                                 }
           this.g.fillRect ( x, y, w, h);                        this.DrawPolygon4 = function(   x1, y1, x2, y2, x3, y3, x4, y4, s ){
      }                                                              this.g.fillStyle = s;
      this.DrawLine = function( x1, y1, x2, y2 ){                    this.g.beginPath();
           this.g.lineWidth = 2;                                     this.g.moveTo(x1,y1);
           this.g.beginPath();                                       this.g.lineTo(x2,y2);
           this.g.moveTo(x1,y1);                                     this.g.lineTo(x3,y3);
           this.g.lineTo(x2,y2);                                     this.g.lineTo(x4,y4);
           this.g.closePath();                                       this.g.closePath();
           this.g.stroke();                                          this.g.fill();
      }                                                          }
      this.DrawLine = function( x1, y1, x2, y2, s ){
           this.g.strokeStyle = s;
           this.g.beginPath();
           this.g.moveTo(x1,y1);
           this.g.lineTo(x2,y2);
           this.g.closePath();
           this.g.stroke();
      }
this.DrawImage = function( img, x, y ){
        this.g.drawImage(img, x, y);
    }
    this.DrawImage4 = function( img, x, y, w, h ){
        this.g.drawImage(img, x, y, w, h);
    }
    this.DrawImageObj = function( img, sx, sy, sw, sh ){
        this.g.drawImage(img, sx, sy, sw, sh, 0, 0, sw, sh);
    }
    this.DrawImage6 = function( img, sx, sy, sw, sh, x, y){
        this.g.drawImage(img, sx, sy, sw, sh, x, y, sw, sh);
    }
    this.DrawImage8 = function( img, sx, sy, sw, sh, x, y, w, h ){
        this.g.drawImage(img, sx, sy, sw, sh, x, y, w, h);
    }
    this.Pos     = function( x, y ){
        this.g.translate( x, y );
    }
    this.Ang     = function( a ){
        this.g.rotate( a )
    }
    this.Push    = function(){
        this.g.save();
    }
    this.Pop     = function(){
        this.g.restore();
    }
};
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
                                                          Lib化して楽しよう
<meta charset="utf-8"/>
<title>Test</title>

<script language="JavaScript" src="./Glib.js"></script>
<script>//<![CDATA[
var timerInterval = 16.7;
Var g;
var imgTmy;

function draw() {
    g.Cls("#0000ff");
    g.DrawImage( imgTmy, 40, 40);
    g.DrawLine( 0, 0, 250, 200, "#00ffff");
    g.Draw();
}
function init(){
    g            = new Glib( "canvas1");
    setInterval("draw()", timerInterval);

    imgTmy = new Image();
    imgTmy.src = "./grand001.png";
}

//]]></script>
</head>
<body onload="init()">
<canvas id="canvas1" width="300" height="300"></canvas>
</body>
</html>
SmileBoom Petit Developer
スマイルブーム

Enchant.js
Ubiquitous Entertainment Inc

FLASH
Unity
<script>//<![CDATA[
window.document.onkeydown = click_down;   イベントでキャッチ
window.document.onkeyup = click_up;

function click_down()   {
    if( event.keyCode   == 37 )
        my_add_x        = 256*2;
    if( event.keyCode   == 39 )
        my_add_x        =-256*2;
}

function click_up() {
    if( event.keyCode   ==   37 )
        my_add_x        =    0;
    if( event.keyCode   ==   39 )
        my_addx         =    0;
}

//]]></script>
function   myGetBrowser(){
    myOP   = (navigator.userAgent.indexOf("Opera",0) != -1)?1:0; //OP
    myN6   = document.getElementById; // N6 or IE
    myIE
    myN4
           = document.all;
           = document.layers;
                                       // IE
                                       // N4
                                                                        昔はブラウザ依存を
    if (myOP){                           // OP?
        document.onmousemove = myMoveOP;
    }else if (myIE){                     // IE?
                                                                        気負つける必要が
        document.onmousemove = myMoveIE;
    }else if (myN6){                     // N6?
        window.addEventListener("mousemove",myMoveN6,true);
    }else if (myN4){                     // N4?
                                                                        あった。
        window.captureEvents(Event.MOUSEMOVE);
        window.onmousemove = myMoveN4;
    }
    document.addEventListener("touchstart", touchHandler, false);
    document.addEventListener("touchmove", touchHandler, false);
    document.addEventListener("touchend", touchHandler, false);
}

function touchHandler(event) {
    Xpos = event.touches[0].pageX;
    Ypos = event.touches[0].pageY;
    Catch();
}
function myMoveOP(){ // OPŃ}EX
    Xpos = window.event.clientX;
    Ypos = window.event.clientY;
    Catch();
}
function myMoveN6(myEvent){ // N6Ń}EX
    Xpos = myEvent.clientX + window.pageXOffset;
    Ypos = myEvent.clientY + window.pageYOffset;
    Catch();
}
function myMoveIE(){ // IEŃ}EX
    Xpos = window.event.clientX + document.body.scrollLeft;
    Ypos = window.event.clientY + document.body.scrollTop;
    Catch();
}
function myMoveN4(myEvent){ // N4Ń}EX
    Xpos = myEvent.x;
    Ypos = myEvent.y;
    Catch();
}
JQuery




    Googleを使う
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
</script>
ページ切り替え     中身切り替え

          <body>
           <div id="MainFrame">
          </body>
          </html>
var命令による変数宣言は省略しない
  比較演算子は「==」ではなく「===」を
  配列の生成にはリテラルを使う
  中括弧は省略しない
  文の途中の改行に要注意

http://blog.livedoor.jp/ryo511-web/archives/13577395.html
動かして楽しもう
JavaScript

Flash
Flash11
http://nissan-stagejuk3d.com/



  WebGL
https://code.google.com/p/webglsamples/
やっておいて損はない
質問
Mail: sanoh@zener.co.jp
Blog: http://d.hatena.ne.jp/sanoh/ (ポリゴン魂)
Facebook: 佐野 浩章
Twitter: sanoh00

HTML5って必要?

  • 1.
    ZENER NET WORKS 2013/02/28 sanoh
  • 2.
  • 4.
  • 5.
  • 9.
    課金 ストア ストア ストア 課金 課金 課金 ソーシャル グラフ リアル グラフ 利益 利益 利益 利益
  • 10.
  • 11.
  • 12.
  • 13.
    FLASH Java Silverlight HTML5 Ajax CSS JavaScrpt(JQuery,Json・・・) HTML HTTP XML Perl PHP(Cake,Zend) C#(ASP・・) MySQL SQL Azure Postgre Linux クラウド(Amazon,Azure・・・・)
  • 14.
    HTML5 JavaScrpt HTML
  • 15.
  • 16.
    Desktop iPhone Android2.3 IE9 FireFox Chrome Safari Safari Chrome 標準 FireFox 15.0.1 21.0 5.1.7 5.1 12 15.0.1 Canvas ○ ○ ○ ○ ○ ○ ○ ○ SVG ○ ○ ○ ○ ○ ○ ○ ○ Audio ○ ○ ○ ○ ○ ○ ○ ○ Video ○ ○ ○ ○ ○ ○ ○ ○ WebSocket X ○ ○ ○ ○ ○ X ○ WebWorker X ○ ○ ○ ○ ○ X ○ WebStrage ○ ○ ○ ○ - - - - WebGL X X ○ X X X X ○
  • 17.
  • 18.
  • 19.
    IE9 F12 Firefox Firebug(エクステンション) Safari Web Inspector Chrome Chromeデベロッパーツール VisualStudio2010 / WebMatrix2
  • 20.
  • 21.
    HTML5 HTML5 JavaScript(JQuery) JavaScript(JQuery) Apache CakePHP IIS MVC-3、4 PHP ASP.NET MySQL WindowsServer
  • 22.
  • 23.
    4.1 表示 4.2 動きのある表示 4.3 色加算 4.4 パフォーマンス 4.5 Lib化 4.6 入力 4.7 ブラウザ互換 4.8 ページ遷移 4.9 バグの出にくいソース?
  • 24.
  • 25.
    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <metacharset="utf-8"/> <title>Sample001.html</title> <script> function draw() { var canvas = document.getElementById("canvas1"); var c = canvas.getContext("2d"); } </script> </head> <body onload="draw()"> <canvas id="canvas1" width="300" height="300"></canvas> </body> </html>
  • 26.
    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <metacharset="utf-8"/> <title>Sample002.html</title> <script> function draw() { var canvas = document.getElementById("canvas1"); var c = canvas.getContext("2d"); c.font = "38px 'MS Gothic'"; c.fillStyle = "#666666"; c.fillText("こんにちは", 100, 100); } </script> </head> <body onload="draw()"> <canvas id="canvas1" width="300" height="300"></canvas> </body> </html>
  • 27.
    : function draw() { var canvas = document.getElementById("canvas1"); var c = canvas.getContext("2d"); c.fillStyle = "#0099ff"; c.fillRect (15, 15, 50, 45); c.fillStyle = "rgba(0, 0, 200, 0.5)"; c.fillRect (30, 30, 50, 45); } :
  • 28.
    function draw() { var canvas = document.getElementById("canvas1"); var c = canvas.getContext("2d"); c.strokeStyle = "#ff9900"; c.beginPath(); c.arc(70, 70, 60, 0, Math.PI*2, false); c.stroke(); } function draw() { var canvas = document.getElementById("canvas1"); var c = canvas.getContext("2d"); c.fillStyle = "#990099"; c.beginPath(); c.arc(70, 70, 60, 0, Math.PI*2, false); c.fill(); }
  • 29.
    function draw() { var canvas = document.getElementById("canvas1"); var c = canvas.getContext("2d"); c.fillStyle = "#999999"; c.beginPath(); c.moveTo(10,10); c.lineTo(200,50); c.lineTo(100,120); c.closePath(); c.fill(); }
  • 30.
    function draw() { Onloadなので読み込み終 var canvas = document.getElementById("canvas1"); var c = canvas.getContext("2d"); 了してない var img = new Image(); img.src = "img/grand001.png"; c.drawImage(img, 0, 0); }
  • 31.
    function draw() { var canvas = document.getElementById("canvas1"); var c = canvas.getContext("2d"); var img = new Image(); img.src = "img/grand001.png"; c.drawImage(img, 0, 0, 640, 480); }
  • 32.
    function draw() { var canvas = document.getElementById("canvas1"); var c = canvas.getContext("2d"); var img = new Image(); img.src = "img/tree001.png"; c.drawImage(img, 10, 10, 64, 64, 100, 100, 128, 32); }
  • 33.
    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <metacharset="utf-8"/> <title>Sample002.html</title> <script>//<![CDATA[ var timerInterval = 25; //25msec var timer1; var c; function draw() { } function init(){ var canvas = document.getElementById("canvas1"); c = canvas.getContext("2d"); timer1 = setInterval("draw()", timerInterval); } //]]></script> </head> <body onload="init()"> <canvas id="canvas1" width=“300" height=“300"></canvas> </body> </html>
  • 34.
    <script>//<![CDATA[ var timerInterval = 25; //25msec イメージの読み var timer1; var c; 込み終了を待つ var img; function draw() { } function init(){ var canvas = document.getElementById("canvas1"); c = canvas.getContext("2d"); img = new Image(); img.src = "img/grand001.png"; img.onload = function(){ draw(); timer1 = setInterval("draw()", timerInterval); } } //]]></script>
  • 35.
    <script>//<![CDATA[ var timerInterval =25; //25msec var timer1; var c; var img; var angle = 3; function draw() { c.fillStyle = "#c0c0c0"; c.fillRect (0, 0, 300, 300); c.rotate(angle * Math.PI / 180); c.drawImage(img, 0, 0); } function init(){ var canvas = document.getElementById("canvas1"); c = canvas.getContext("2d"); img = new Image(); img.src = "img/grand001.png"; img.onload = function(){ draw(); timer1 = setInterval("draw()", timerInterval); } } //]]></script>
  • 37.
    <script> function Draw(){ Var draw; draw.clearRect(0, 0, windWidth, windHeight); Var img; draw.fillStyle = "#000000"; Var partX; draw.fillRect(0, 0, windWidth, windHeight); Var partY; Var partAX; Var partAY; draw.globalCompositeOperation = "lighter"; for( var i = 0 ; i < partX.length ; i++ ){ function init() { draw.drawImage(img, partX[i], partY[i]); var max = 60; //----------------------------------------- var outputcanvas = document.getElementById("canvas1"); partX[i] += partAX[ i ]; var ang; if( partX[i] < -128 ) partAX[i] = -partAX[i]; per = new Performance(); if( partX[i] > windWidth-128 ) draw = outputcanvas.getContext("2d"); partAX[i] = -partAX[i]; setInterval(“Draw()", 16.7); partY[i] += partAY[ i ]; windWidth = outputcanvas.width; windHeight = outputcanvas.height; if( partY[i] < -128 ) //-------------------------------------- partAY[i] = -partAY[i]; img = new Image(); if( partY[i] > windHeight-128 ) img.src = "../img/ball.png"; partAY[i] = -partAY[i]; //-------------------------------------- } partX = Array( max ); draw.globalCompositeOperation = "source-over"; partY = Array( max ); partAX = Array( max ); } partAY = Array( max ); for( var i = 0 ; i < max ; i++ ){ </script> partX[i] = Math.random() * (windWidth-128); </head> partY[i] = Math.random() * (windHeight-128); <body onload="init()"> Ang = Math.random() * Math.PI * 2; partAX[i] = Math.sin( ang ); <canvas id="canvas1" width="640" height="400"></canvas> partAY[i] = Math.sin( ang ); </body> } </html> }
  • 39.
    <script language="JavaScript“ src="./Performance.js"></script> function Performance(){ this.startTime = new Date(); var per; this.endTime = new Date(); this.fpsTime = 0; function init() { this.Start = function(){ per = new Performance(); this.startTime = new Date(); this.fpsTime = this.startTime - this.endTime; this.endTime = this.startTime; } function Draw(){ this.GetFPS = function( fr ){ var fps; return Math.min(Math.floor(1000/this.fpsTime), fr ) per.Start(); } fps = per.GetFPS(60); } : 描画 draw.font = "128px 'MS Gothic'"; draw.fillStyle = "#ff0000"; draw.fillText("FPS="+fps, 100, 150); }
  • 41.
    Var Glib = function(name){ this.DrawPolygon3 = function( x1, y1, x2, y2, x3, y3 ){ this.canvas = document.getElementById(name); this.g.beginPath(); this.g = this.canvas.getContext("2d"); this.g.moveTo(x1,y1); this.canvasW = this.canvas.width; this.g.lineTo(x2,y2); this.canvasH = this.canvas.height; this.g.lineTo(x3,y3); this.g.lineWidth = 1; this.g.closePath(); this.Cls = function() { this.g.fill(); this.g.clearRect(0, 0, this.canvasW, this.canvasH); } this.Push(); this.DrawPolygon3 = function( x1, y1, x2, y2, x3, y3, s ){ } this.g.fillStyle = s; this.Cls = function(s) { this.g.beginPath(); this.g.fillStyle = s; this.g.moveTo(x1,y1); this.g.fillRect(0, 0, this.canvasW, this.canvasH); this.g.lineTo(x2,y2); this.Push(); this.g.lineTo(x3,y3); } this.g.closePath(); this.Draw = function() { this.g.fill(); this.Pop(); } } this.DrawPolygon4 = function( x1, y1, x2, y2, x3, y3, x4, y4 ){ this.SetColor = function( s ){ this.g.beginPath(); this.g.fillStyle = s; this.g.moveTo(x1,y1); } this.g.lineTo(x2,y2); this.DrawBox = function( x, y, w, h ){ this.g.lineTo(x3,y3); this.g.fillRect ( x, y, w, h); this.g.lineTo(x4,y4); } this.g.closePath(); this.DrawBox = function( x, y, w, h, s ){ this.g.fill(); this.g.fillStyle = s; } this.g.fillRect ( x, y, w, h); this.DrawPolygon4 = function( x1, y1, x2, y2, x3, y3, x4, y4, s ){ } this.g.fillStyle = s; this.DrawLine = function( x1, y1, x2, y2 ){ this.g.beginPath(); this.g.lineWidth = 2; this.g.moveTo(x1,y1); this.g.beginPath(); this.g.lineTo(x2,y2); this.g.moveTo(x1,y1); this.g.lineTo(x3,y3); this.g.lineTo(x2,y2); this.g.lineTo(x4,y4); this.g.closePath(); this.g.closePath(); this.g.stroke(); this.g.fill(); } } this.DrawLine = function( x1, y1, x2, y2, s ){ this.g.strokeStyle = s; this.g.beginPath(); this.g.moveTo(x1,y1); this.g.lineTo(x2,y2); this.g.closePath(); this.g.stroke(); }
  • 42.
    this.DrawImage = function(img, x, y ){ this.g.drawImage(img, x, y); } this.DrawImage4 = function( img, x, y, w, h ){ this.g.drawImage(img, x, y, w, h); } this.DrawImageObj = function( img, sx, sy, sw, sh ){ this.g.drawImage(img, sx, sy, sw, sh, 0, 0, sw, sh); } this.DrawImage6 = function( img, sx, sy, sw, sh, x, y){ this.g.drawImage(img, sx, sy, sw, sh, x, y, sw, sh); } this.DrawImage8 = function( img, sx, sy, sw, sh, x, y, w, h ){ this.g.drawImage(img, sx, sy, sw, sh, x, y, w, h); } this.Pos = function( x, y ){ this.g.translate( x, y ); } this.Ang = function( a ){ this.g.rotate( a ) } this.Push = function(){ this.g.save(); } this.Pop = function(){ this.g.restore(); } };
  • 43.
    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> Lib化して楽しよう <meta charset="utf-8"/> <title>Test</title> <script language="JavaScript" src="./Glib.js"></script> <script>//<![CDATA[ var timerInterval = 16.7; Var g; var imgTmy; function draw() { g.Cls("#0000ff"); g.DrawImage( imgTmy, 40, 40); g.DrawLine( 0, 0, 250, 200, "#00ffff"); g.Draw(); } function init(){ g = new Glib( "canvas1"); setInterval("draw()", timerInterval); imgTmy = new Image(); imgTmy.src = "./grand001.png"; } //]]></script> </head> <body onload="init()"> <canvas id="canvas1" width="300" height="300"></canvas> </body> </html>
  • 45.
  • 46.
    <script>//<![CDATA[ window.document.onkeydown = click_down; イベントでキャッチ window.document.onkeyup = click_up; function click_down() { if( event.keyCode == 37 ) my_add_x = 256*2; if( event.keyCode == 39 ) my_add_x =-256*2; } function click_up() { if( event.keyCode == 37 ) my_add_x = 0; if( event.keyCode == 39 ) my_addx = 0; } //]]></script>
  • 47.
    function myGetBrowser(){ myOP = (navigator.userAgent.indexOf("Opera",0) != -1)?1:0; //OP myN6 = document.getElementById; // N6 or IE myIE myN4 = document.all; = document.layers; // IE // N4 昔はブラウザ依存を if (myOP){ // OP? document.onmousemove = myMoveOP; }else if (myIE){ // IE? 気負つける必要が document.onmousemove = myMoveIE; }else if (myN6){ // N6? window.addEventListener("mousemove",myMoveN6,true); }else if (myN4){ // N4? あった。 window.captureEvents(Event.MOUSEMOVE); window.onmousemove = myMoveN4; } document.addEventListener("touchstart", touchHandler, false); document.addEventListener("touchmove", touchHandler, false); document.addEventListener("touchend", touchHandler, false); } function touchHandler(event) { Xpos = event.touches[0].pageX; Ypos = event.touches[0].pageY; Catch(); } function myMoveOP(){ // OPŃ}EX Xpos = window.event.clientX; Ypos = window.event.clientY; Catch(); } function myMoveN6(myEvent){ // N6Ń}EX Xpos = myEvent.clientX + window.pageXOffset; Ypos = myEvent.clientY + window.pageYOffset; Catch(); } function myMoveIE(){ // IEŃ}EX Xpos = window.event.clientX + document.body.scrollLeft; Ypos = window.event.clientY + document.body.scrollTop; Catch(); } function myMoveN4(myEvent){ // N4Ń}EX Xpos = myEvent.x; Ypos = myEvent.y; Catch(); }
  • 48.
    JQuery Googleを使う <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"> </script>
  • 49.
    ページ切り替え 中身切り替え <body> <div id="MainFrame"> </body> </html>
  • 50.
    var命令による変数宣言は省略しない 比較演算子は「==」ではなく「===」を 配列の生成にはリテラルを使う 中括弧は省略しない 文の途中の改行に要注意 http://blog.livedoor.jp/ryo511-web/archives/13577395.html
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
    Mail: sanoh@zener.co.jp Blog: http://d.hatena.ne.jp/sanoh/(ポリゴン魂) Facebook: 佐野 浩章 Twitter: sanoh00