random_vertex_generator

utils/generators.py

Random vertex generator.

The random_vertex function is useful for generating a single random color. However, if you are dealing with a large number of objects the random_vertex_generator function can be used to generate a large number of random vertices at once.

By default points will be generated in the range [-1.0, 1.0]. This can be changed by specifying a start and/or stop value. Note that points are generated in a cube.

Since this function returns a generator object you will need to wrap it in a list() or call the next() method on the generator. See the examples section below for usage.

syntax

random_vertex_generator(n, start=-1.0, stop=1.0):

parameters

n number of vertices

optional arguments

start minimum for vertex data
stop maximum for vertex data

return

Generator object for vertices.

examples

random points

def init():
   vertices = list(random_vertex_generator(1000))
   Global.points = PointCloud(vertices)

def display():
   lighting(False)
   scale(3.0)
   Global.points.draw()

random cubes

def init():
   Global.vertices = list(random_vertex_generator(50, -5, 5))

def display():
   lighting(False)
   draw(sphere, 0.5).for_each(Global.vertices)