-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from evaristocuesta/dev.0.3.0
Dev.0.3.0
- Loading branch information
Showing
18 changed files
with
453 additions
and
68 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import ShootingStars from "./shooting-stars-effect/shooting-stars-effect"; | ||
import LedMatrixEffect from "./led-matrix-effect/led-matrix-effect"; | ||
|
||
export default class EffectFactory { | ||
static #effects = { | ||
'straight-particle': (config) => new ShootingStars(config), | ||
'twisted-particle': (config) => new ShootingStars(config), | ||
'led-matrix': (config) => new LedMatrixEffect(config) | ||
} | ||
|
||
static createParticle(config) { | ||
return this.#effects[config.particleType]?.(config) ?? new ShootingStars(config); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
export default class DefaultLedParticle { | ||
|
||
#config; | ||
#x; | ||
#y; | ||
#originalX; | ||
#originalY; | ||
#targetX; | ||
#targetY; | ||
#maxDistance; | ||
#color; | ||
#minForce; | ||
|
||
constructor(config, props) { | ||
this.#config = config; | ||
this.#x = 0; | ||
this.#y = 0; | ||
this.#originalX = props.x; | ||
this.#originalY = props.y; | ||
this.setTargetToOrigin(); | ||
this.#color = props.color; | ||
this.#minForce = ((Math.random() * this.#config.speed) + this.#config.speed / 2) * 0.001; | ||
} | ||
|
||
setTarget(x, y) { | ||
this.#targetX = x; | ||
this.#targetY = y; | ||
} | ||
|
||
setTargetToOrigin() { | ||
this.#targetX = this.#originalX; | ||
this.#targetY = this.#originalY; | ||
} | ||
|
||
setPos(x, y) { | ||
this.#x = x; | ||
this.#y = y; | ||
} | ||
|
||
getX() { | ||
return this.#x; | ||
} | ||
|
||
getY() { | ||
return this.#y; | ||
} | ||
|
||
getOriginalX() { | ||
return this.#originalX; | ||
} | ||
|
||
getOriginalY() { | ||
return this.#originalY; | ||
} | ||
|
||
getTargetX() { | ||
return this.#targetX; | ||
} | ||
|
||
getTargetY() { | ||
return this.#targetY; | ||
} | ||
|
||
update(deltaTime, speed) { | ||
const dx = this.#targetX - this.#x; | ||
const dy = this.#targetY - this.#y; | ||
if (Math.abs(dx) > 1 || Math.abs(dy) > 1 ) { | ||
this.#x += speed * dx * deltaTime * this.#minForce; | ||
this.#y += speed * dy * deltaTime * this.#minForce; | ||
return false; | ||
} | ||
else { | ||
this.#x = this.#targetX; | ||
this.#y = this.#targetY; | ||
return true; | ||
} | ||
} | ||
|
||
draw(ctx) { | ||
ctx.beginPath(); | ||
ctx.arc(this.#x, this.#y, 2, 0, Math.PI*2); | ||
ctx.closePath(); | ||
ctx.fillStyle = this.#color; | ||
ctx.fill(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export default class LedMatrixEffectBaseState { | ||
|
||
ledMatrixEffect; | ||
|
||
setLedMatrixEffect(ledMatrixEffect) { | ||
this.ledMatrixEffect = ledMatrixEffect; | ||
} | ||
|
||
update(deltaTime) { | ||
|
||
} | ||
|
||
setLedMatrixEffect(ledMatrixEffect) { | ||
this.ledMatrixEffect = ledMatrixEffect; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import LedMatrixStateFactory from "./led-matrix-state-factory"; | ||
import LedMatrixEffectBaseState from "./led-matrix-effect-base-state"; | ||
|
||
export default class LedMatrixEffectIdleState extends LedMatrixEffectBaseState { | ||
|
||
#accumulatedTime = 0; | ||
#config; | ||
#particlesArray; | ||
|
||
constructor(config, particles) { | ||
super(); | ||
this.#config = config; | ||
this.#particlesArray = particles; | ||
} | ||
|
||
update(deltaTime) { | ||
this.#accumulatedTime += deltaTime; | ||
if (this.#accumulatedTime > this.#config.transitionTime) { | ||
this.ledMatrixEffect.setState(LedMatrixStateFactory.createLedMatrixState(this.#config.type, this.#config, this.#particlesArray)); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/led-matrix-effect/led-matrix-effect-returning-state.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import LedMatrixEffectBaseState from "./led-matrix-effect-base-state"; | ||
import LedMatrixStateFactory from "./led-matrix-state-factory"; | ||
|
||
export default class LedMatrixEffectReturningState extends LedMatrixEffectBaseState { | ||
|
||
#config; | ||
#particlesArray; | ||
|
||
constructor(config, particles) { | ||
super(); | ||
this.#config = config; | ||
this.#particlesArray = particles; | ||
for (let i = 0; i < this.#particlesArray.length; i++){ | ||
|
||
this.#particlesArray[i].setTargetToOrigin(); | ||
} | ||
} | ||
|
||
update(deltaTime) { | ||
let finished = true; | ||
for (let i = 0; i < this.#particlesArray.length; i++){ | ||
let particleIdle = this.#particlesArray[i].update(deltaTime, 1); | ||
finished = finished && particleIdle; | ||
} | ||
if (finished) { | ||
this.ledMatrixEffect.setState(LedMatrixStateFactory.createLedMatrixState('idle', this.#config, this.#particlesArray)); | ||
} | ||
} | ||
} |
Oops, something went wrong.