-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement shading without alpha channel #5
base: main
Are you sure you want to change the base?
Conversation
class DigitalRain { | ||
constructor(canvasContainer) { | ||
constructor(canvasContainer, options) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor 1: let the constructor take in an optional parameter options
.
const CHARACTERS = | ||
"MATRIXMATRIXMATRIXMATRIXMAØ1Ø1Ø1Ø1Ø#$%@&#$%@&ヲァィゥェォャュョッアイウエオカキクケコサシスセソタチツテトナヌネノハヒフヘホマミムメモヤユヨラリルレロワンヲァィゥェォャュョッアイウエオカキクケコサシスセソタチツテトナヌネノハヒフヘホマミムメモヤユヨラリルレロワンヲァィゥェォャュョッアイウエオカキクケコサシスセソタチツテトナヌネノハヒフヘホマミムメモヤユヨラリルレロワンヲァィゥェォャュョッアイウエオカキクケコサシスセソタチツテトナヌネノハヒフヘホマミムメモヤユヨラリルレロワン"; | ||
|
||
const getRandomChar = () => { | ||
const randNum = Math.floor(Math.random() * CHARACTERS.length); | ||
return CHARACTERS.charAt(randNum); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor 2: Extract characters
and getRandomChar
outside of the DigitalRain
class.
this.firstChar = null; | ||
this.secondChar = null; | ||
this.characters = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor 3: Replace firstChar
& secondChar
with characters
.
for (let i = 4; i < stream.streamLength - 3; i++) { | ||
this.ctx2.fillStyle = "rgba(0, 0, 0, 0.075)"; | ||
fillRectTweak(this.ctx2, stream.XLOC, stream.YLOC, i); | ||
for (let i = 4; i < stream.characters.length; i++) { | ||
const char = stream.characters[i]; | ||
const settledRgb = parseHex(this.settledColor); | ||
const multiplier = 1 - (i + 1) / stream.streamLength; | ||
const shadedRgb = multiplyRgb(settledRgb, multiplier); | ||
const shadedColor = rgbToHex(shadedRgb); | ||
clearRectTweak(this.ctx, stream.XLOC, stream.YLOC, i + 1); | ||
textTweak( | ||
this.ctx, | ||
char, | ||
stream.XLOC, | ||
stream.YLOC, | ||
i + 1, | ||
shadedColor | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternative way of implementing the gradient shadow effect. This should be more performant because this approach does not use alpha channel.
No description provided.