Beispiel #1
0
	def generate_background_vertex_list(self):
		"""Generate a reusable vertex/color list of all background stars.  It
		will be invoked as background_vertex_list.draw(pyglet.gl.GL_POINTS).  """

		background_star_vertices = []
		background_star_colors = []

		# randomly generate background stars
		for coordinate in utilities.random_dispersed_coordinates(amount=8000, dispersion=3):
			[background_star_vertices.append(component) for component in coordinate]

			color = []
			for index in range(0,3):
				color.append(64)
			# allow one or two of the bytes to be less, which allows slight coloration
			color[random.randint(0,2)] = random.randint(32,64)
			color[random.randint(0,2)] = random.randint(32,64)

			[background_star_colors.append(component) for component in color]

		self.background_vertex_list = pyglet.graphics.vertex_list(
			8000,
			('v2i/static', background_star_vertices),
			('c3B/static', background_star_colors)
		)
Beispiel #2
0
	def __init__(self, coordinates, primary_color_name=None):
		super(Nebula, self).__init__(coordinates)

		if primary_color_name is None:
			primary_color_name = random.choice(Lobe.color_names.keys())

		if not Lobe.color_names.has_key(primary_color_name):
			raise DataError, "invalid primary color name: %s"%primary_color_name
		self.primary_color_name = primary_color_name

		number_of_lobes = random.randint(Nebula.min_lobes, Nebula.max_lobes)
		self.lobes = []
		permutation_index = random.randint(0,1000)

		for lobe_coordinate in utilities.random_dispersed_coordinates(
			-Nebula.lobe_offset_bounds, -Nebula.lobe_offset_bounds, 
				Nebula.lobe_offset_bounds, Nebula.lobe_offset_bounds,
			amount = number_of_lobes,
			dispersion = 15
		):

			# cycle through all lobe secondary/image combinations
			permutation_index += 1

			self.lobes.append( Lobe(lobe_coordinate, self.primary_color_name, permutation_index) )

		logger.debug("lobe count: %s", len(self.lobes))
Beispiel #3
0
	def generate(self, amount, edges):
		# minimize repetition of nebula colors
		lobe_primary_color_names = Lobe.color_names.keys()
		lobe_primary_color_index = random.randint(0, 1000)

		for coordinate in utilities.random_dispersed_coordinates(
			edges[0], edges[1], edges[2], edges[3],
			amount=amount,
			dispersion=Nebula.max_offset*2
		):
			lobe_primary_color_index = lobe_primary_color_index % len(lobe_primary_color_names )
			primary_color_name = lobe_primary_color_names[lobe_primary_color_index]

			self.list.append( Nebula(coordinate, primary_color_name) )
			
			# cycle to next lobe primary color
			lobe_primary_color_index += 1
Beispiel #4
0
	def generate_stars_and_black_holes(self, config):
		# generate coordinates for stars AND black holes in one pass
		# since they may not overlap
		object_coordinates = utilities.random_dispersed_coordinates(
			config.limits[0], config.limits[1], config.limits[2], config.limits[3],
			amount=config.star_count, dispersion=config.dispersion
		)

		self.stars = stars.Stars(self.orbitals)
		self.black_holes = black_holes.BlackHoles()

		for coordinate in object_coordinates:
			object_type = utilities.choose_from_probability(config.object_pool)

			if object_type == 'black hole':
				self.black_holes.add(coordinate)

			else:
				# object_type is color
				self.stars.add(coordinate, object_type)
layer1 = pyglet.graphics.OrderedGroup(0)
layer2 = pyglet.graphics.OrderedGroup(1)
layer3 = pyglet.graphics.OrderedGroup(2)
layer4 = pyglet.graphics.OrderedGroup(3)

batch1 = pyglet.graphics.Batch()
batch2 = pyglet.graphics.Batch()

# outline of box to be divided
batch1.add(4, GL_LINE_LOOP, layer1,
	( 'v2i', (left-1,bottom-1, left-1,top+1, right+1,top+1, right+1,bottom-1)),
	( 'c3B', (128,128,128, 128,128,128, 128,128,128, 128,128,128))
)

for coordinate in utilities.random_dispersed_coordinates(bottom,left,top,right,amount,dispersion):
	layer = layer2
	batch2.add(1, GL_POINTS, layer,
		( 'v2i', (coordinate[0], coordinate[1])),
		( 'c3B', (0, 255, 255))
	)

@window.event
def on_draw():
	window.clear()
	glMatrixMode(GL_PROJECTION)
	glLoadIdentity()
	gluOrtho2D(-512, 512, -364, 364)
	glMatrixMode(GL_MODELVIEW)
	batch1.draw()
	batch2.draw()
Beispiel #6
0
	def testCoordinatesWithinMargin(self):
		"Given an evenly-divisible rectangle and maximum margins, coordinates should be known."
		coordinates = utilities.random_dispersed_coordinates( 0, 0, 2, 5, amount=2, dispersion=2 )
		self.assertEqual(coordinates, [(1, 1), (4, 1)])
Beispiel #7
0
	def testCoordinateCount(self):
		"The number of coordinates returned should equal the number requested."
		coordinates = utilities.random_dispersed_coordinates( amount=5133, dispersion=1 )
		self.assertEqual(len(coordinates), 5133)