From 395e4a7852ccbfb2935ea167166494e232d5fec5 Mon Sep 17 00:00:00 2001 From: tosh <-@--PC.(none)> Date: Thu, 9 May 2013 12:08:19 +0200 Subject: [PATCH] removes equator, achieves uniform distribution of stars implementing rejection sampling, adds UNIX script header --- interface/resources/gen_stars.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/interface/resources/gen_stars.py b/interface/resources/gen_stars.py index d18ec28b86..c1ddf4be15 100644 --- a/interface/resources/gen_stars.py +++ b/interface/resources/gen_stars.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python + # # gen_stars.py # interface @@ -12,7 +14,7 @@ from random import random,randint from math import sqrt, hypot, atan2, pi, fmod, degrees from sys import argv,stderr -hemisphere_only, equator, meridians= False, 1000, 1000 +hemisphere_only, equator, meridians= False, 0, 1000 n_random = 100000 if len(argv) > 1: @@ -50,10 +52,13 @@ for i in range(n_random): g = max(0,min(255,w + randint(-20,60))) b = max(0,min(255,w + randint(-10,100))) # position - x,y,z = random()*2-1,random(),random()*2-1 - if not hemisphere_only: - y = y*2-1 - l = sqrt(x*x + y*y + z*z) + while True: + x,y,z = random()*2-1,random(),random()*2-1 + if not hemisphere_only: + y = y*2-1 + l = sqrt(x*x + y*y + z*z) + if l <= 1.0: + break x /= l; y /= l; z /= l xz = hypot(x,z)