From: Kadir H. <kha...@ya...> - 2008-03-26 10:42:03
|
Hi Symion, I am not an astronomer, but while playing with VPython I was trying to solve the same problem you have mentioned a few days ago: Central lighting. I tried to post an answer to your previous note with my simple solar system VPython "simulation", but due to its attachments above the size limit, it was caught-up in the moderator queue. I am posting again a simplified version of it without the textures on the planets. It is not a realistic solar system, with no scale or whatsoever, but provides a "tricky solution" to the central lighting issue. Bruce has warned me that the future VPython implementation may not be implementing a similar "spot light" system, so with that warning, may be you can use it for your wish list, to create a more realistic solar system with correct orbits and periods. I have the textured version where the Earth, the Moon and the Mars are textured with some photo images. I can send textured version to you if you like, but I understand you are using VPython V3 at the moment where you can not use texturing functions. (Actually, the code is almost there, with texture option for the spheres replaced by simple color option. You need specified texturefiles as well of course). Have fun, Kadir ----------------------------- from __future__ import division from visual import * from PIL import Image # from the Python Imaging Library (PIL); www.pythonware.com/products/pil from random import random from random import uniform scene.autoscale = 0 im = Image.open("earth3.jpg") # read a jpeg file named earth3.jpg im = im.resize((256,256)) # resize so that length and width are powers of 2 data = array(list(im.getdata()),ubyte) # read pixel data into flat Numeric array data = reshape(data, (256,256,3)) # reshape for rgb texture im = data[::-1].copy() # copy() is necessary to make array contiguous in memory im2 = Image.open("Mars400.jpg") # read a jpeg file named Mars400.jpg im2 = im2.resize((256,256)) # resize so that length and width are powers of 2 data2 = array(list(im2.getdata()),ubyte) # read pixel data into flat Numeric array data2 = reshape(data2, (256,256,3)) # reshape for rgb texture im2 = data2[::-1].copy() # copy() is necessary to make array contiguous in memory im3 = Image.open("Luna400.jpg") # read a jpeg file named Luna400.jpg im3 = im3.resize((256,256)) # resize so that length and width are powers of 2 data3 = array(list(im3.getdata()),ubyte) # read pixel data into flat Numeric array data3 = reshape(data3, (256,256,3)) # reshape for rgb texture im3 = data3[::-1].copy() # copy() is necessary to make array contiguous in memory photo = texture(data=im, type="rgb") photo2 = texture(data=im2, type="rgb") photo3 = texture(data=im3, type="rgb") scene.width = 1024 scene.title = "Solar System" scene.height = 800 scene.range = (12,12,12) scene.forward = (-0.2,-0.2,-1) earth = frame(pos=(-10,0,+10)) pib8 = pi/8 k1 = sphere(frame=earth, pos=(-3,0,-3), radius=1, color=(0.6,0.6,0.6), shininess=0) k2 = sphere(frame=earth, pos=(0,0,0), radius=2, color=color.blue, axis=(0,0.4244,1), shininess=0) eaxis = box(frame=earth, pos=k2.pos, size=(0.1,k2.radius*2.4,0.1), axis=k2.axis) k3 = sphere(pos=(+15,0,+15), radius=1, color=color.green, shininess=0) k4 = sphere(pos=(+5,0,-5), radius=1, color=color.red, shininess=0) scene.lights = [] scene.ambient = 0.2 light(pos=(0, 0, 0), local=True, color=0.2) sun = sphere(pos=(0,0,0), radius=1, color=(0.99,0.99,0.50), opacity=0.90) spot7 = light(pos=(-4,-4,0), local=True, color=0.8, spot_direction=(1,1,0), spot_cutoff=10) spot8 = light(pos=(+4,+4,0), local=True, color=0.8, spot_direction=(-1,-1,0), spot_cutoff=10) spot9 = light(pos=(-4,0,-4), local=True, color=0.8, spot_direction=(1,0,1), spot_cutoff=10) spot10 = light(pos=(+4,0,+4), local=True, color=0.8, spot_direction=(-1,0,-1), spot_cutoff=10) spot11 = light(pos=(0,-4,-4), local=True, color=0.8, spot_direction=(0,1,1), spot_cutoff=10) spot12 = light(pos=(0,+4,+4), local=True, color=0.8, spot_direction=(0,-1,-1), spot_cutoff=10) ring1 = ring(pos=sun.pos, axis=(0,1,0), radius=sun.radius*1.2, thickness=sun.radius*0.01, color=color.yellow) ring2 = ring(pos=sun.pos, axis=(1,0,0), radius=sun.radius*1.2, thickness=sun.radius*0.01, color=color.red) ring3 = ring(pos=sun.pos, axis=(0,0,1), radius=sun.radius*1.2, thickness=sun.radius*0.01, color=color.blue) for i in(range(1,200)): x = uniform(-50,50) y = uniform(-50,50) sphere(pos=(x,y), radius=0.05, color=color.white, shininess=1) pi4 = pi/512 pi2 = pi4*2 pie = pi4*4 pi8 = pie*2 while True: k2.rotate(angle=pie, axis=(0,1,-0.4244)) earth.rotate(angle=pi4,axis=(0,1,0), origin=(0,0,0)) k1.rotate(angle=pi2, axis=(0,1,0), origin=(0,0,0)) k3.rotate(angle=pi4, axis=(0,1,0), origin=(0,0,0)) k4.rotate(angle=pi8, axis=(0,1,0), origin=(0,0,0)) rate(32) ____________________________________________________________________________________ Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs |