Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRodolfo D. Arce S <rodolfo.arce.s@gmail.com>2011-05-19 22:34:48 (GMT)
committer Rodolfo D. Arce S <rodolfo.arce.s@gmail.com>2011-05-19 22:34:48 (GMT)
commit7e2c99eac909d717fa6265361452eb3ded8d3acc (patch)
tree751e2ebfdc3ff18d857af56c2820c1bf2e643dfe
parentd6ab7ab099c66554a80b06a5ad12ca656f0b69b1 (diff)
Added drawing function for tree class, playing with colors to see what looks better
-rw-r--r--main.py18
-rw-r--r--tree.py64
2 files changed, 43 insertions, 39 deletions
diff --git a/main.py b/main.py
index fae042d..67f57a1 100644
--- a/main.py
+++ b/main.py
@@ -3,6 +3,7 @@ from pygame import K_ESCAPE
from random import randint
from tree import Tree
+global window_h, window_w
window_h = 640
window_w = 480
@@ -12,7 +13,6 @@ screen = pygame.display.set_mode( (window_h, window_w) )
pygame.display.set_caption("Ranger")
# Tree
-tree_color = [51, 204, 0]
tree_height = tree_width = 40
tree_radius = 15
trees = []
@@ -25,15 +25,8 @@ screen.fill(bg_color)
number_trees = 160
while number_trees != 0:
trees.append(Tree(screen, \
- (randint(0,5), randint(0,255), randint(0,5) ), \
- window_h, \
- window_w, \
- (randint(0,window_h), randint(0,window_w)) , 15, 20, 20) )
+ (randint(0,window_h), randint(0,window_w)) , randint(10,20) ) )
number_trees -=1
-
-
-
-
while True:
for event in pygame.event.get():
@@ -43,9 +36,14 @@ while True:
keyboard = pygame.key.get_pressed()
if keyboard[K_ESCAPE]:
exit()
+
+ screen.fill(bg_color)
+
+ #for arbol in trees:
+ # trees.remove(arbol)
for arbol in trees:
- trees.remove(arbol)
+ arbol.draw()
pygame.display.update()
clock.tick(60)
diff --git a/tree.py b/tree.py
index d6f2940..dbfd6cf 100644
--- a/tree.py
+++ b/tree.py
@@ -2,64 +2,70 @@ import pygame
from random import randint
class Tree:
- def __init__(self, surface, tree_color, window_h, window_w, position, tree_size, height, width):
+ def __init__(self, surface, position, tree_size):
self.position = position
- self.height = height
- self.width = width
+ self.height = 10
+ self.width = 10
+ self.circle_w = randint (6,8)
self.size = tree_size
+ self.circle1 = self.size * randint (1,2)
+ self.circle2 = self.size * randint (1,2)
self.surface = surface
- self.color = tree_color
- pygame.draw.rect( self.surface, self.color, \
+ self.color_circle = (randint(0,3), randint(100,200), randint(0,3))
+ self.color_rect = (5, randint(100,200), 5)
+
+ def draw(self):
+ pygame.draw.rect( self.surface, self.color_rect, \
( (self.position[0] - self.height/2), \
(self.position[1] - self.width/2), \
self.size, \
self.size), \
0)
- pygame.draw.circle(self.surface, self.color, \
+ pygame.draw.circle(self.surface, self.color_circle, \
((self.position[0] + self.height/2), \
(self.position[1] + self.width/2)), \
- self.size*randint(1,2), \
- 8)
+ self.circle1, \
+ self.circle_w)
- pygame.draw.circle(self.surface, self.color, \
+ pygame.draw.circle(self.surface, self.color_circle, \
((self.position[0]), \
(self.position[1] + self.width/2)), \
- tree_size*randint(1,2), \
- 1)
+ self.circle2, \
+ self.circle_w)
- pygame.draw.circle(self.surface, self.color, \
+ pygame.draw.circle(self.surface, self.color_circle, \
((self.position[0] + self.height/2), \
(self.position[1])), \
- tree_size*randint(1,2), \
- 8)
+ self.circle1, \
+ self.circle_w)
- pygame.draw.circle(self.surface, self.color, \
+ pygame.draw.circle(self.surface, self.color_circle, \
((self.position[0] - self.height/2), \
(self.position[1] - self.width/2)), \
- tree_size*randint(1,2), \
- 8)
+ self.circle2, \
+ self.circle_w)
- pygame.draw.circle(self.surface, self.color, \
+ pygame.draw.circle(self.surface, self.color_circle, \
((self.position[0]), \
(self.position[1] - self.width/2)), \
- tree_size*randint(1,2), \
- 8)
+ self.circle1, \
+ self.circle_w)
- pygame.draw.circle(self.surface, self.color, \
+ pygame.draw.circle(self.surface, self.color_circle, \
((self.position[0] - self.height/2), \
(self.position[1])), \
- tree_size*randint(1,2), \
- 8)
+ self.circle2, \
+ self.circle_w)
- pygame.draw.circle(self.surface, self.color, \
+ pygame.draw.circle(self.surface, self.color_circle, \
((self.position[0] + self.height/2), \
(self.position[1]) - self.width/2), \
- tree_size*randint(1,2), \
- 8)
+ self.circle1, \
+ self.circle_w)
- pygame.draw.circle(self.surface, self.color, \
+ pygame.draw.circle(self.surface, self.color_circle, \
((self.position[0] - self.height/2), \
(self.position[1]) + self.width/2), \
- tree_size*randint(1,2), \
- 8)
+ self.circle2, \
+ self.circle_w)