Created
September 12, 2023 21:55
-
-
Save gen3vra/7aac263d1be34ddb19cb09e4b9f66ecf to your computer and use it in GitHub Desktop.
Generate a random ascii starfield.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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