Skip to content

Commit 727bc04

Browse files
author
a-jie
committed
upload proton 1.0.0
0 parents  commit 727bc04

File tree

234 files changed

+32715
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

234 files changed

+32715
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

build/.DS_Store

6 KB
Binary file not shown.

build/proton-1.0.0.js

Lines changed: 4143 additions & 0 deletions
Large diffs are not rendered by default.

build/proton-1.0.0.min.js

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/.DS_Store

12 KB
Binary file not shown.

example/behaviour/.DS_Store

12 KB
Binary file not shown.
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
<head>
4+
<title>behaviour-attraction1</title>
5+
<meta charset="utf-8">
6+
<style type="text/css">
7+
body {
8+
background-color: #333333;
9+
margin: 0px;
10+
overflow: hidden;
11+
-moz-user-select: none;
12+
-webkit-user-select: none;
13+
-ms-user-select: none;
14+
-khtml-user-select: none;
15+
user-select: none;
16+
}
17+
#testCanvas {
18+
background: #000;
19+
}
20+
</style>
21+
</head>
22+
<body>
23+
<canvas id="testCanvas"></canvas>
24+
<script src="../../lib/stats.min.js"></script>
25+
<script src="../../../build/proton-1.0.0.min.js"></script>
26+
<script>
27+
var canvas;
28+
var context;
29+
var proton;
30+
var renderer;
31+
var emitter;
32+
var stats;
33+
var _mousedown = false;
34+
var mouseObj;
35+
var attractionBehaviour, crossZoneBehaviour;
36+
37+
Main();
38+
39+
function Main() {
40+
canvas = document.getElementById("testCanvas");
41+
canvas.width = window.innerWidth;
42+
canvas.height = window.innerHeight;
43+
context = canvas.getContext('2d');
44+
addStats();
45+
46+
createProton();
47+
createRenderer();
48+
tick();
49+
canvas.addEventListener('mousedown', mousedownHandler, false);
50+
canvas.addEventListener('mouseup', mouseupHandler, false);
51+
canvas.addEventListener('mousemove', mousemoveHandler, false);
52+
window.onresize = function(e) {
53+
canvas.width = window.innerWidth;
54+
canvas.height = window.innerHeight;
55+
crossZoneBehaviour.reset(new Proton.RectZone(0, 0, canvas.width, canvas.height), 'cross');
56+
}
57+
}
58+
59+
function addStats() {
60+
stats = new Stats();
61+
stats.setMode(2);
62+
stats.domElement.style.position = 'absolute';
63+
stats.domElement.style.left = '0px';
64+
stats.domElement.style.top = '0px';
65+
document.body.appendChild(stats.domElement);
66+
}
67+
68+
function createProton() {
69+
proton = new Proton;
70+
emitter = new Proton.Emitter();
71+
emitter.damping = 0.008;
72+
emitter.rate = new Proton.Rate(250);
73+
emitter.addInitialize(new Proton.Mass(1));
74+
emitter.addInitialize(new Proton.Radius(4));
75+
emitter.addInitialize(new Proton.Velocity(new Proton.Span(1.5), new Proton.Span(0, 360), 'polar'));
76+
77+
mouseObj = {
78+
x : 1003 / 2,
79+
y : 610 / 2
80+
};
81+
attractionBehaviour = new Proton.Attraction(mouseObj, 0, 0);
82+
crossZoneBehaviour = new Proton.CrossZone(new Proton.RectZone(0, 0, canvas.width, canvas.height), 'cross');
83+
emitter.addBehaviour(new Proton.Color('random'));
84+
emitter.addBehaviour(attractionBehaviour, crossZoneBehaviour);
85+
emitter.addBehaviour(new Proton.RandomDrift(10, 10, .05));
86+
emitter.p.x = canvas.width / 2;
87+
emitter.p.y = canvas.height / 2;
88+
emitter.emit('once');
89+
proton.addEmitter(emitter);
90+
}
91+
92+
function mousedownHandler(e) {
93+
_mousedown = true;
94+
attractionBehaviour.reset(mouseObj, 10, 1200);
95+
mousemoveHandler(e);
96+
}
97+
98+
function mousemoveHandler(e) {
99+
if (_mousedown) {
100+
var _x, _y;
101+
if (e.layerX || e.layerX == 0) {
102+
_x = e.layerX;
103+
_y = e.layerY;
104+
} else if (e.offsetX || e.offsetX == 0) {
105+
_x = e.offsetX;
106+
_y = e.offsetY;
107+
}
108+
109+
mouseObj.x = _x;
110+
mouseObj.y = _y;
111+
}
112+
}
113+
114+
function mouseupHandler(e) {
115+
_mousedown = false;
116+
attractionBehaviour.reset(mouseObj, 0, 0);
117+
}
118+
119+
function createRenderer() {
120+
renderer = new Proton.Renderer('other', proton);
121+
renderer.onProtonUpdate = function() {
122+
context.fillStyle = "rgba(0, 0, 0, 0.02)";
123+
context.fillRect(0, 0, canvas.width, canvas.height);
124+
};
125+
126+
renderer.onParticleUpdate = function(particle) {
127+
context.beginPath();
128+
context.strokeStyle = particle.color;
129+
context.lineWidth = 1;
130+
context.moveTo(particle.old.p.x, particle.old.p.y);
131+
context.lineTo(particle.p.x, particle.p.y);
132+
context.closePath();
133+
context.stroke();
134+
};
135+
136+
renderer.start();
137+
}
138+
139+
function tick() {
140+
requestAnimationFrame(tick);
141+
142+
stats.begin();
143+
proton.update();
144+
stats.end();
145+
}
146+
</script>
147+
</body>
148+
</html>
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
<head>
4+
<title>behaviour-attraction2</title>
5+
<meta charset="utf-8">
6+
<style type="text/css">
7+
body {
8+
background-color: #333333;
9+
margin: 0px;
10+
overflow: hidden;
11+
-moz-user-select: none;
12+
-webkit-user-select: none;
13+
-ms-user-select: none;
14+
-khtml-user-select: none;
15+
user-select: none;
16+
}
17+
#testCanvas {
18+
background: #000;
19+
}
20+
</style>
21+
</head>
22+
<body>
23+
<canvas id="testCanvas"></canvas>
24+
<script src="../../lib/stats.min.js"></script>
25+
<script src="../../../build/proton-1.0.0.min.js"></script>
26+
<script>
27+
var canvas;
28+
var context;
29+
var proton;
30+
var renderer;
31+
var emitter;
32+
var stats;
33+
var mouseObj;
34+
var _mousedown = false;
35+
var repulsionBehaviour, crossZoneBehaviour;
36+
37+
Main();
38+
39+
function Main() {
40+
canvas = document.getElementById("testCanvas");
41+
canvas.width = window.innerWidth;
42+
canvas.height = window.innerHeight;
43+
context = canvas.getContext('2d');
44+
addStats();
45+
46+
createProton();
47+
createRenderer();
48+
tick();
49+
canvas.addEventListener('mousedown', mousedownHandler, false);
50+
canvas.addEventListener('mouseup', mouseupHandler, false);
51+
canvas.addEventListener('mousemove', mousemoveHandler, false);
52+
window.onresize = function(e) {
53+
canvas.width = window.innerWidth;
54+
canvas.height = window.innerHeight;
55+
crossZoneBehaviour.reset(new Proton.RectZone(0, 0, canvas.width, canvas.height), 'cross');
56+
}
57+
}
58+
59+
function addStats() {
60+
stats = new Stats();
61+
stats.setMode(2);
62+
stats.domElement.style.position = 'absolute';
63+
stats.domElement.style.left = '0px';
64+
stats.domElement.style.top = '0px';
65+
document.body.appendChild(stats.domElement);
66+
}
67+
68+
function createProton() {
69+
proton = new Proton;
70+
emitter = new Proton.Emitter();
71+
emitter.damping = 0.008;
72+
emitter.rate = new Proton.Rate(200);
73+
emitter.addInitialize(new Proton.Mass(1));
74+
emitter.addInitialize(new Proton.Radius(4));
75+
emitter.addInitialize(new Proton.Velocity(new Proton.Span(1.5), new Proton.Span(0, 360), 'polar'));
76+
77+
mouseObj = {
78+
x : 1003 / 2,
79+
y : 610 / 2
80+
};
81+
repulsionBehaviour = new Proton.Repulsion(mouseObj, 0, 0);
82+
addrepulsionBehaviours();
83+
crossZoneBehaviour = new Proton.CrossZone(new Proton.RectZone(0, 0, canvas.width, canvas.height), 'cross');
84+
emitter.addBehaviour(new Proton.Color('random'));
85+
emitter.addBehaviour(repulsionBehaviour);
86+
emitter.addBehaviour(crossZoneBehaviour);
87+
emitter.p.x = canvas.width / 2;
88+
emitter.p.y = canvas.height / 2;
89+
emitter.emit('once');
90+
proton.addEmitter(emitter);
91+
}
92+
93+
function addrepulsionBehaviours() {
94+
var total = 12;
95+
var d = 360 / total;
96+
var R = 230;
97+
for (var i = 0; i < 360; i += d) {
98+
var x = R * Math.cos(i * Math.PI / 180);
99+
var y = R * Math.sin(i * Math.PI / 180);
100+
emitter.addBehaviour(new Proton.Attraction({
101+
x : x + canvas.width / 2,
102+
y : y + canvas.height / 2
103+
}, 10, 300));
104+
}
105+
106+
emitter.addBehaviour(new Proton.Repulsion({
107+
x : canvas.width / 2,
108+
y : canvas.height / 2
109+
}, 20, 300));
110+
}
111+
112+
function mousedownHandler(e) {
113+
_mousedown = true;
114+
}
115+
116+
function mousemoveHandler(e) {
117+
if (_mousedown) {
118+
var _x, _y;
119+
if (e.layerX || e.layerX == 0) {
120+
_x = e.layerX;
121+
_y = e.layerY;
122+
} else if (e.offsetX || e.offsetX == 0) {
123+
_x = e.offsetX;
124+
_y = e.offsetY;
125+
}
126+
127+
mouseObj.x = _x;
128+
mouseObj.y = _y;
129+
repulsionBehaviour.reset(mouseObj, 30, 500);
130+
}
131+
}
132+
133+
function createRenderer() {
134+
renderer = new Proton.Renderer('other', proton);
135+
renderer.onProtonUpdate = function() {
136+
context.fillStyle = "rgba(0, 0, 0, 0.02)";
137+
context.fillRect(0, 0, canvas.width, canvas.height);
138+
};
139+
140+
renderer.onParticleUpdate = function(particle) {
141+
context.beginPath();
142+
context.strokeStyle = particle.color;
143+
context.lineWidth = 1;
144+
context.moveTo(particle.old.p.x, particle.old.p.y);
145+
context.lineTo(particle.p.x, particle.p.y);
146+
context.closePath();
147+
context.stroke();
148+
};
149+
150+
renderer.start();
151+
}
152+
153+
function mouseupHandler(e) {
154+
_mousedown = false;
155+
repulsionBehaviour.reset(mouseObj, 0, 0);
156+
}
157+
158+
function tick() {
159+
requestAnimationFrame(tick);
160+
161+
stats.begin();
162+
proton.update();
163+
stats.end();
164+
}
165+
</script>
166+
</body>
167+
</html>

0 commit comments

Comments
 (0)