A starfield effect, inspired by the old Windows screensaver, though the style is more in line with Star Trek. Use up and down to increase and decrease speed, and press X to show stats.
I used nucleartide's Pico-8 snippets, specifically vec3 and pline(), to do the 3D projection. I was encouraged by reinvdwoerd's Perspective Lines and used his cartridge to figure out how to use pline().
To really get immersed, shout "increase speed to [warp number]!" as you hold the up key or "all stop!" as you slow down to zero.
@PicoLate I'd love to do something similar to this in my game. Would you mind relicensing this code under something more permissive, like the MIT license that nucleartide/pico-snippets is under?
@a2 You're free to use it however you want, no credit necessary, and I promise I won't sue! I just selected Pico-8's default licensing option, figuring it's better than nothing at all. I don't know how to license it with the MIT license, other than hosting it on Github.
Besides, I don't think my code is original enough to warrant it; plenty of people have done 3D starfields before, and nucleartide's stuff is doing the heavy lifting here.
Also, if you wait a day or two, I'm working on a tweet-length cart that does a 3D starfield with much fewer characters, possibly making it easier to drop into whatever you're working on.
@PicoLate Sure, that makes sense. All good :) Looking forward to your tweet-length cart :)
@PicoLate In addition to my original praise for this effect on Twitter - I did have a suggestion for your consideration that may improve the effect even more?
What if the stars start out, briefly, at color 1 (dark blue)?
I think it may make their appearance from the depths of space even smoother than they already are.
Anyway - just a thought! ;-)
@Liquidream I think I tried starting the colors out at blue, but rejected it for some reason. Maybe it didn't look as nice as I expected, but I'll try it again. You'll notice that I made a mistake with the colors in this starfield. The stars are supposed to go from dark grey to grey to white, but at some point I got them mixed up and they go from dark grey to white to grey! Fixing this should make the stars feel smoother.
@PicoLate Fair enough.
(And didn't notice the bug - but yeah, that should help too!)
I really want to use this routine in a game I'm working on, but it's quite token-heavy. Does anyone have any ideas for optimising/trimming it?
@timeandspace You're in luck. I made a post with smaller versions of starfields here. You'll be interested in the mini starfield or, if you're really pressed for space, the tweet starfield.
@timeandspace Also, note that the tweet starfield has visual errors because a star's z-coordinate can sometimes be zero! I did that to save a couple characters.
Therefore you should either go with the mini starfield snippet, or use this altered version of the tweet snippet:
function _init() t={} n=64 for i=-32,n do add(t,{v={x=i,y=0,z=0}}) end end function _draw() cls() for i=1,n do q=t[i].v x,y=p(q.x,q.y,q.z) q.z+=1 a,b=p(q.x,q.y,q.z) line(x,y,a,b) if q.z>-1.2then q.y=-rnd(n)+32 q.z=-rnd(n)-2 end end end function p(x,y,z) return -x/z*n+n,-y/z*n+n end |
I changed "if q.z>-1then" to "if q.z>-1.2then", ensuring that when 1 is added to the z-coordinate of a star q, the z-coordinate will still always be less than zero, or else the star's position is reset.
Of course, the mini starfield is heavily commented and much more amenable to alterations so that you can fit it into your game how you like, so you probably ought to look at that one anyway :).
I'm going to use the multi-colour routine. It's still smaller than the original routine on this page, and it looks too awesome not to use!
[Please log in to post a comment]