@@ -10,19 +10,19 @@ const container = document.querySelector('div#container');
10
10
const containerWidthText = document . querySelector ( '.container-width' ) ;
11
11
const origin = document . querySelector ( 'div#origin' ) ;
12
12
13
- var containerLength = 0 ;
13
+ let containerLength = 0 ;
14
14
15
15
function floatToPx ( num ) {
16
16
return String ( num ) + 'px' ;
17
17
}
18
18
19
19
function parseFloat200 ( s ) {
20
- let res = parseFloat ( s ) ;
20
+ const res = parseFloat ( s ) ;
21
21
return ( isNaN ( res ) ) ? Infinity : res ;
22
22
}
23
23
24
24
function wrongInput ( elem ) {
25
- let o = elem . style . backgroundColor ;
25
+ const o = elem . style . backgroundColor ;
26
26
elem . style . backgroundColor = '#c98d8d' ;
27
27
setTimeout ( ( ) => {
28
28
elem . style . backgroundColor = o ;
@@ -31,7 +31,7 @@ function wrongInput(elem) {
31
31
32
32
function onChangeContainerSize ( e ) {
33
33
containerLength = parseFloat ( window . getComputedStyle ( container ) . width ) ;
34
- var containerLengthPx = floatToPx ( containerLength ) ;
34
+ const containerLengthPx = floatToPx ( containerLength ) ;
35
35
container . style . height = containerLengthPx ;
36
36
containerWidthText . value = containerLengthPx ;
37
37
@@ -77,10 +77,10 @@ function Block(initOffset = 0, initPeriod = 0, initSemiX = 0, initSemiY = 0, ini
77
77
* rad:rotation angle in radians, deg:rotation angle in deg
78
78
*/
79
79
this . yieldRotated = ( t ) => {
80
- let x = this . yieldX ( t ) ;
81
- let y = this . yieldY ( t ) ;
82
- let deg = this . rotate ( t ) ;
83
- let rad = degToRadian ( deg ) ;
80
+ const x = this . yieldX ( t ) ;
81
+ const y = this . yieldY ( t ) ;
82
+ const deg = this . rotate ( t ) ;
83
+ const rad = degToRadian ( deg ) ;
84
84
return {
85
85
x : rotateX ( x , y , rad ) ,
86
86
y : rotateY ( x , y , rad ) ,
@@ -94,18 +94,18 @@ function Block(initOffset = 0, initPeriod = 0, initSemiX = 0, initSemiY = 0, ini
94
94
95
95
// moving block area
96
96
97
- var intervals = 40 ;
97
+ let intervals = 40 ;
98
98
99
99
/**
100
100
* the rendered block
101
101
* @function BlockInMotion
102
102
* @param {Number } id specifies the index number of the spawned block
103
103
* @return {BlockInMotion } a newly spawned moving block
104
104
*
105
- * usage var x = new BlockInMotion(1)
105
+ * usage let x = new BlockInMotion(1)
106
106
*/
107
107
function BlockInMotion ( id ) {
108
- var block1 = new Block ( ) ;
108
+ let block1 = new Block ( ) ;
109
109
const blockElement = document . querySelector ( `div#moving-obj-${ id } ` ) ;
110
110
const blockTrajectoryElement = document . querySelector ( `div#moving-obj-trajectory-${ id } ` ) ;
111
111
const blockPrjElement = document . querySelector ( `div#moving-obj-prj-${ id } ` ) ;
@@ -124,14 +124,14 @@ function BlockInMotion(id) {
124
124
const setRotateAroundSelect = document . querySelector ( `#info-container-${ id } .set-rotate-around` ) ;
125
125
const enterBtn = document . querySelector ( `#info-container-${ id } .set-attr-go` ) ;
126
126
const resetBtn = document . querySelector ( `#info-container-${ id } .set-attr-reset` ) ;
127
- var maxRadiusInContainer = 0 ;
128
- var timer = 0 ;
129
- var rendered = null ;
130
- var isFocus = false ;
127
+ let maxRadiusInContainer = 0 ;
128
+ let timer = 0 ;
129
+ let rendered = null ;
130
+ let isFocus = false ;
131
131
132
- var dragFlag = false ;
133
- var blockElementIniX = 0 ;
134
- var blockElementIniY = 0 ;
132
+ let dragFlag = false ;
133
+ let blockElementIniX = 0 ;
134
+ let blockElementIniY = 0 ;
135
135
136
136
// set default values of the circle
137
137
function setDefaultValsForCircle ( e , resetColor = true ) {
@@ -187,16 +187,16 @@ function BlockInMotion(id) {
187
187
// also renders semiX/semiY trajectory // |
188
188
function rendersBlock ( ) { // |
189
189
timer += intervals ; // |
190
- let realTimer = timer / 1000 ; // intriguing geometry. i do not like // |
191
- let o = parseFloat ( blockElement . style . width ) ;
192
- let correction = maxRadiusInContainer - o / 2 ;
190
+ const realTimer = timer / 1000 ; // intriguing geometry. i do not like // |
191
+ const o = parseFloat ( blockElement . style . width ) ;
192
+ const correction = maxRadiusInContainer - o / 2 ;
193
193
const coordinateSet = block1 . yieldRotated ( realTimer ) ;
194
194
let x = coordinateSet . x + correction ;
195
195
let y = coordinateSet . y + correction ;
196
196
197
197
let dX = 0 , dY = 0 ;
198
198
if ( isFocus ) { // if ellipse circulates around the focus, shift
199
- let rad = coordinateSet . rad ;
199
+ const rad = coordinateSet . rad ;
200
200
if ( Math . abs ( coordinateSet . rx ) >= Math . abs ( coordinateSet . ry ) ) {
201
201
let c = Math . sqrt ( coordinateSet . rx ** 2 - coordinateSet . ry ** 2 ) ;
202
202
dX = c * Math . cos ( rad ) ;
@@ -245,7 +245,7 @@ function BlockInMotion(id) {
245
245
semiY = Math . abs ( semiY ) ;
246
246
blockTrajectoryElement . style . width = floatToPx ( semiX * 2 ) ;
247
247
blockTrajectoryElement . style . height = floatToPx ( semiY * 2 ) ;
248
- let leftTopPos = parseFloat ( window . getComputedStyle ( container ) . width ) / 2 ;
248
+ const leftTopPos = parseFloat ( window . getComputedStyle ( container ) . width ) / 2 ;
249
249
blockTrajectoryElement . style . left = floatToPx ( leftTopPos - semiX + dX ) ;
250
250
blockTrajectoryElement . style . top = floatToPx ( leftTopPos - semiY + dY ) ;
251
251
blockTrajectoryElement . style . transform = `rotate(${ deg } deg)` ;
@@ -284,15 +284,15 @@ function BlockInMotion(id) {
284
284
// by changing the 'rotate around', we can make the ball circulate around origin, or focus (apply to ellipses)
285
285
// updates the isFocus
286
286
setRotateAroundSelect . addEventListener ( 'change' , ( e ) => {
287
- let option = setRotateAroundSelect . value ;
288
- if ( option == 'origin' ) isFocus = false ;
287
+ const option = setRotateAroundSelect . value ;
288
+ if ( option === 'origin' ) isFocus = false ;
289
289
else isFocus = true ;
290
290
} ) ;
291
291
292
292
// by clicking go button, start rotating the ball
293
293
enterBtn . addEventListener ( 'click' , function triggerCircleMotion ( e ) {
294
294
// check color and size boxes
295
- const setSizeTextVal = parseFloat ( setSizeText . value )
295
+ const setSizeTextVal = parseFloat ( setSizeText . value ) ;
296
296
if ( setSizeTextVal <= 30 && setSizeTextVal >= 5 ) {
297
297
enterBtn . style . backgroundColor = setColorText . value ;
298
298
@@ -306,10 +306,10 @@ function BlockInMotion(id) {
306
306
return ;
307
307
}
308
308
// check period, semiX/semiY, rotation boxes
309
- let TNotValid = isNaN ( parseFloat ( setPeriodText . value ) ) ;
310
- let ANotValid = isNaN ( parseFloat ( setRotateText . value ) ) || Math . abs ( parseFloat ( setRotateText . value ) ) > 360 ;
311
- let XToLarge = Math . abs ( parseFloat200 ( setSemiXText . value ) ) > maxRadiusInContainer ;
312
- let YToLarge = Math . abs ( parseFloat200 ( setSemiYText . value ) ) > maxRadiusInContainer ;
309
+ const TNotValid = isNaN ( parseFloat ( setPeriodText . value ) ) ;
310
+ const ANotValid = isNaN ( parseFloat ( setRotateText . value ) ) || Math . abs ( parseFloat ( setRotateText . value ) ) > 360 ;
311
+ const XToLarge = Math . abs ( parseFloat200 ( setSemiXText . value ) ) > maxRadiusInContainer ;
312
+ const YToLarge = Math . abs ( parseFloat200 ( setSemiYText . value ) ) > maxRadiusInContainer ;
313
313
if ( ! XToLarge && ! YToLarge && ! TNotValid && ! ANotValid ) {
314
314
block1 . initPeriod = parseFloat ( setPeriodText . value ) ;
315
315
block1 . initSemiX = parseFloat ( setSemiXText . value ) ;
@@ -332,18 +332,18 @@ function BlockInMotion(id) {
332
332
if ( ! setSemiXLDeltaText . value ) setSemiXLDeltaText . value = 0 ;
333
333
if ( ! setSemiYLDeltaText . value ) setSemiYLDeltaText . value = 0 ;
334
334
if ( ! setRotateLDeltaText . value ) setRotateLDeltaText . value = 0 ;
335
- let TLDNotValid = isNaN ( parseFloat ( setPeriodLDeltaText . value ) ) ;
336
- let ALDNotValid = isNaN ( parseFloat ( setRotateLDeltaText . value ) ) || Math . abs ( parseFloat ( setRotateLDeltaText . value ) ) > 360 ;
337
- let XLDToLarge = Math . abs ( parseFloat200 ( setSemiXLDeltaText . value ) ) > maxRadiusInContainer ;
338
- let YLDToLarge = Math . abs ( parseFloat200 ( setSemiYLDeltaText . value ) ) > maxRadiusInContainer ;
335
+ const TLDNotValid = isNaN ( parseFloat ( setPeriodLDeltaText . value ) ) ;
336
+ const ALDNotValid = isNaN ( parseFloat ( setRotateLDeltaText . value ) ) || Math . abs ( parseFloat ( setRotateLDeltaText . value ) ) > 360 ;
337
+ const XLDToLarge = Math . abs ( parseFloat200 ( setSemiXLDeltaText . value ) ) > maxRadiusInContainer ;
338
+ const YLDToLarge = Math . abs ( parseFloat200 ( setSemiYLDeltaText . value ) ) > maxRadiusInContainer ;
339
339
if ( ! XLDToLarge && ! YLDToLarge && ! TLDNotValid && ! ALDNotValid ) {
340
- var periodLD = parseFloat ( setPeriodLDeltaText . value ) ;
340
+ const periodLD = parseFloat ( setPeriodLDeltaText . value ) ;
341
341
block1 . period = ( t ) => block1 . initPeriod + t * periodLD ;
342
- var semiXLD = parseFloat ( setSemiXLDeltaText . value ) ;
342
+ const semiXLD = parseFloat ( setSemiXLDeltaText . value ) ;
343
343
block1 . semiX = ( t ) => block1 . initSemiX + t * semiXLD ;
344
- var semiYLD = parseFloat ( setSemiYLDeltaText . value ) ;
344
+ const semiYLD = parseFloat ( setSemiYLDeltaText . value ) ;
345
345
block1 . semiY = ( t ) => block1 . initSemiY + t * semiYLD ;
346
- var rotateLD = parseFloat ( setRotateLDeltaText . value ) ;
346
+ const rotateLD = parseFloat ( setRotateLDeltaText . value ) ;
347
347
block1 . rotate = ( t ) => block1 . initRotate + t * rotateLD ;
348
348
349
349
setPeriodLDeltaText . value = periodLD ;
@@ -390,9 +390,9 @@ function BlockInMotion(id) {
390
390
if ( dragFlag ) {
391
391
e = e || window . event ;
392
392
e . preventDefault ( ) ;
393
- let o = parseFloat ( blockElement . style . width ) ;
394
- let newX = ( e . clientX || e . touches [ 0 ] . clientX ) - blockElementIniX ;
395
- let newY = ( e . clientY || e . touches [ 0 ] . clientY ) - blockElementIniY ;
393
+ const o = parseFloat ( blockElement . style . width ) ;
394
+ const newX = ( e . clientX || e . touches [ 0 ] . clientX ) - blockElementIniX ;
395
+ const newY = ( e . clientY || e . touches [ 0 ] . clientY ) - blockElementIniY ;
396
396
if ( blockOffBoundary ( newX , newY , o ) ) return ;
397
397
blockElement . style . left = floatToPx ( newX ) ;
398
398
blockElement . style . top = floatToPx ( newY ) ;
@@ -401,9 +401,9 @@ function BlockInMotion(id) {
401
401
402
402
blockPrjElement . style . left = floatToPx ( newX ) ;
403
403
404
- let dX = newX - parseFloat ( origin . style . left ) ;
405
- let dY = newY - parseFloat ( origin . style . top ) ;
406
- let newRadius = Math . sqrt ( ( dX ** 2 + dY ** 2 ) ) ;
404
+ const dX = newX - parseFloat ( origin . style . left ) ;
405
+ const dY = newY - parseFloat ( origin . style . top ) ;
406
+ const newRadius = Math . sqrt ( ( dX ** 2 + dY ** 2 ) ) ;
407
407
setSemiXText . value = newRadius ;
408
408
setSemiYText . value = newRadius ;
409
409
block1 . offset = - Math . atan2 ( dY , dX ) ;
@@ -440,7 +440,7 @@ function BlockInMotion(id) {
440
440
const setFpsText = document . querySelector ( '.shared-info-container-bo > span:nth-child(2)' ) ;
441
441
442
442
document . querySelector ( '.shared-info-container-bo .fps-decrease' ) . addEventListener ( 'click' , ( e ) => {
443
- let fps = parseInt ( setFpsText . innerText ) ;
443
+ const fps = parseInt ( setFpsText . innerText ) ;
444
444
if ( fps <= 5 ) {
445
445
setFpsText . innerText = 5 ;
446
446
return ;
@@ -449,13 +449,11 @@ document.querySelector('.shared-info-container-bo .fps-decrease').addEventListen
449
449
setFpsText . innerText = fps - ( ( fps >= 40 ) ? 10 : 5 ) ;
450
450
} ) ;
451
451
document . querySelector ( '.shared-info-container-bo .fps-increase' ) . addEventListener ( 'click' , ( e ) => {
452
- let fps = parseInt ( setFpsText . innerText ) ;
452
+ const fps = parseInt ( setFpsText . innerText ) ;
453
453
if ( fps >= 150 ) {
454
454
setFpsText . innerText = 150 ;
455
455
return ;
456
456
}
457
457
intervals = parseInt ( 1000 / fps ) ;
458
458
setFpsText . innerText = fps + ( ( fps >= 40 ) ? 10 : 5 ) ;
459
459
} ) ;
460
-
461
-
0 commit comments