No Description

main.py 1.7KB

    from RigidMass import RigidMass from PIL import Image from PIL import ImageFont from PIL import ImageDraw import random import math outImg = Image.new("RGB", [1000, 1000]) def storePixels(name, things): global outImg #outImg = Image.new("RGB", [1000, 1000]) w, h = 1000, 1000 for thing in things: if thing.x > 0 and thing.y > 0 and thing.x < 1000 and thing.y < 1000: outImg.putpixel((int(thing.x), int(thing.y)), 16581370*255) #outImg.save(name) #sun = RigidMass( 500000000000000, 0, -5, 500, 500, 0.05) #earth = RigidMass(500000000000000, 0, 5, 250, 500, 0.05) tick_time = 0.05 num_stars = 1000 stars = [] for i in range(num_stars): #give each star some angular velocity #did some cool algebra on paper x = random.randint(375, 625) y = random.randint(375, 625) dx = x - 500 dy = y - 500 if abs(dy) <= abs(dx): vy = 3 * random.random() vx = -vy * dy / dx else: vx = 3 * random.random() vy = -vx * dx / dy #this makes the circle rotate together #without it, one half rotates in the opposite direction #the two halves are separated by the y=x line #I have no idea why that happens, but this fixes it. if y < x: vx = -vx vy = -vy stars.append(RigidMass(50000000000, vx, vy, x, y, tick_time)) for i in range(0, 50000): for a in range(0, num_stars): for b in range(0, num_stars): if not a == b and abs(stars[a].x - stars[b].x) > 0.5 and abs(stars[a].y - stars[b].y) > 0.5: stars[a].gravity(stars[b]) for a in range(0, num_stars): stars[a].process_tick() storePixels(str(i) + ".png", stars) if i % 10 == 0: draw = ImageDraw.Draw(outImg) draw.text((0, 0),"t=" + str(i * tick_time) + "s", (255,255,255)) outImg.save("img/" + str(i // 10) + ".png") outImg = Image.new("RGB", [1000, 1000]) outImg.save("final.png")