Skip to content

Instantly share code, notes, and snippets.

@the-louie
Last active February 1, 2019 06:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save the-louie/0b19c8e664f184291d3fb8caaa289d71 to your computer and use it in GitHub Desktop.
Save the-louie/0b19c8e664f184291d3fb8caaa289d71 to your computer and use it in GitHub Desktop.
SCRIPT-8
// Create the universe and all the stars
const bigBang = (maxx, maxy, count) => [...Array(count)].map((i) => ({
x: (Math.random() * maxx),
y: (Math.random() * maxy),
c: Math.floor((1 - Math.sqrt(1 - Math.random())) * 5)
})).concat([{x: 120, y: 40, c: 5}])
const starCount = 100
const universe = bigBang(128, 128, starCount)
initialState = {
speed: 0.1
}
draw = (state) => {
clear()
universe.forEach((star) => {
sprite(star.x, star.y, star.c)
star.x -= (star.c + 1) * state.speed
if (star.x < 0) {
star.x = 128
} else if (star.x > 128) {
star.x = 0
}
})
}
update = (state, input) => {
if (input.left) {
state.speed += 0.07
} else if (input.right) {
state.speed -= 0.07
}
}
{
"0": [
" ",
" ",
" ",
" 66 ",
" 66 ",
" ",
" ",
" "
],
"1": [
" ",
" ",
" ",
" 33 ",
" 33 ",
" ",
" ",
" "
],
"2": [
" ",
" ",
" 4 ",
" 424 ",
" 424 ",
" 4 ",
" ",
" "
],
"3": [
" ",
" ",
" 3 ",
" 313 ",
" 313 ",
" 3 ",
" ",
" ",
0
],
"4": [
" 4 ",
" 3 ",
" 1 ",
" 31013 ",
" 31013 ",
" 1 ",
" 3 ",
" 4 "
],
"5": [
" 00 ",
" 555255 ",
" 252222 ",
"25555222",
"55222222",
" 552225 ",
" 555255 ",
" 00 ",
0
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment