Skip to content

Commit

Permalink
make project 1
Browse files Browse the repository at this point in the history
make project 1
  • Loading branch information
NamJungsook committed Mar 10, 2016
1 parent 2f3e928 commit 9de8dda
Show file tree
Hide file tree
Showing 379 changed files with 44,926 additions and 0 deletions.
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/canvas_physics-master.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/jsLibraryMappings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

436 changes: 436 additions & 0 deletions .idea/workspace.xml

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions Template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<title>Example</title>

<style>
body {
background: #dddddd;
}

#canvas {
background: #ffffff;
border: thin inset #aaaaaa;
}
</style>
</head>

<body>
<canvas id='canvas' width="800" height="600">
Canvas not supported
</canvas>
<script>

</script>
</body>
</html>
101 changes: 101 additions & 0 deletions c01.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<!DOCTYPE html>
<html>
<head>
<title>Example</title>

<style>
body {
background: #dddddd;
}

#canvas {
background: #ffffff;
border: thin inset #aaaaaa;
}
</style>
</head>

<body>
<canvas id='canvas' width="800" height="600">
Canvas not supported
</canvas>
<script>
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");

function Ball() {
this.x = 0;
this.y = 0;

this.radius = 10;
this.color = "red";
this.angle = 0;
}

Ball.prototype = {
draw : function() {
context.save();

context.beginPath();

context.translate(this.x, this.y);
context.rotate(this.angle);
context.arc(0, 0, this.radius, 0, Math.PI * 2);
context.fillRect(0, 0, 30, 5);
context.fillStyle = this.color;
context.fill();

context.restore();
}
}

var ball = new Ball();

var ax = 0;
var ay = 0;
var vx = 0;
var vy = 0;
var friction = 0.98;

ball.x = 100;
ball.y = 100;
//ball.angle = 45 * Math.PI / 180;

canvas.onmousedown = function(e) {
ax = 0.5;
};

canvas.onmouseup = function(e) {
ax = 0;
};


requestAnimationFrame(loop);

function loop() {
context.clearRect(0, 0, canvas.width, canvas.height);

vx += ax;
vy += ay;

vx *= friction;
vy *= friction;

ball.x += vx;
ball.y += vy;

if(ball.x > canvas.width) {
ball.x = 0;
}

render();
requestAnimationFrame(loop);
}

function render() {
ball.draw();
}

</script>
</body>
</html>
106 changes: 106 additions & 0 deletions c02.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<!DOCTYPE html>
<html>
<head>
<title>Example</title>

<style>
body {
background: #dddddd;
}

#canvas {
background: #ffffff;
border: thin inset #aaaaaa;
}
</style>
</head>

<body>
<canvas id='canvas' width="800" height="600">
Canvas not supported
</canvas>
<script>
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");

function windowToCanvas(x, y) {
var bbox = canvas.getBoundingClientRect();

return { x : x - bbox.left, y : y - bbox.top }
}

function Ball() {
this.x = 0;
this.y = 0;

this.radius = 10;
this.color = "red";
this.angle = 0;
}

Ball.prototype = {
draw : function() {
context.save();

context.beginPath();

context.translate(this.x, this.y);
context.rotate(this.angle);
context.arc(0, 0, this.radius, 0, Math.PI * 2);
//context.fillRect(0, 0, 30, 5);
context.fillStyle = this.color;
context.fill();

context.restore();
}
}

var ball = new Ball();

var vx = 0;
var vy = 0;

var targetX = 0;
var targetY = 0;

ball.x = 100;
ball.y = 100;
//ball.angle = 45 * Math.PI / 180;

canvas.onmousedown = function(e) {
var loc = windowToCanvas(e.clientX, e.clientY);

targetX = loc.x;
targetY = loc.y;
}


requestAnimationFrame(loop);

function loop() {
context.clearRect(0, 0, canvas.width, canvas.height);

var dx = targetX - ball.x;
var dy = targetY - ball.y;

vx = dx * 0.2;
vy = dy * 0.2;

ball.x += vx;
ball.y += vy;

if(ball.x > canvas.width) {
ball.x = 0;
}

render();
requestAnimationFrame(loop);
}

function render() {
ball.draw();
}

</script>
</body>
</html>
Loading

0 comments on commit 9de8dda

Please sign in to comment.