This is why Python becomes the most popular:
It allows an amateur like me to illustrate a physics idea about how to look over the edge of our visible Universe with an animation produced in less than 100 lines.
#!/usr/bin/env python2.7
'''
How to look outside our observable Universe using an outpost:
-------------------------------------------------------------
- the WHITE dots are the stars
- The Pale Blue Dot is the Earth
- the GREEN circle is the obsarvable Universe, looking from Earth
- the RED dot is an outpost telescope, continuously broadcasting its view
- the RED circle is the observable Universe, looking from the outpost
- note that the circles' radius increases with time, at the speed of light, c
- note that even the observable radius keeps increasing,
with time the stars are leaving the observable circles because space expands
- note how with time, will be less and less stars to view,
even thought the stars are still shining out there,
just that they are running away faster than the speed of light
- by receiving the broadcasted view from the outpost,
we will be able to study all the stars seen by the outpost,
including the stars that otherwise will be outside of our direct reach,
but are still reachable from the outpost viewpoint
- after a while, even the outpost will run away outside our view
'''
import pygame as pg
import random
WIDTH = 1920
HEIGHT = 1080
ANIMATION_FPS = 10
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
LIGHT_BLUE = (32, 64, 255)
NR_OF_STARS = 2000
INFLATION_COEF = 0.01
OBSERVABLE_START_RANGE = 200
class Dot:
def __init__(self, x=0, y=0, color=WHITE, thickness=3):
self.x = random.randrange(1, WIDTH-1)
self.y = random.randrange(1, HEIGHT-1)
self.color = color
self.thickness = thickness
self.x_now = self.x
self.y_now = self.y
def __call__(self, x, y, color, thickness):
self.x = x
self.y = y
self.color = color
self.thickness = thickness
def xy_now(self, time=0):
self.x_now = int(round(self.x * (1 + time * INFLATION_COEF)))
self.y_now = int(round(self.y * (1 + time * INFLATION_COEF)))
screen = pg.display.set_mode((WIDTH, HEIGHT))
pg.display.set_caption("Observable vs Expansion")
clock = pg.time.Clock()
light_day = 1
# populate the Universe with stars
random.seed(1)
stars = [Dot() for i in range(NR_OF_STARS)]
# add Earth to the Universe
Earth = Dot()
Earth(200, 150, LIGHT_BLUE, 10)
stars.append(Earth)
# add an Outpost to the Universe, inside the viewrange of the Earth
Outpost = Dot()
ox = Earth.x + int(round(3.0/4.0 * 2**0.5/2 * OBSERVABLE_START_RANGE))
oy = Earth.y + int(round(2.0/4.0 * 2**0.5/2 * OBSERVABLE_START_RANGE))
Outpost(ox, oy, RED, 5)
stars.append(Outpost)
# animation loop
stopped = False
while not stopped:
# Frames Per Second
clock.tick(ANIMATION_FPS)
for event in pg.event.get(): # User did something
if event.type == pg.QUIT: # If user clicked close
stopped=True # Flag that we are done so we exit this loop
# Clear the display buffer and set the screen background
screen.fill(BLACK)
for star in stars:
# Update the star positions as per today's view and draw the star
star.xy_now(light_day)
pg.draw.circle(screen, star.color, [star.x_now, star.y_now], star.thickness)
# Draw today observable ranges from Earth and from Outpost
pg.draw.circle(screen, GREEN, [Earth.x_now, Earth.y_now], OBSERVABLE_START_RANGE+light_day, 1)
pg.draw.circle(screen, RED, [Outpost.x_now, Outpost.y_now], OBSERVABLE_START_RANGE+light_day, 1)
# Display the screen buffer
pg.display.flip()
pg.image.save(screen, "frame" + str(light_day).rjust(5, '0') + ".png")
# A day passes with each frame
light_day += 1
pg.quit()
How to look over the edge of our visible Universe - Outpost simulation
If the outpost idea is correct or not from the physics standpoint is another topic, but Python allowed to show exactly what I was picturing in my mind but couldn't describe it clear enough by words.