Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
phenomLi committed Dec 26, 2019
0 parents commit e3ea3cd
Show file tree
Hide file tree
Showing 39 changed files with 4,334 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Torque

75 changes: 75 additions & 0 deletions creator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@



class Creator {
constructor(container, width, height, opt) {
this.zr = zrender.init(document.getElementById(container)),
this.t = new Torque(width, height, opt || {});
}

circle(x, y, r, opt) {
let circle = Torque.body.Circle(x, y, r, opt),
circleShape = new zrender.Circle({
shape: {
cx: x,
cy: y,
r: r
},
style: {
fill: opt.color,
stroke: '#333',
//text: circle.id
}
});

circle.setRender(function(body) {
circleShape.attr('origin', [body.position.x, body.position.y]);
circleShape.attr('rotation', -body.rotation);
circleShape.attr('shape', {
cx: body.origin.x,
cy: body.origin.y
});
});

circle.setData(circleShape);
this.t.append(circle);
this.zr.add(circleShape);
}

rect(x, y, w, h, opt) {
let rect = Torque.body.Rect(x, y, w, h, opt),
rectShape = new zrender.Rect({
origin: [rect.position.x, rect.position.y],
shape: {
x: x,
y: y,
width: w,
height: h
},
style: {
fill: opt.color,
stroke: '#333',
text: rect.id
}
});

rect.setRender(function(body) {
rectShape.attr('origin', [body.position.x, body.position.y]);
rectShape.attr('rotation', -body.rotation);
rectShape.attr('shape', {
x: body.origin.x,
y: body.origin.y
});
});

rect.setData(rectShape);
this.t.append(rect);
this.zr.add(rectShape);
}

polygon() {

}
}

Creator.v = Torque.math.vector;
60 changes: 60 additions & 0 deletions demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>

* {
margin: 0;
padding: 0;
}

#canvas {
width: 1000px;
height: 600px;
background-color: #eee;
}

</style>
</head>
<body>


<div id="canvas"></div>

<button id="start">开始</button>
<button id="pause">暂停</button>


<div id="mouse"></div>

<script src="./lib/zrender.min.js"></script>
<script src="./dist/torque.js"></script>
<script src="./creator.js"></script>
<script src="./test.js"></script>
<script>

document.getElementById('start').addEventListener('click', () => {
creator.t.start();
});

document.getElementById('pause').addEventListener('click', () => {
creator.t.pause();
});




let mouse = document.getElementById('mouse');

document.addEventListener('mousemove', e => {
mouse.innerText = 'x:' + e.clientX + '; y:' + e.clientY;
});


</script>
</body>
</html>
1 change: 1 addition & 0 deletions dist/torque.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/zrender.min.js

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"dependencies": {
"awesome-typescript-loader": "^5.2.1",
"typescript": "^3.2.2",
"webpack": "^4.28.2",
"zrender": "^4.0.7"
},
"devDependencies": {
"webpack-cli": "^3.2.3"
}
}
Loading

0 comments on commit e3ea3cd

Please sign in to comment.