def generate_color(x, z): m = 0.005 h = (pg.simplex2(x * m, z * m, 4) + 1) / 2 s = (pg.simplex2(-x * m, z * m, 4) + 1) / 2 v = (pg.simplex2(x * m, -z * m, 4) + 1) / 2 v = v * 0.5 + 0.5 return colorsys.hsv_to_rgb(h, s, v)
def setup(self): self.wasd = pg.WASD(self, speed=3) self.wasd.look_at((-5, 4, 5), (0, 0, 0)) self.context = pg.Context(pg.DirectionalLightProgram()) data = [] points = pg.poisson_disc(-4, -4, 4, 4, 1, 32) for x, z in points: noise = pg.simplex2(10 + x * 0.25, 10 + z * 0.25, 4) y = (noise + 1) / 1 shape = pg.Cone((x, 0, z), (x, y, z), 0.4, 36) data.extend(pg.interleave(shape.positions, shape.normals)) shape = pg.Sphere(3, 0.3, (x, y, z)) data.extend(pg.interleave(shape.positions, shape.normals)) self.context.position, self.context.normal = ( pg.VertexBuffer(data).slices(3, 3)) self.plane = pg.Context(pg.DirectionalLightProgram()) self.plane.object_color = (1, 1, 1) shape = pg.Plane((0, -0.1, 0), (0, 1, 0), 5) data = pg.interleave(shape.positions, shape.normals) self.plane.position, self.plane.normal = (pg.VertexBuffer(data).slices( 3, 3)) self.axes = pg.Context(pg.SolidColorProgram()) self.axes.color = (0.3, 0.3, 0.3) self.axes.position = pg.VertexBuffer(pg.Axes(100).positions)
def setup(self): self.wasd = pg.WASD(self, speed=3) self.wasd.look_at((-5, 4, 5), (0, 0, 0)) self.context = pg.Context(pg.DirectionalLightProgram()) data = [] points = pg.poisson_disc(-4, -4, 4, 4, 1, 32) for x, z in points: noise = pg.simplex2(10 + x * 0.25, 10 + z * 0.25, 4) y = (noise + 1) / 1 shape = pg.Cone((x, 0, z), (x, y, z), 0.4, 36) data.extend(pg.interleave(shape.positions, shape.normals)) shape = pg.Sphere(3, 0.3, (x, y, z)) data.extend(pg.interleave(shape.positions, shape.normals)) self.context.position, self.context.normal = ( pg.VertexBuffer(data).slices(3, 3)) self.plane = pg.Context(pg.DirectionalLightProgram()) self.plane.object_color = (1, 1, 1) shape = pg.Plane((0, -0.1, 0), (0, 1, 0), 5) data = pg.interleave(shape.positions, shape.normals) self.plane.position, self.plane.normal = ( pg.VertexBuffer(data).slices(3, 3)) self.axes = pg.Context(pg.SolidColorProgram()) self.axes.color = (0.3, 0.3, 0.3) self.axes.position = pg.VertexBuffer(pg.Axes(100).positions)
def noise(x, z): a = pg.simplex2(-x * 0.01, -z * 0.01, 4) b = pg.simplex2(x * 0.1, z * 0.1, 4) return (a + 1) * 16 + b / 10