Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

0916dhkim
Copy link

No description provided.

class DigitalRain {
constructor(canvasContainer) {
constructor(canvasContainer, options) {
Copy link
Author

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.

Comment on lines +16 to +22
const CHARACTERS =
"MATRIXMATRIXMATRIXMATRIXMAØ1Ø1Ø1Ø1Ø#$%@&#$%@&ヲァィゥェォャュョッアイウエオカキクケコサシスセソタチツテトナヌネノハヒフヘホマミムメモヤユヨラリルレロワンヲァィゥェォャュョッアイウエオカキクケコサシスセソタチツテトナヌネノハヒフヘホマミムメモヤユヨラリルレロワンヲァィゥェォャュョッアイウエオカキクケコサシスセソタチツテトナヌネノハヒフヘホマミムメモヤユヨラリルレロワンヲァィゥェォャュョッアイウエオカキクケコサシスセソタチツテトナヌネノハヒフヘホマミムメモヤユヨラリルレロワン";

const getRandomChar = () => {
const randNum = Math.floor(Math.random() * CHARACTERS.length);
return CHARACTERS.charAt(randNum);
};
Copy link
Author

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.

Comment on lines -569 to +610
this.firstChar = null;
this.secondChar = null;
this.characters = [];
Copy link
Author

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.

Comment on lines -341 to +385
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
);
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant