コード例 #1
0
 def __init__(self, occupied):
     self.occupied = occupied
     self.context = pg.Context(pg.DirectionalLightProgram())
     self.context.object_color = pg.hex_color(random.choice(COLORS))
     self.context.position = self.positions = pg.VertexBuffer()
     self.context.normal = self.normals = pg.VertexBuffer()
     self.restart()
コード例 #2
0
ファイル: cuboids.py プロジェクト: bobbybabra/pg
 def setup(self):
     self.wasd = pg.WASD(self, speed=8)
     self.wasd.look_at((-10, 0, 0), (0, 0, 0))
     # cuboids
     self.context = pg.Context(pg.DirectionalLightProgram())
     self.context.use_color = True
     self.context.ambient_color = (0.5, 0.5, 0.5)
     self.context.light_color = (0.5, 0.5, 0.5)
     self.context.light_direction = pg.normalize((-1, 1, 1))
     data = []
     n = 16
     for x in range(256):
         z = random.randint(-n, n)
         y = random.randint(-n, n)
         cuboid = pg.Cuboid(x, x + 1, y - 0.5, y + 0.5, z - 0.5, z + 0.5)
         color = pg.hex_color(random.randint(0, 0xffffff))
         colors = [color] * len(cuboid.positions)
         data.extend(pg.interleave(
             cuboid.positions, cuboid.normals, colors))
     self.context.position, self.context.normal, self.context.color = (
         pg.VertexBuffer(data).slices(3, 3, 3))
     # bullets
     self.bullet = pg.Context(pg.DirectionalLightProgram())
     self.bullet.ambient_color = (0.5, 0.5, 0.5)
     self.bullet.light_color = (0.5, 0.5, 0.5)
     sphere = pg.Sphere(3, 0.05, (0, 0, 0))
     self.bullet.position = pg.VertexBuffer(sphere.positions)
     self.bullet.normal = pg.VertexBuffer(sphere.normals)
     self.bullets = []
     # crosshairs
     self.crosshairs = pg.Context(pg.SolidColorProgram())
     self.crosshairs.position = pg.VertexBuffer(pg.Crosshairs().positions)
コード例 #3
0
ファイル: cuboids.py プロジェクト: studiovc/pg
 def setup(self):
     self.wasd = pg.WASD(self, speed=8)
     self.wasd.look_at((-10, 0, 0), (0, 0, 0))
     # cuboids
     self.context = pg.Context(pg.DirectionalLightProgram())
     self.context.use_color = True
     self.context.ambient_color = (0.5, 0.5, 0.5)
     self.context.light_color = (0.5, 0.5, 0.5)
     self.context.light_direction = pg.normalize((-1, 1, 1))
     data = []
     n = 16
     for x in range(256):
         z = random.randint(-n, n)
         y = random.randint(-n, n)
         cuboid = pg.Cuboid(x, x + 1, y - 0.5, y + 0.5, z - 0.5, z + 0.5)
         color = pg.hex_color(random.randint(0, 0xffffff))
         colors = [color] * len(cuboid.positions)
         data.extend(pg.interleave(
             cuboid.positions, cuboid.normals, colors))
     self.context.position, self.context.normal, self.context.color = (
         pg.VertexBuffer(data).slices(3, 3, 3))
     # bullets
     self.bullet = pg.Context(pg.DirectionalLightProgram())
     self.bullet.ambient_color = (0.5, 0.5, 0.5)
     self.bullet.light_color = (0.5, 0.5, 0.5)
     sphere = pg.Sphere(3, 0.05, (0, 0, 0))
     self.bullet.position = pg.VertexBuffer(sphere.positions)
     self.bullet.normal = pg.VertexBuffer(sphere.normals)
     self.bullets = []
     # crosshairs
     self.crosshairs = pg.Context(pg.SolidColorProgram())
     self.crosshairs.position = pg.VertexBuffer(pg.Crosshairs().positions)
コード例 #4
0
ファイル: moving_spheres.py プロジェクト: Emilgardis/pg
from math import sin, cos, pi
import pg

RED = 0xF04326
YELLOW = 0xFAC02D
GREEN = 0x1AB243
BLUE = 0x1256D1

COLORS = [pg.hex_color(x) for x in [RED, YELLOW, GREEN, BLUE]]

class Window(pg.Window):
    def setup(self):
        self.font = pg.Font(self, 0, '/Library/Fonts/Arial.ttf', 24)
        self.wasd = pg.WASD(self, speed=5)
        self.wasd.look_at((14, 0, 0), (0, 0, 0))
        self.context = pg.Context(pg.DirectionalLightProgram())
        self.sphere = pg.Sphere(5, 0.4, (0, 0, 0))
        self.context.ambient_color = (0.4, 0.4, 0.4)
        self.context.light_color = (0.6, 0.6, 0.6)
    def draw(self):
        self.clear()
        self.context.camera_position = self.wasd.position
        matrix = self.wasd.get_matrix()
        matrix = matrix.perspective(65, self.aspect, 0.01, 100)
        for z in range(-2, 3):
            for x in range(-10, 11):
                y = sin(self.t * pi / 4 + x * 0.5 + z * pi) * 3
                model_matrix = pg.Matrix().translate((x, y, z * 3))
                self.context.model_matrix = model_matrix
                self.context.matrix = matrix * model_matrix
                self.context.object_color = COLORS[(z + x) % len(COLORS)]
コード例 #5
0
from math import sin, cos, pi
import pg

RED = 0xF04326
YELLOW = 0xFAC02D
GREEN = 0x1AB243
BLUE = 0x1256D1

COLORS = [pg.hex_color(x) for x in [RED, YELLOW, GREEN, BLUE]]


class Window(pg.Window):
    def setup(self):
        self.font = pg.Font(self, 0, '/Library/Fonts/Arial.ttf', 24)
        self.wasd = pg.WASD(self, speed=5)
        self.wasd.look_at((14, 0, 0), (0, 0, 0))
        self.context = pg.Context(pg.DirectionalLightProgram())
        self.sphere = pg.Sphere(5, 0.4, (0, 0, 0))
        self.context.ambient_color = (0.4, 0.4, 0.4)
        self.context.light_color = (0.6, 0.6, 0.6)

    def draw(self):
        self.clear()
        self.context.camera_position = self.wasd.position
        matrix = self.wasd.get_matrix()
        matrix = matrix.perspective(65, self.aspect, 0.01, 100)
        for z in range(-2, 3):
            for x in range(-10, 11):
                y = sin(self.t * pi / 4 + x * 0.5 + z * pi) * 3
                model_matrix = pg.Matrix().translate((x, y, z * 3))
                self.context.model_matrix = model_matrix