GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — mojs/spec/shape-swirl.coffee at master · softDen/mojs

Expand file tree

/

shape-swirl.coffee

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
258 lines (234 loc) · 10.1 KB
/

shape-swirl.coffee

Copy path

File metadata and controls

258 lines (234 loc) · 10.1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
Shape = mojs.Shape
ShapeSwirl = mojs.ShapeSwirl
Module = mojs.Module
tr = new Shape
describe 'ShapeSwirl ->', ->
describe 'extension ->', ->
it 'should extend Shape class', ->
swirl = new ShapeSwirl
expect(swirl instanceof Shape).toBe true
it 'should have degreeShift value', ->
swirl = new ShapeSwirl
x: {0:10}, y: {0:10}
isSwirl: false, degreeShift: 90
expect(swirl._props.degreeShift).toBe 90
describe '_calcPosData method ->', ->
it 'should calc position radius', ->
swirl = new ShapeSwirl x: {0:10}, y: {0:20}
expect(swirl._posData.radius).toBe Math.sqrt (10*10 + 20*20)
it 'should calc position angle', ->
swirl = new ShapeSwirl x: {0:10}, y: {0:10}
expect(swirl._posData.angle).toBe 135
it 'should calc position angle', ->
swirl = new ShapeSwirl x: {0:-10}, y: {0:-10}
expect(swirl._posData.angle).toBe - 45
it 'should calc position angle', ->
swirl = new ShapeSwirl x: {0:0}, y: {0:-10}
expect(swirl._posData.angle).toBe 0
it 'should calc position angle', ->
swirl = new ShapeSwirl x: {0:-10}, y: {0:0}
expect(swirl._posData.angle).toBe 270
it 'should save startX and StartY values', ->
swirl = new ShapeSwirl x: {0:10}, y: {10:10}
expect(swirl._posData.x.start).toBe 0
expect(swirl._posData.y.start).toBe 10
it 'should set start position anyways', ->
swirl = new ShapeSwirl x: {0:10}, y: 0
expect(swirl._props.x).toBe '0px'
expect(swirl._props.y).toBe '0px'
# it 'should call _calcSwirlXY method with 1', ->
# swirl = new ShapeSwirl x: {0:10}, y: 0
# spyOn swirl, '_calcSwirlXY'
# swirl._calcPosData()
# expect(swirl._calcSwirlXY).toHaveBeenCalledWith 1
describe '_extendDefaults method ->', ->
it 'should call super _extendDefaults method', ->
swirl = new ShapeSwirl radius: [{ 20: 50 }, 20]
spyOn(Module.prototype, '_extendDefaults').and.callThrough()
swirl._extendDefaults()
expect(Module.prototype._extendDefaults).toHaveBeenCalled()
it 'should call _calcPosData method', ->
swirl = new ShapeSwirl radius: [{ 20: 50 }, 20]
spyOn(swirl, '_calcPosData').and.callThrough()
swirl._extendDefaults()
expect(swirl._calcPosData).toHaveBeenCalled()
describe '_tuneNewOptions method ->', ->
it 'should call super _tuneNewOptions method', ->
swirl = new ShapeSwirl radius: [{ 20: 50 }, 20]
spyOn(Module.prototype, '_tuneNewOptions').and.callThrough()
swirl._tuneNewOptions({})
expect(Module.prototype._tuneNewOptions).toHaveBeenCalled()
it 'should not call super _tuneNewOptions method if no o', ->
swirl = new ShapeSwirl radius: [{ 20: 50 }, 20]
spyOn(Module.prototype, '_tuneNewOptions').and.callThrough()
swirl._tuneNewOptions()
expect(Module.prototype._tuneNewOptions).not.toHaveBeenCalled()
it 'should call _calcPosData method if x changes', ->
swirl = new ShapeSwirl x: 200
spyOn(swirl, '_calcPosData').and.callThrough()
swirl._tuneNewOptions({ x: 300 })
expect(swirl._calcPosData).toHaveBeenCalled()
it 'should call _calcPosData method if y changes', ->
swirl = new ShapeSwirl y: 200
spyOn(swirl, '_calcPosData').and.callThrough()
swirl._tuneNewOptions({ y: 300 })
expect(swirl._calcPosData).toHaveBeenCalled()
it 'should not call _calcPosData method if no x/y changes', ->
swirl = new ShapeSwirl radius: [{ 20: 50 }, 20]
spyOn(swirl, '_calcPosData').and.callThrough()
swirl._tuneNewOptions({ radius: 200 })
expect(swirl._calcPosData).not.toHaveBeenCalled()
describe '_declareDefaults method ->', ->
it 'should call super _declareDefaults', ->
swirl = new ShapeSwirl radius: [{ 20: 50 }, 20]
spyOn(ShapeSwirl.prototype, '_declareDefaults').and.callThrough()
swirl._declareDefaults()
expect(ShapeSwirl.prototype._declareDefaults).toHaveBeenCalled()
it 'should add swirlSize default', ->
swirl = new ShapeSwirl radius: [{ 20: 50 }, 20]
expect(swirl._defaults.swirlSize).toBe 10
it 'should add swirlFrequency default', ->
swirl = new ShapeSwirl radius: [{ 20: 50 }, 20]
expect(swirl._defaults.swirlFrequency).toBe 3
it 'should add isSwirl default', ->
swirl = new ShapeSwirl radius: [{ 20: 50 }, 20]
expect(swirl._defaults.isSwirl).toBe true
it 'should add pathScale default', ->
swirl = new ShapeSwirl radius: [{ 20: 50 }, 20]
expect(swirl._defaults.pathScale).toBe 1
it 'should add degreeShift default', ->
swirl = new ShapeSwirl radius: [{ 20: 50 }, 20]
expect(swirl._defaults.degreeShift).toBe 0
it 'should modify radius default', ->
swirl = new ShapeSwirl fill: 'cyan'
expect(swirl._defaults.radius).toBe 5
it 'should modify scale default', ->
swirl = new ShapeSwirl fill: 'cyan'
expect(swirl._defaults.scale[1]).toBe 0
it 'should modify x default', ->
swirl = new ShapeSwirl fill: 'cyan'
expect(swirl._defaults.x).toBe 0
it 'should modify x default', ->
swirl = new ShapeSwirl fill: 'cyan'
expect(swirl._defaults.y).toBe 0
it 'should add direction default', ->
swirl = new ShapeSwirl radius: [{ 20: 50 }, 20]
expect(swirl._defaults.direction).toBe 1
it 'should have isWithShape', ->
swirl = new ShapeSwirl fill: 'cyan'
expect(swirl._defaults.isWithShape).toBe true
describe '_setProgress ->', ->
it 'should svae progress', ->
swirl = new ShapeSwirl radius: [{ 20: 50 }, 20]
swirl._progress = -1
swirl._setProgress .5
expect(swirl._progress).toBe .5
it 'should call _calcCurrentProps method', ->
swirl = new ShapeSwirl radius: [{ 20: 50 }, 20]
spyOn(swirl, '_calcCurrentProps').and.callThrough()
swirl._setProgress .5, .35
expect(swirl._calcCurrentProps).toHaveBeenCalledWith .5, .35
it 'should call _draw method', ->
swirl = new ShapeSwirl radius: [{ 20: 50 }, 20]
spyOn(swirl, '_draw').and.callThrough()
swirl._setProgress .5
expect(swirl._draw).toHaveBeenCalledWith .5
it 'should set x/y progress', ->
swirl = new ShapeSwirl x: {0:10}, y: {0:10}, isSwirl: false
swirl._setProgress .4
swirl._setProgress .5
expect(parseInt(swirl._props.x, 10)).toBe 5
expect(parseInt(swirl._props.y, 10)).toBe 5
it 'should set x/y progress regarding degreeShift', ->
swirl = new ShapeSwirl
x: {0:10}, y: {0:10}, isSwirl: false,
degreeShift: 90
# swirl._setProgress .4
swirl._setProgress .5
x = parseFloat(swirl._props.x).toFixed 2
expect(x).toBe '-5.00'
expect(parseInt(swirl._props.y, 10)).toBe 5
it 'should set x/y progress regarding delta degreeShift', ->
swirl = new ShapeSwirl
x: {0:10}, y: {0:10}, isSwirl: false,
degreeShift: { 0: 180 }
# swirl._setProgress .5
swirl._setProgress .5
x = parseFloat(swirl._props.x).toFixed 2
expect(x).toBe '-5.00'
expect(parseInt(swirl._props.y, 10)).toBe 5
it 'should set x/y progress', ->
swirl = new ShapeSwirl x: {0:10}, y: {0:10}, isSwirl: false
swirl._setProgress 1
expect(parseInt(swirl._props.x, 10)).toBe 10
expect(parseInt(swirl._props.y, 10)).toBe 10
it 'should set negative x/y progress', ->
swirl = new ShapeSwirl
x: {0:'-10'}, y: {0:'-10'}, isSwirl: false
swirl._setProgress 1
x = parseFloat(swirl._props.x).toFixed 2
expect(x).toBe '-10.00'
y = parseFloat(swirl._props.y).toFixed 2
expect(y).toBe '-10.00'
# expect(parseInt(swirl._props.x, 10)).toBe -10
# expect(parseInt(swirl._props.y, 10)).toBe -10
# old foreign
# it 'should set plain x/y progress if foreign context', ->
# swirl = new ShapeSwirl
# x: {0:10}, y: {0:10}, ctx: tr.ctx, isSwirl: false
# swirl._setProgress .5
# swirl._setProgress 1
# expect(swirl._props.x.toFixed(2)).toBe '10.00'
# expect(swirl._props.y.toFixed(2)).toBe '10.00'
it 'should respect pathScale value', ->
swirl = new ShapeSwirl
x: {0:10}, y: {0:10},
isSwirl: false, pathScale: .5
swirl._setProgress 1
expect(parseInt(swirl._props.x, 10) ).toBe 5
expect(parseInt(swirl._props.y, 10) ).toBe 5
it 'should not add swirl', ->
swirl = new ShapeSwirl x: {0:10}, y: {0:10}, isSwirl: false
swirl._setProgress .5
expect( parseInt(swirl._props.x, 10) ).toBe 5
expect( parseInt(swirl._props.y, 10) ).toBe 5
it 'should add swirl if isSwirl', ->
swirl = new ShapeSwirl x: {0:10}, y: {0:10}, isSwirl: true
swirl._setProgress .5
expect(swirl._props.x).not.toBe '5.0000px'
expect(swirl._props.y).not.toBe '5.0000px'
describe '_getSwirl method ->', ->
it 'should calc swirl based on swirlFrequency and swirlSize props', ->
swirl = new ShapeSwirl
swirl1 = swirl._getSwirl(.5)
freq = Math.sin(swirl._props.swirlFrequency*.5)
sign = swirl._props.direction
expect(swirl1).toBe sign*swirl._props.swirlSize*freq
describe '_draw method ->', ->
it 'should call super', ->
swirl = new ShapeSwirl
spyOn Shape::, '_draw'
swirl._draw()
expect(Shape::_draw).toHaveBeenCalled()
it 'should not call super if !isWithShape', ->
swirl = new ShapeSwirl isWithShape: false
spyOn Shape::, '_draw'
spyOn Shape::, '_drawEl'
swirl._draw()
expect(Shape::_draw).not.toHaveBeenCalled()
expect(Shape::_drawEl).toHaveBeenCalled()
describe '_calcSwirlXY method ->', ->
it 'should set values without exponintail values', ->
swirl = new ShapeSwirl x: { 0: 250 }, y: { 0: 250 }
swirl._calcSwirlXY( .000000001 )
swirl._calcSwirlXY( .000000001 )
# console.log swirl._props.x
expect(swirl._props.x).not.toMatch /e/
expect(swirl._props.y).not.toMatch /e/
it 'should set negative values without exponintail values', ->
swirl = new ShapeSwirl x: { 0: -250 }, y: { 0: -250 }
swirl._calcSwirlXY( .000000001 )
swirl._calcSwirlXY( .000000001 )
# console.log swirl._props.x
expect(swirl._props.x).not.toMatch /e/
expect(swirl._props.y).not.toMatch /e/
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.