-
Notifications
You must be signed in to change notification settings - Fork 3
/
Star.js
executable file
·107 lines (73 loc) · 2.24 KB
/
Star.js
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
dojo.provide("Star");
dojo.declare("Star", [Container],{
//alpha argument
maxAlpha:0.95,
minAlpha:0.4,
//frequency of rotation, rotation speed,
//amount to twinkle, and speed to fall.
frequency:50,
rotationSpeed:180,
twinkle:0.5,
speedIncrement:1,
scalar:1,
stroke: 1,
constructor:function(args) {
//Container Object to hold Ship and it's flame.
//dojo.safeMixin(this,new Container());
//Take arguments and mix them in.
dojo.safeMixin(this, args);
this.starOne = new Shape();
this.starTwo = new Shape();
this.addChild(this.starOne);
this.addChild(this.starTwo);
this.makeShape();
this.alphaRange = this.maxAlpha - this.minAlpha;
//this.alpha = this.maxAlpha;
this.scaleX = this.scaleY = this.scalar;
},
makeShape:function(){
//console.log("star made");
//working graphics object
var g = this.starOne.graphics;
g.clear();
g.setStrokeStyle(this.stroke,"round").beginStroke("#FFFFFF");
g.beginFill("#FFF");
g.moveTo(0, 5); //top
g.lineTo(0, -5); //bottom
g.moveTo(5, 0); //left
g.lineTo(-5, 0); //right
g.closePath(); //close
//Now part two
g = this.starTwo.graphics;
g.clear();
g.setStrokeStyle(this.stroke,"round").beginStroke("#FFF");
g.beginFill("#FFF");
g.moveTo(3, 3); //NE
g.lineTo(-3, -3); //SW
g.moveTo(-3, 3); //NW
g.lineTo(3, -3); //SE
g.closePath(); //close
},
tick:function(){
var ticks = Ticker.getTicks(false);
var amt = (ticks % this.frequency) / this.frequency;
var t = this.twinkle;
var scaleOne = t + (amt)*(1-t);
var scaleTwo = t + (1 - amt)*(1-t);
var alphaOne = this.minAlpha + this.alphaRange * amt;
var alphaTwo = this.minAlpha + this.alphaRange * (1-amt);
if (amt < 0.5) {
this.starOne.scaleX = this.starOne.scaleY = scaleOne;
this.starTwo.scaleX = this.starTwo.scaleY = scaleTwo;
this.starOne.alpha = alphaOne;
this.starTwo.alpha = alphaTwo;
}else{
this.starOne.scaleX = this.starOne.scaleY = scaleTwo;
this.starTwo.scaleX = this.starTwo.scaleY = scaleOne;
this.starOne.alpha = alphaTwo;
this.starTwo.alpha = alphaOne;
}
this.rotation = ((ticks%this.rotationSpeed)/this.rotationSpeed)*360;
this.y += this.speedIncrement;
}
});