Last active
December 27, 2015 12:19
-
-
Save davepape/7324944 to your computer and use it in GitHub Desktop.
Plots points from the US Census's 2000 gazetteer on a sphere.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pyglet.gl import * | |
from math import * | |
f = open('places2k.txt') | |
lines = f.readlines() | |
f.close() | |
verts = [] | |
for l in lines: | |
pop = int(l[73:82]) | |
if pop > 1000: | |
lat = radians(float(l[143:153])) | |
lon = radians(float(l[153:164])) | |
x = cos(lat) * cos(lon) | |
z = cos(lat) * sin(lon) | |
y = sin(lat) | |
verts += [x, y, z] | |
for lat in range(-90,90,10): | |
for lon in range(-180,180,10): | |
x = cos(radians(lat)) * cos(radians(lon)) | |
z = cos(radians(lat)) * sin(radians(lon)) | |
y = sin(radians(lat)) | |
verts += [x, y, z] | |
vlist = pyglet.graphics.vertex_list(len(verts)/3, ('v3f', verts)) | |
window = pyglet.window.Window(1024,512) | |
angle = 0 | |
@window.event | |
def on_draw(): | |
glClear(GL_COLOR_BUFFER_BIT) | |
glMatrixMode(GL_PROJECTION) | |
glLoadIdentity() | |
glOrtho(-2,2,-1,1,-1,1) | |
glMatrixMode(GL_MODELVIEW) | |
glLoadIdentity() | |
glRotatef(angle, 0,1,0) | |
glColor3f(1,1,1) | |
vlist.draw(GL_POINTS) | |
def update(dt): | |
global angle | |
angle -= 1 | |
pyglet.clock.schedule_interval(update,1/60.0) | |
pyglet.app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment