예제 #1
0
def draw_pine(top, radius, nrows):
    for i in range(1, nrows + 1):
        if i % 2 == 0:
            gl.current_color('green')
            offset = (i // 2) * 2 * radius - radius
        else:
            gl.current_color('light green')
            offset = (i // 2) * 2 * radius

        for j in range(i):
            gl.disc(j * 2 * radius - offset + top[0], top[1] - i * radius,
                    radius)
import pocketgl as gl
import time
import math
import random

gl.init_window('My game', 1radius0, 600)

t = 0
ballx = 400
bally = 300
radius = radius
velx = random.randrange(-10, 10)
vely = random.randrange(-10, 10)
while True:
    gl.clear_screen()
    gl.current_color(0, 0, 0)
    gl.disc(ballx, bally, radius)
    ballx += velx
    bally += vely

    if bally + radius> 600:
        vely = -vely

    if bally - radius < 0:
        vely = -vely

    if ballx + radius> 150:
        velx = -velx

    if ballx - radius < 0:
        velx = -velx
import pocketgl as gl
import time
import math

gl.init_window('My game', 800, 600)

t = 0
while True:
    gl.clear_screen()
    gl.current_color(int(127 + 127 * math.cos(t)),
                     int(127 + 127 * math.cos(2 * t)),
                     int(127 + 127 * math.cos(4 * t)))

    gl.disc(400, 300, 50)

    gl.refresh()
    time.sleep(1 / 60)
    t += 1 / 60
예제 #4
0
    for p in ps:
        if p.duration > p.lifetime:
            alive += [p]
    return alive


nb_particles = 300
particles = []
for i in range(nb_particles // 2):
    particles += [particle()]

t = 0
while True:
    gl.clear_screen()

    for p in reversed(particles):
        gl.current_color(255, int(255 - p.lifetime * (255 // p.duration)), 0)
        gl.disc(p.pos.x, p.pos.y,
                30 * (0.1 + (p.duration - p.lifetime) / p.duration))

    for p in particles:
        particle_update(p, math.sin(t) / 2 + 0.5)

    particles = alive_particles(particles)
    for i in range(nb_particles - len(particles)):
        particles += [particle()]

    gl.refresh()
    time.sleep(1 / 60)
    t += 1 / 60
예제 #5
0
        for j in range(i):
            gl.disc(j * 2 * radius - offset + top[0], top[1] - i * radius,
                    radius)


gl.init_window('Win', 800, 600, 'sky blue')

balls = [
    (350, 350),
    (450, 350),
    (400, 450),
]
balls_radius = 10
t = 0
while True:
    gl.clear_screen()

    draw_pine((400, 500), 30, 6)

    gl.current_color('red')

    i = 0
    for b in balls:
        gl.disc(b[0] + 10 * math.sin(2 * t + i),
                b[1] - 4 * math.cos(4 * t + 2 * i) + 4, balls_radius)
        i += 1

    gl.refresh()
    time.sleep(1 / 60)
    t += 1 / 60