Skip to content
Advertisement

Modifying an existing CodePen Galaxy affect (Zoom out to Zoom In)

so recently I have found this awesome galaxy effect on codepen: https://codepen.io/zeztron/pen/MPNxxR

I tried to modify the JavaScript and couldn’t figure out a way to change it so instead of it feeling like Zooming out, making it to feel like Zooming in.

Can anyone help? Thank you!!

Here are the codes:

JavaScript
JavaScript
JavaScript

Advertisement

Answer

The z-axis of each star is decreasing from a random point inside the canvas to 0 to create a zooming-out effect. To reverse it, simply increase the z-axis, not the speed.

This is the zooming-out:

JavaScript

And this is the zooming-in:

JavaScript

You need to reset the z-axis when it reaches a certain point so that it could run infinitely.

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement