Skip to content

Commit

Permalink
Sample shape program, using lines.
Browse files Browse the repository at this point in the history
  • Loading branch information
pvcraven committed Apr 15, 2020
1 parent 44f039d commit a2c9909
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
22 changes: 17 additions & 5 deletions arcade/examples/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
RECT_WIDTH = 50
RECT_HEIGHT = 50

NUMBER_OF_SHAPES = 200
NUMBER_OF_SHAPES = 500


class Shape:

""" Generic base shape class """
def __init__(self, x, y, width, height, angle, delta_x, delta_y,
delta_angle, color):
self.x = x
Expand Down Expand Up @@ -73,6 +73,13 @@ def draw(self):
arcade.draw_rectangle_filled(self.x, self.y, self.width, self.height,
self.color, self.angle)

class Line(Shape):

def draw(self):
arcade.draw_line(self.x, self.y,
self.x + self.width, self.y + self.height,
self.color, 2)


class MyGame(arcade.Window):
""" Main application class. """
Expand Down Expand Up @@ -107,14 +114,19 @@ def setup(self):
blue = random.randrange(256)
alpha = random.randrange(256)

shape_type = random.randrange(2)
# shape_type = random.randrange(3)
shape_type = 2

if shape_type == 0:
shape = Rectangle(x, y, width, height, angle, d_x, d_y,
d_angle, (red, green, blue, alpha))
else:
elif shape_type == 1:
shape = Ellipse(x, y, width, height, angle, d_x, d_y,
d_angle, (red, green, blue, alpha))
d_angle, (red, green, blue, alpha))
elif shape_type == 2:
shape = Line(x, y, width, height, angle, d_x, d_y,
d_angle, (red, green, blue, alpha))

self.shape_list.append(shape)

def on_update(self, dt):
Expand Down
28 changes: 23 additions & 5 deletions arcade/examples/shapes_buffered.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
RECT_WIDTH = 50
RECT_HEIGHT = 50

NUMBER_OF_SHAPES = 200
NUMBER_OF_SHAPES = 500


class Shape:

""" Generic base shape class """
def __init__(self, x, y, width, height, angle, delta_x, delta_y,
delta_angle, color):
self.x = x
Expand Down Expand Up @@ -96,6 +96,19 @@ def __init__(self, x, y, width, height, angle, delta_x, delta_y,
self.shape_list = arcade.ShapeElementList()
self.shape_list.append(shape)

class Line(Shape):

def __init__(self, x, y, width, height, angle, delta_x, delta_y,
delta_angle, color):

super().__init__(x, y, width, height, angle, delta_x, delta_y,
delta_angle, color)

shape = arcade.create_line(0, 0,
self.width, self.height,
self.color, 2)
self.shape_list = arcade.ShapeElementList()
self.shape_list.append(shape)

class MyGame(arcade.Window):
""" Main application class. """
Expand Down Expand Up @@ -130,14 +143,19 @@ def setup(self):
blue = random.randrange(256)
alpha = random.randrange(256)

shape_type = random.randrange(2)
# shape_type = random.randrange(3)
shape_type = 2

if shape_type == 0:
shape = Rectangle(x, y, width, height, angle, d_x, d_y,
d_angle, (red, green, blue, alpha))
else:
elif shape_type == 1:
shape = Ellipse(x, y, width, height, angle, d_x, d_y,
d_angle, (red, green, blue, alpha))
d_angle, (red, green, blue, alpha))
elif shape_type == 2:
shape = Line(x, y, width, height, angle, d_x, d_y,
d_angle, (red, green, blue, alpha))

self.shape_list.append(shape)

def on_update(self, dt):
Expand Down

0 comments on commit a2c9909

Please sign in to comment.