自分で作ったり提供したりするものは、まず自分自身で使ってみろろということです。自分じゃ使わないものなら人はいくらでも無責任にも無思考にもなれる。そういう投げやりな「サービス」やら「プロダクツ」なんて、だれだってイヤだ。自分が作り手と同時に利用者の立場になれば、ちゃんと使えるレベルのものを提供しようとします。

2010年10月4日月曜日

html5曲線の描画

html5で曲線を描画する方法を紹介します。

新しい知識はないので、ただCanvas描画APIの紹介です。

サンプル:
http://html5next.appspot.com/curves1.html


ソース:
<script type="text/javascript">
function formload()
{
 try
 {
  var objCanvas = document.getElementById("cvs01");
  var context = objCanvas.getContext("2d");

  // Save the canvas state and draw the path
  context.save(); 
  context.translate(-10, 350);
  context.beginPath(); 
  // The first curve bends up and right
  context.moveTo(0, 0);
  context.quadraticCurveTo(170, -50, 260, -190); 
  // The second curve continues down and right
  context.quadraticCurveTo(310, -250, 410,-250); 
  // Draw the path in a wide brown stroke
  context.strokeStyle = '#663300';
  context.lineWidth = 20;
  context.stroke(); 
  // Restore the previous canvas state
  context.restore();  
 }
 catch(e)
 {
  alert(e.description);
 }
}
</script>

0 件のコメント:

コメントを投稿

ホームページ