From 8a1fd4343744fc867f763ab9da166ad1e481f501 Mon Sep 17 00:00:00 2001 From: tosh Date: Wed, 27 Mar 2013 03:28:48 +0100 Subject: [PATCH] implements a more uniform distribution of star positions and a progress bar --- interface/resources/gen_stars.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/interface/resources/gen_stars.py b/interface/resources/gen_stars.py index a7244ba066..521cdab72d 100644 --- a/interface/resources/gen_stars.py +++ b/interface/resources/gen_stars.py @@ -9,13 +9,16 @@ # Input file generator for the starfield. from random import random,randint -from sys import argv +from math import sqrt, hypot, atan2, pi, fmod, degrees +from sys import argv,stderr -n = 1000 +n = 10 if len(argv) > 1: n = int(argv[1]) +bars_total, bars_prev = 77, 0 + for i in range(n): # color w = randint(30,randint(40,255)) @@ -23,7 +26,21 @@ for i in range(n): g = max(0,min(255,w + randint(-20,60))) b = max(0,min(255,w + randint(-10,100))) # position - azi = random() * 360 - alt = random() * 90 - print "%f %f #%02x%02x%02x" % (azi,alt,r,g,b) + x,y,z = random()*2-1,random(),random()*2-1 + l = sqrt(x*x + y*y + z*z) + x /= l; y /= l; z /= l + xz = hypot(x,z) + + azimuth = degrees(fmod(atan2(x,z)+pi,2*pi)) + altitude = degrees(atan2(y,xz)) + + bars = round(bars_total*i/n) + if bars != bars_prev: + bars_prev = bars + bars = int(bars) + stderr.write('\r[%s%s]' % ('#' * bars, '-' * (bars_total-bars))) + + print "%f %f #%02x%02x%02x" % (azimuth,altitude,r,g,b) + +stderr.write('\r[%s]\n' % ('#' * bars_total,))