# looks best if run on 128x128x128 or bigger import math clr.AddReference('mscorlib') from System import Array clr.AddReference('System.Windows.Forms') from System.Windows.Forms import * clr.AddReference('System.Drawing') from System.Drawing import Bitmap empty = Color( 255, 255, 255, 0 ) def getColor(x, y, z): dx = (2.0 * x/width)-1.0 dy = (2.0 * y/depth)-1.0 dz = (2.0 * z/height)-1.0 r = math.sqrt( dx**2 + dy**2 + dz**2 ) phi = math.atan2( dy, dx ) if r == 0: theta = 0 else: theta = math.acos( dz / r ) lat = theta / math.pi long = ((phi / math.pi) + 1) / 2 r = r * 1.2 # exaggerated scale to look better if r < 0.19: # inner core return Color( 212, 212, 212, 255 ) elif r < 0.54: # outer core return Color( 255, 255, 0, 255 ) elif r < 0.89: # lower mantle return Color( 255, 127, 0, 255) elif r < 0.97: # upper mantle return Color( 158, 81, 58, 255 ) elif r < 1.0: # crust mapx = max( 0, min( map.Width - 1, math.floor( long * map.Width ) ) ) mapy = max( 0, min( map.Height - 1, math.floor( lat * map.Height ) ) ) mapcolor = map.GetPixel( mapx, mapy ) return Color( mapcolor.R, mapcolor.G, mapcolor.B, 255 ) elif r < 1.1: # atmosphere return Color( 128, 128, 255, (1.1-r)*70 ) else: # space return empty ofd = OpenFileDialog() ofd.CheckFileExists = True ofd.Multiselect = False ofd.Filter = "Image files (*.*)|*.*" if ofd.ShowDialog() == DialogResult.OK: map = Bitmap( ofd.FileName ) newvox = Array.CreateInstance( Color, width, depth, height ) for x in range(width): for y in range(depth): for z in range(height): newvox[x,y,z] = getColor(x,y,z) voxels = newvox map.Dispose()