Skip to content

Instantly share code, notes, and snippets.

@gen3vra
Created September 12, 2023 21:55
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 gen3vra/7aac263d1be34ddb19cb09e4b9f66ecf to your computer and use it in GitHub Desktop.
Save gen3vra/7aac263d1be34ddb19cb09e4b9f66ecf to your computer and use it in GitHub Desktop.
Generate a random ascii starfield.
import random
characters = ['˚', '゚', ' ', '‍', ',', '*', ' ', '✦', '.', ' ']
width = 60
height = 20
starfield = [[' ' for _ in range(width)] for _ in range(height)]
star_density = 0.07 # higher = more stars
for row in range(height):
for col in range(width):
if random.random() < star_density:
starfield[row][col] = random.choice(characters)
starfield_str = '\n'.join([''.join(row) for row in starfield])
print(starfield_str)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment