import pylab from continent import continent from weather import temperature, precipitation print 'loading...' h = continent(13,13,0.0,8) # good plains # s, w = temperature(h*8, 10, 60) # pylab.contour(h,[0]) # pylab.contour(s,[0],colors='r') # pylab.axis('scaled') # pylab.xlim([0, h.shape[0]-1]) # pylab.ylim([0, h.shape[0]-1]) p = precipitation(h, 10, 60) print 'finished.' pylab.contour(h,[0,0.001]) pylab.contour(p,[0.4,0.2,0.1,0.05,0.025,0.01]) pylab.axis('scaled') pylab.xlim([0, h.shape[0]-1]) pylab.ylim([0, h.shape[0]-1])
def initScene(): print 'Loading...' # heightmap h = continent(4,5,0.465,8) # penesulas # h = continent(7,7,0.0,8) # mountainous # h = continent(13,13,0.0,8) # good plains # h = continent(24,65,0.0,8) # sahara h *= SCALE summer, winter = temperature(h, 10, 60) precip = precipitation(h, 10, 60) dh = slope(h) r, g, b = vegetation(h, dh, summer, winter, precip) # h[h == 0] = - 0.7 # pylab.figure() # pylab.contour(h,25) # pylab.axis('scaled') # pylab.xlim([0, h.shape[0]-1]) # pylab.ylim([0, h.shape[0]-1]) # pylab.show() # h[h < 0] = 0.0 n = h.shape[0] dh = (numpy.arange(n) / float(n-1) - 0.5) / 2.0 dh = dh ** 2 * n * SCALE for i in xrange(n): h[:,i] -= dh h[i,:] -= dh print 'Finished.' # build OpenGL list gllist = glGenLists(1) glNewList(gllist, GL_COMPILE) for i in xrange(1, n): glBegin(GL_QUAD_STRIP) for j in xrange(n): glColor3f(r[j,i-1], g[j,i-1], b[j,i-1]) glVertex3f((i-1) * SCALE, j * SCALE, h[j,i-1]) glColor3f(r[j,i], g[j,i], b[j,i]) glVertex3f(i * SCALE, j * SCALE, h[j,i]) glEnd() glEndList() glViewport(0, 0, 1200, 800) glShadeModel(GL_SMOOTH) # glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) glEnable(GL_DEPTH_TEST) # atmosphere fog glClearColor(0.22, 0.45, 0.9, 1.0) glFogi(GL_FOG_MODE, GL_EXP) glFogfv(GL_FOG_COLOR, [0.22, 0.45, 0.9, 1.0]) glFogf(GL_FOG_DENSITY, 0.025) glEnable(GL_FOG) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(45.0, 1.5, 0.1, 1000.0) glMatrixMode(GL_MODELVIEW) return gllist, h, dh