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

[PoemBot][HOC] Twinkling Stars Foreground Effect #42201

Merged
merged 6 commits into from
Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ export const commands = {
circles.push(createCircle());
}
this.backgroundEffect = () => {
this.p5.push();
this.p5.noStroke();
this.p5.background('black');
for (let i = 0; i < circles.length; i++) {
const circle = circles[i];
Expand All @@ -150,6 +152,7 @@ export const commands = {
circle.radius * 2
);
}
this.p5.pop();
};
break;
}
Expand Down
35 changes: 34 additions & 1 deletion apps/src/p5lab/spritelab/poembot/commands/foregroundEffects.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ export const commands = {
};
this.foregroundEffect = () => {
this.p5.push();
this.p5.noStroke();
if (stars.length === 0) {
resetStars();
}
Expand Down Expand Up @@ -244,6 +245,7 @@ export const commands = {
};
this.foregroundEffect = () => {
this.p5.push();
this.p5.noStroke();
glassShards.forEach(glass => drawGlass(glass));
glassShards = glassShards.filter(glass =>
// the glass shard is considered in bounds if at least one vertex
Expand All @@ -265,8 +267,39 @@ export const commands = {
break;
case 'birds':
break;
case 'twinkling':
case 'twinkling': {
let stars = [];
for (let i = 0; i < 75; i++) {
stars.push({
color: utils.randomColorFromPalette('twinkling'),
x: utils.randomInt(0, 400),
y: utils.randomInt(0, 400),
alpha: utils.randomInt(1, 100),
delta: this.p5.random([-6, -5, -4, -3, 3, 4, 5, 6])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think i understand what delta and the values in this array mean here -- can you add a comment?

});
}

this.foregroundEffect = () => {
this.p5.push();
this.p5.noStroke();
stars.forEach(star => {
const color = this.getP5Color(star.color, star.alpha);
this.p5.fill(color);

star.alpha += star.delta;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fine as is, but as an exercise, it could be interesting to turn this into a pure functional approach where the alpha is calculated simply based on which frame number we are up to, rather than doing the sign-flipping and alpha adjustment periodically.

if (star.alpha > 100) {
star.delta *= -1;
}
if (star.alpha < 0) {
star.delta *= -1;
}
drawStar(this.p5, star.x, star.y, 3, 9, 5);
});
this.p5.pop();
};

break;
}
default:
break;
}
Expand Down
3 changes: 2 additions & 1 deletion apps/src/p5lab/spritelab/poembot/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export const PALETTES = {
spring: ['#303F06', '#385202', '#547607', '#85AF4C', '#C1E876', '#D7FF6B'],
summer: ['#FAD0AE', '#F69F88', '#EE6E51', '#BC4946', '#425D19', '#202E14'],
autumn: ['#484F0C', '#AEA82E', '#EEBB10', '#D46324', '#731B31', '#4A173C'],
winter: ['#EAECE8', '#E3DDDF', '#D3CEDC', '#A2B6BF', '#626C7D', '#A4C0D0']
winter: ['#EAECE8', '#E3DDDF', '#D3CEDC', '#A2B6BF', '#626C7D', '#A4C0D0'],
twinkling: ['#FFC702', '#FC9103', '#F17302', '#B83604', '#7E1301']
};

export const POEMS = {
Expand Down