<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=320, user-scalable=no" />
<title>Canvas Test</title>
</head>
<body>
<canvas id="myCanvas" width="300" height="300"></canvas>
<script type="text/javascript">
// 캔버스 객체 취득
var canvas = document.getElementById("myCanvas");
// 이미지 컨텍스트 취득
var ctx = canvas.getContext("2d");
canvas.onmousedown = function(e) {
//alert("클릭!");
//터치한 좌표 취득
var x = e.x;
var y = e.y;
//alert("(" + x + "," + y + ")");
var r = Math.random() * 10 + 5; //5~15사이의 난수
//패스설정
ctx.beginPath();
ctx.moveTo(x, y);
ctx.lineTo(x, y+r);
ctx.lineTo(x+r, y+r);
ctx.lineTo(x, y);
//그리자!
ctx.strokeStyle="red";
ctx.stroke();
};
</script>
</body>
</html>
'html5' 카테고리의 다른 글
| canvas #6 원뿔 그리기 (0) | 2013.02.21 |
|---|---|
| canvas #5 랜덤하게 그리기 (0) | 2013.02.21 |
| canvas #4 아크 그리기 (0) | 2013.02.20 |
| canvas #2 삼각형 그리기 (0) | 2013.02.20 |
| canvas #1 사각형 그리기 (0) | 2013.02.20 |