From 9ebab046878bb95c4eddf5d9e0a4211c21c8948f Mon Sep 17 00:00:00 2001 From: Chris Ball Date: Wed, 21 May 2008 16:51:49 +0000 Subject: Add "tree" and "snow", by Dafydd Harries. --- (limited to 'data') diff --git a/data/graphics/snow b/data/graphics/snow new file mode 100644 index 0000000..4fc30f2 --- /dev/null +++ b/data/graphics/snow @@ -0,0 +1,73 @@ + +import pippy, pygame, sys +from pygame.locals import * +from random import * + +# always need to init first thing +pygame.init() + +# XO screen is 1200x900 +size = width, height = 1200, 900 + +# create the window and keep track of the surface +# for drawing into +screen = pygame.display.set_mode(size) + +# turn off the cursor +pygame.mouse.set_visible(False) + +bg_color = (0,0,0) + +xs = [] +ys = [] +dxs = [] +dys = [] +sizes = [] +nflakes = 1000 + +while pippy.pygame.next_frame(): + # if we don't have enough flakes, add one + if len(xs) < nflakes: + xs.append(randint(0, width)) + ys.append(0) + dxs.append(randint(-2, 2)) + size = expovariate(1) * 5 + sizes.append(int(size)) + dys.append(size * 2) + + # clear the screen + screen.fill(bg_color) + + for event in pygame.event.get(): + if event.type == QUIT: + sys.exit() + elif event.type == KEYDOWN: + if event.key == K_ESCAPE: + sys.exit() + + for x, y, size in zip(xs, ys, sizes): + c = 40 + int(float(y) / height * 215) + pygame.draw.circle( + screen, (c, c, c), (x, y), size) + + xs_ = [] + ys_ = [] + dxs_ = [] + dys_ = [] + sizes_ = [] + + for x, y, dx, dy, size in zip(xs, ys, dxs, dys, sizes): + if 0 <= x + dx <= width and 0 <= y + dy <= height: + xs_.append(x + dx) + ys_.append(y + int(dy)) + dxs_.append(dx) + dys_.append(dy) + sizes_.append(size) + + xs = xs_ + ys = ys_ + dxs = dxs_ + dys = dys_ + sizes = sizes_ + + pygame.display.flip() diff --git a/data/graphics/tree b/data/graphics/tree new file mode 100644 index 0000000..ab1c906 --- /dev/null +++ b/data/graphics/tree @@ -0,0 +1,71 @@ + +import pippy, pygame, sys +from pygame.locals import * +from random import * +import math + +# always need to init first thing +pygame.init() + +# XO screen is 1200x900 +size = width, height = 1200, 900 + +# create the window and keep track of the surface +# for drawing into +screen = pygame.display.set_mode(size) + +# turn off the cursor +pygame.mouse.set_visible(False) + +color = (250,250,250) +min_factor = 0.8 +max_factor = 0.9 +start_length = 130 +min_length = 40 +min_angle_delta = 0.4 +max_angle_delta = 0.5 + +# start the screen all black +bgcolor = (0,0,0) +screen.fill(bgcolor) + +def draw_tree(x, y, length, angle): + x2 = x + length * math.sin(angle) + y2 = y - length * math.cos(angle) + pygame.draw.line(screen, color, (x, y), (x2, y2)) + + if length > min_length: + # draw left branch + left_angle = angle - \\ + uniform(min_angle_delta, max_angle_delta) + left_length = length * \\ + uniform(min_factor, max_factor) + draw_tree(x2, y2, left_length, left_angle) + # draw middle branch + middle_length = length * \\ + uniform(min_factor, max_factor) + draw_tree(x2, y2, middle_length, angle) + # draw right branch + right_angle = angle + \\ + uniform(min_angle_delta, max_angle_delta) + right_length = length * \\ + uniform(min_factor, max_factor) + draw_tree(x2, y2, right_length, right_angle) + +# clear the screen +screen.fill(bgcolor) + +# draw a tree, starting at the bottom centre of the +# screen +draw_tree((width / 2), height - 20, start_length, 0) +pygame.display.flip() + +while pippy.pygame.next_frame(): + # chill until a key is pressed + for event in pygame.event.get(): + if event.type == QUIT: + sys.exit() + + if event.type == KEYDOWN: + if event.key == K_ESCAPE: + sys.exit() -- cgit v0.9.1