forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo worm.js
More file actions
79 lines (49 loc) · 1.48 KB
/
Copy pathdemo worm.js
File metadata and controls
79 lines (49 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.image('ball', 'assets/sprites/shinyball.png');
}
var sprite;
var particles = [];
var bmd;
var u = 0;
var n = 0;
var oldn = 0;
var ad = 0;
function create() {
bmd = game.add.bitmapData(800, 600);
for (var i = 0; i < 60; i++)
{
particles.push(new Phaser.Point(0, 0));
}
sprite = game.add.sprite(0, 0, bmd);
}
function mycircle(context, x, y, R, color) {
//R = 64;
context.fillStyle = color;
context.beginPath();
context.arc(x, y, R, 0, Math.PI * 2, true);
context.closePath();
context.fill();
}
function update() {
bmd.clear();
oldn = n;
for (var t = 0; t < particles.length; t++)
{
var p = particles[t];
// p.x = Math.sin(n) * 50 + Math.cos(n * 1.5) * 300;
// p.y = Math.sin(n / 2) * 20 + Math.sin(n * 2) * 250;
p.x = Math.cos(n) * 50 + Math.sin(n * 1.5) * 300;
p.y = Math.cos(n / 2) * 20 + Math.cos(n * 2) * 250;
var tx = p.x;
var ty = p.y;
bmd.context.globalCompositeOperation = 'xor';
//mycircle(bmd.context, p.x + 400, p.y + 300, Math.sin(t * 360 / particles.length / 2 * Math.PI / 180) * 50, 'rgba(255, 255, 0, 1)');
mycircle(bmd.context, p.x + 400, p.y + 300, Math.sin(t * 360 / particles.length / 2 * Math.PI / 180) * 50, 'rgba(255, 255, 0, 1)');
n += 0.05;
//bmd.context.globalCompositeOperation = 'source-over';
}
n = oldn + 0.02;
}
function render() {
}