25
25
26
26
// === PAINT OBJECTS ===
27
27
28
- CanvasLineSegment = Utilities . createClass (
29
- function ( stage )
28
+ class CanvasLineSegment {
29
+ constructor ( stage )
30
30
{
31
31
var circle = Stage . randomInt ( 0 , 3 ) ;
32
32
this . _color = [ "#e01040" , "#10c030" , "#744CBA" , "#e05010" ] [ circle ] ;
@@ -39,9 +39,9 @@ CanvasLineSegment = Utilities.createClass(
39
39
this . _startY = stage . circleRadius * this . _sinTheta + stage . circleY [ circle ] ;
40
40
this . _length = Math . pow ( Pseudo . random ( ) , 8 ) * stage . lineLengthMaximum + stage . lineMinimum ;
41
41
this . _segmentDirection = Pseudo . random ( ) > 0.5 ? - 1 : 1 ;
42
- } , {
42
+ }
43
43
44
- draw : function ( context )
44
+ draw ( context )
45
45
{
46
46
context . strokeStyle = this . _color ;
47
47
context . lineWidth = this . _lineWidth ;
@@ -54,10 +54,10 @@ CanvasLineSegment = Utilities.createClass(
54
54
this . _startY + this . _segmentDirection * this . _length * this . _sinTheta ) ;
55
55
context . stroke ( ) ;
56
56
}
57
- } ) ;
57
+ }
58
58
59
- CanvasArc = Utilities . createClass (
60
- function ( stage )
59
+ class CanvasArc {
60
+ constructor ( stage )
61
61
{
62
62
var maxX = 6 , maxY = 3 ;
63
63
var distanceX = stage . size . x / maxX ;
@@ -77,9 +77,9 @@ CanvasArc = Utilities.createClass(
77
77
this . _color = colors [ Math . floor ( Pseudo . random ( ) * colors . length ) ] ;
78
78
this . _lineWidth = 1 + Math . pow ( Pseudo . random ( ) , 5 ) * 30 ;
79
79
this . _doStroke = Stage . randomInt ( 0 , 3 ) != 0 ;
80
- } , {
80
+ }
81
81
82
- draw : function ( context )
82
+ draw ( context )
83
83
{
84
84
this . _startAngle += this . _omega ;
85
85
this . _endAngle += this . _omega / 2 ;
@@ -99,13 +99,24 @@ CanvasArc = Utilities.createClass(
99
99
context . fill ( ) ;
100
100
}
101
101
}
102
- } ) ;
102
+ }
103
103
104
104
// CanvasLinePoint contains no draw() method since it is either moveTo or
105
105
// lineTo depending on its index.
106
- CanvasLinePoint = Utilities . createClass (
107
- function ( stage )
106
+ class CanvasLinePoint {
107
+ static gridSize ;
108
+ static offsets ;
109
+
110
+ constructor ( stage )
108
111
{
112
+ CanvasLinePoint . gridSize = new Point ( 80 , 40 ) ;
113
+ CanvasLinePoint . offsets = [
114
+ new Point ( - 4 , 0 ) ,
115
+ new Point ( 2 , 0 ) ,
116
+ new Point ( 1 , - 2 ) ,
117
+ new Point ( 1 , 2 ) ,
118
+ ] ;
119
+
109
120
var colors = [ "#101010" , "#808080" , "#c0c0c0" , "#101010" , "#808080" , "#c0c0c0" , "#e01040" ] ;
110
121
this . color = Stage . randomElementInArray ( colors ) ;
111
122
this . width = Math . pow ( Pseudo . random ( ) , 5 ) * 20 + 1 ;
@@ -115,69 +126,61 @@ CanvasLinePoint = Utilities.createClass(
115
126
if ( stage . objects . length )
116
127
nextPoint = this . randomPoint ( stage , stage . objects [ stage . objects . length - 1 ] . coordinate ) ;
117
128
else
118
- nextPoint = this . randomPoint ( stage , this . gridSize . center ) ;
129
+ nextPoint = this . randomPoint ( stage , CanvasLinePoint . gridSize . center ) ;
119
130
this . point = nextPoint . point ;
120
131
this . coordinate = nextPoint . coordinate ;
121
- } , {
122
-
123
- gridSize : new Point ( 80 , 40 ) ,
124
- offsets : [
125
- new Point ( - 4 , 0 ) ,
126
- new Point ( 2 , 0 ) ,
127
- new Point ( 1 , - 2 ) ,
128
- new Point ( 1 , 2 ) ,
129
- ] ,
132
+ }
130
133
131
- randomPoint : function ( stage , startCoordinate )
134
+ randomPoint ( stage , startCoordinate )
132
135
{
133
136
var coordinate = startCoordinate ;
134
137
if ( stage . objects . length ) {
135
- var offset = Stage . randomElementInArray ( this . offsets ) ;
138
+ var offset = Stage . randomElementInArray ( CanvasLinePoint . offsets ) ;
136
139
137
140
coordinate = coordinate . add ( offset ) ;
138
- if ( coordinate . x < 0 || coordinate . x > this . gridSize . width )
141
+ if ( coordinate . x < 0 || coordinate . x > CanvasLinePoint . gridSize . width )
139
142
coordinate . x -= offset . x * 2 ;
140
- if ( coordinate . y < 0 || coordinate . y > this . gridSize . height )
143
+ if ( coordinate . y < 0 || coordinate . y > CanvasLinePoint . gridSize . height )
141
144
coordinate . y -= offset . y * 2 ;
142
145
}
143
146
144
- var x = ( coordinate . x + .5 ) * stage . size . x / ( this . gridSize . width + 1 ) ;
145
- var y = ( coordinate . y + .5 ) * stage . size . y / ( this . gridSize . height + 1 ) ;
147
+ var x = ( coordinate . x + .5 ) * stage . size . x / ( CanvasLinePoint . gridSize . width + 1 ) ;
148
+ var y = ( coordinate . y + .5 ) * stage . size . y / ( CanvasLinePoint . gridSize . height + 1 ) ;
146
149
return {
147
150
point : new Point ( x , y ) ,
148
151
coordinate : coordinate
149
152
} ;
150
- } ,
153
+ }
151
154
152
- draw : function ( context )
155
+ draw ( context )
153
156
{
154
157
context . lineTo ( this . point . x , this . point . y ) ;
155
158
}
156
- } ) ;
159
+ }
157
160
158
- CanvasQuadraticSegment = Utilities . createSubclass ( CanvasLinePoint ,
159
- function ( stage )
161
+ class CanvasQuadraticSegment extends CanvasLinePoint {
162
+ constructor ( stage )
160
163
{
161
- CanvasLinePoint . call ( this , stage ) ;
164
+ super ( stage ) ;
162
165
// The chosen point is instead the control point.
163
166
this . _point2 = this . point ;
164
167
165
168
// Get another random point for the actual end point of the segment.
166
169
var nextPoint = this . randomPoint ( stage , this . coordinate ) ;
167
170
this . point = nextPoint . point ;
168
171
this . coordinate = nextPoint . coordinate ;
169
- } , {
172
+ }
170
173
171
- draw : function ( context )
174
+ draw ( context )
172
175
{
173
176
context . quadraticCurveTo ( this . _point2 . x , this . _point2 . y , this . point . x , this . point . y ) ;
174
177
}
175
- } ) ;
178
+ }
176
179
177
- CanvasBezierSegment = Utilities . createSubclass ( CanvasLinePoint ,
178
- function ( stage )
180
+ class CanvasBezierSegment extends CanvasLinePoint {
181
+ constructor ( stage )
179
182
{
180
- CanvasLinePoint . call ( this , stage ) ;
183
+ super ( stage ) ;
181
184
// The chosen point is instead the first control point.
182
185
this . _point2 = this . point ;
183
186
var nextPoint = this . randomPoint ( stage , this . coordinate ) ;
@@ -186,13 +189,13 @@ CanvasBezierSegment = Utilities.createSubclass(CanvasLinePoint,
186
189
nextPoint = this . randomPoint ( stage , nextPoint . coordinate ) ;
187
190
this . point = nextPoint . point ;
188
191
this . coordinate = nextPoint . coordinate ;
189
- } , {
192
+ }
190
193
191
- draw : function ( context , off )
194
+ draw ( context , off )
192
195
{
193
196
context . bezierCurveTo ( this . _point2 . x , this . _point2 . y , this . _point3 . x , this . _point3 . y , this . point . x , this . point . y ) ;
194
197
}
195
- } ) ;
198
+ }
196
199
197
200
// === STAGES ===
198
201
0 commit comments