Exemplo n.º 1
0
from shapes import Triangle, Rectangle, Oval, Paper

rect1 = Rectangle()

rect1.set_width(200)
rect1.set_height(100)
rect1.set_color("blue")
rect1.draw()

rect2 = Rectangle()

rect2.set_width(50)
rect2.set_height(150)
rect2.set_color("yellow")
rect2.set_x(100)
rect2.set_y(100)
rect2.draw()

oval1 = Oval()

oval1.randomize()
oval1.draw()

tri1 = Triangle(5, 5, 100, 5, 100, 200)
tri1.draw()

Paper.display()
Exemplo n.º 2
0
rectangle1.set_height(100)
rectangle1.set_color("blue")
rectangle1.set_x(50)
rectangle1.set_y(250)

triangle1 = Triangle()
# triangle1.randomise()
triangle1.set_color("red")
triangle1.x=150
triangle1.y=150
triangle1.x2=150
triangle1.y2=200
triangle1.x3=200
triangle1.y3=150


oval1 = Oval()
# oval1.randomise()
oval1.set_color("green")
oval1.set_x(300)
oval1.set_y(300)
oval1.set_height(200)
oval1.set_width(200)

rectangle1.draw()
oval1.draw()
triangle1.draw()

root = Tk()
gui = MyGUI(root)
root.mainloop()
Exemplo n.º 3
0
rect1 = Rectangle()
rect1.set_width(200)
rect1.set_width(100)
rect1.set_color("blue")

rect1.draw()

rect2 = Rectangle()
rect2.set_x(100)
rect2.set_y(100)
rect2.set_width(100)
rect2.set_width(50)
rect2.set_color("red")

rect2.draw()

oval = Oval()
oval.randomize()

oval.draw()

triangle = Triangle(5, 5, 100, 100, 200, 100)
triangle.set_x(150)
triangle.set_y(250)
triangle.set_color("green")

triangle.draw()

paper.display()
Exemplo n.º 4
0
from shapes import Triangle, Rectangle, Oval, Paper

tri_sup = Triangle(50, 150, 20, 50, 80, 50)
tri_sup.draw()

Paper.display()
Exemplo n.º 5
0
from guizero import App, PushButton
from shapes import Triangle, Rectangle, Oval, Paper


def changeMe():
    r.move(20, -20)
    t2.move(5, 0)


app = App(width=600, height=600)
button = PushButton(app, changeMe, text="Click me")

p = Paper(app)
t = Triangle(p)
t.randomize()
t.draw()

t2 = Triangle(p)
t2.randomize()
t2.draw()

r = Rectangle(p)
r.randomize()
r.width = 400

r.draw()
r.color = 'red'
r.width = 20

app.display()
Exemplo n.º 6
0
from shapes import Triangle, Rectangle, Oval

rect = Rectangle()
rect.set_width(200)
rect.set_height(100)
rect.set_color('blue')
rect.draw()


square = Rectangle()
square.set_width(50)
square.set_height(50)
square.set_color('yellow')
square.set_x(120)
square.set_y(120)
square.draw()

tri = Triangle(5, 5, 100, 5, 100, 200)
tri.set_color('red')
tri.draw()
Exemplo n.º 7
0
class ResourceCounter:
    """A colored number for each resource representing how much has been selected
    along with up / down arrows to change how much is selected"""

    arrow_size_modifier = 0.3
    arrow_separation = 0.3
    arrow_color = common.BLACK

    font_x_offset = 0.15  # centering the font intuitively looks off-center :\
    font_y_offset = 0.1

    min_value = 0
    max_value = 15

    arrow_color = common.BLACK

    def __init__(self, x, y, resource, font):
        self.resource = resource
        self.font = font

        # counter number initialization
        self.num = SelectableText(font, '0', resource.value, 0, 0)

        font_height = get_font_height(font)
        font_width = get_font_width(font)
        # store this center location long-term for re-centering
        self.num_center = (int(x + ResourceCounter.font_x_offset * font_width),
                           int(y +
                               ResourceCounter.font_y_offset * font_height))
        self.num.rect.center = self.num_center

        # arrow initialization
        arrow_size = int(font_height * ResourceCounter.arrow_size_modifier)
        arrow_offset = int(font_height / 2 +
                           font_height * ResourceCounter.arrow_separation)
        self.up_arrow = Triangle(x, y - arrow_offset, arrow_size,
                                 ResourceCounter.arrow_color)
        self.down_arrow = Triangle(x,
                                   y + arrow_offset,
                                   arrow_size,
                                   ResourceCounter.arrow_color,
                                   pointed_up=False)

        # collision rects for detecting mouse / clicks
        self.up_arrow_collision = pygame.rect.Rect(0, 0, arrow_size,
                                                   arrow_size)
        self.up_arrow_collision.center = (x, y - arrow_offset)
        self.down_arrow_collision = pygame.rect.Rect(0, 0, arrow_size,
                                                     arrow_size)
        self.down_arrow_collision.center = (x, y + arrow_offset)

    def check_for_mouse(self, mouse_pos, mouse_click):
        """"Checks if the mouse is close enough to either arrows to highlight them,
        and if there was a click updates the counter (assuming bounds not passed)"""
        if self.up_arrow_collision.collidepoint(mouse_pos):
            # mouse is near the up arrow
            self.up_arrow.color = common.WHITE
            if mouse_click:
                cur_val = int(self.num.text)
                new_val = cur_val + 1

                # bounds checking
                if new_val <= ResourceCounter.max_value:
                    if cur_val == 9:
                        # need to re-initialize text obj for centering
                        self.num = SelectableText(self.font, str(new_val),
                                                  self.resource.value, 0, 0)
                        self.num.rect.center = self.num_center

                    else:
                        self.num.text = str(new_val)
                        self.num.deselect()

            # up arrow is being moused over, so down arrow shouldn't be selected
            self.down_arrow.color = ResourceCounter.arrow_color

        elif self.down_arrow_collision.collidepoint(mouse_pos):
            # mouse is near the down arrow
            self.down_arrow.color = common.WHITE
            if mouse_click:
                cur_val = int(self.num.text)
                new_val = cur_val - 1
                if new_val >= ResourceCounter.min_value:
                    if cur_val == 10:
                        # need to re-initialize text obj for centering
                        self.num = SelectableText(self.font, str(new_val),
                                                  self.resource.value, 0, 0)
                        self.num.rect.center = self.num_center

                    else:
                        self.num.text = str(cur_val - 1)
                        self.num.deselect()

            # down arrow is being moused over, so up arrow shouldn't be selected
            self.up_arrow.color = ResourceCounter.arrow_color

        else:
            # mouse is away; deselect all
            self.up_arrow.color = ResourceCounter.arrow_color
            self.down_arrow.color = ResourceCounter.arrow_color

    def draw(self, screen):
        self.up_arrow.draw(screen)
        self.num.draw(screen)
        self.down_arrow.draw(screen)
Exemplo n.º 8
0
path = Rectangle()
path.set_x(265)
path.set_y(425)
path.set_width(70)
path.set_height(75)
path.set_color("brown")
path.draw()

window_l = Rectangle()
window_l.set_x(175)
window_l.set_y(300)
window_l.set_width(65)
window_l.set_height(65)
window_l.set_color("lightblue")
window_l.draw()

window_r = Rectangle()
window_r.set_x(360)
window_r.set_y(300)
window_r.set_width(65)
window_r.set_height(65)
window_r.set_color("lightblue")
window_r.draw()

roof = Triangle(150, 250, 300, 150, 450, 250)
roof.set_color("purple")
roof.draw()

Paper.display()
Exemplo n.º 9
0
from shapes import Triangle, Rectangle, Oval
rect1 = Rectangle()
rect1.set_width(200)
rect1.set_height(100)
rect1.set_color("blue")
rect1.draw()
rect2 = Rectangle()
rect2.set_width(50)
rect2.set_height(150)
rect2.set_color("yellow")
rect2.set_x(150)
rect2.set_y(100)
rect2.draw()
tri = Triangle(5, 5, 100, 5, 100, 200)
tri.set_color("red")
tri.draw()
egg = Oval()
egg.set_color("tan")
egg.set_height(200)
egg.set_width(150)
egg.set_x(250)
egg.set_y(10)
egg.draw()
star1 = Triangle(5, 300, 55, 350, 105, 300, 'black')
star1.draw()
star2 = Triangle(5, 325, 55, 275, 105, 325, 'black')
star2.draw()
cir = Oval()
cir.set_color("green")
cir.set_height(50)
cir.set_width(50)