예제 #1
0
 def draw(self, shape):
     # Method drawing a shape on the canvas.
     self.__canvas.delete(self.__tmp_rendered)
     rendered_shape = None
     if shape['type'] == 'rectangle' and shape['mode'] == 'normal':
         rendered_shape = Rectangle(shape)
     elif shape['type'] == 'rectangle' and shape['mode'] == 'straight':
         rendered_shape = Square(shape)
     elif shape['type'] == 'oval' and shape['mode'] == 'normal':
         rendered_shape = Oval(shape)
     elif shape['type'] == 'oval' and shape['mode'] == 'straight':
         rendered_shape = Circle(shape)
     elif shape['type'] == 'line' and shape['mode'] == 'normal':
         rendered_shape = Line(shape)
     elif shape['type'] == 'line' and shape['mode'] == 'straight':
         rendered_shape = Diagonal(shape)
     shape_id = rendered_shape.draw_on(self.__canvas)
     return shape_id
"""Using the 'shapes' module to create shapes and control their attributes"""
from shapes import Triangle, Rectangle, Oval

# create a rectangle:
rect_1 = Rectangle(color=None)
# set the attributes:

#rect_1.set_width(200)
#rect_1.set_height(100)
#rect_1.set_color('blue')
# draw the rectangle:
rect_1.draw()

# create an oval:
oval_1 = Oval()

oval_1.set_width(100)
oval_1.set_height(50)
oval_1.set_color('yellow')
oval_1.set_x(100)
oval_1.set_y(200)

oval_1.draw()

rect_2 = Rectangle()

#rect_2.set_width(100)
#rect_2.set_height(150)
#rect_2.set_color('yellow')
#rect_2.set_x(100)
#rect_2.set_y(75)
예제 #3
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()
예제 #4
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()
예제 #5
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(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()
예제 #6
0
 def draw_oval(self, event):
     o = Oval(self.c)
     self.c.bind('<Button-1>', o.shape_create_start)
     self.c.bind('<B1-Motion>', o.shape_create)
예제 #7
0
rect1.set_width(200)
rect1.set_height(100)
rect1.set_color("blue")

#invoking draw method
rect1.draw()
# Paper.display()

# Challenge Rectangle
rect2 = Rectangle()
rect2.set_x(100)
rect2.set_y(100)
rect2.set_width(50)
rect2.set_height(150)
rect2.set_color("yellow")

#Challenge Oval

oval1 = Oval(100,100)
oval1.randomize()
oval1.draw()

rect2.draw()

# Challenge Triangle

tri1 = Triangle(5,5,100,5,100,200)
tri1.set_color("green")
tri1.draw()

Paper.display()
예제 #8
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()
예제 #9
0
from shapes import Paper, Triangle, Rectangle, Oval

paper = Paper()

rect1 = Rectangle()
rect1.set_width(200)
rect1.set_height(100)
rect1.set_color("orange")
rect1.draw()

rect2 = Rectangle()
rect2.set_width(200)
rect2.set_height(100)
rect2.set_color("yellow")
rect2.set_x(100)
rect2.set_y(100)
rect2.draw()

tri1 = Triangle(5, 5, 12, 5, 20, 30)
tri1.set_color("purple")
tri1.set_x(398)
tri1.set_y(500)
tri1.draw()

oval1 = Oval()
oval1.randomize(25, 100)
oval1.draw()

paper.display()
예제 #10
0
from shapes import Paper, Triangle, Rectangle, Oval

# Instance of paper
paper = Paper()

# instance of the rectangle
rect1 = Rectangle()
rect2 = Rectangle()
oval1 = Oval()
triangle = Triangle(0,0,20,0,40,40,color="black")

# Attributes
rect1.set_width(200)
rect1.set_height(100)
rect1.set_color("blue")


rect2.set_width(50)
rect2.set_height(150)
rect2.set_color("yellow")

oval1.randomize(smallest=20, largest=200)

# setting the position of the rect1
rect2.set_y(100)
rect2.set_x(100)


# draw the rectangle on paper
rect1.draw()
rect2.draw()
예제 #11
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()

ov1 = Oval()
ov1.randomize()
ov1.draw()

Paper.display()
예제 #12
0
from shapes import Triangle, Rectangle, Oval, Paper

sky = Rectangle()
sky.set_x(100)
sky.set_y(100)
sky.set_width(400)
sky.set_height(200)
sky.set_color("lightblue")
sky.draw()

sun = Oval()
sun.set_width(75)
sun.set_height(75)
sun.set_x(400)
sun.set_y(125)
sun.set_color("yellow")
sun.draw()

grass = Rectangle()
grass.set_x(100)
grass.set_y(300)
grass.set_width(400)
grass.set_height(200)
grass.set_color("green")
grass.draw()

wall = Rectangle()
wall.set_x(150)
wall.set_y(250)
wall.set_width(300)
wall.set_height(175)
# RENNIE THE ROBOT
# FUTURELEARN, SEPTEMBER 03,2017
# Ashmead ALI

from shapes import Triangle, Rectangle, Oval

mouth = Rectangle()
mouth.set_width(200)
mouth.set_height(100)
mouth.set_color('blue')
mouth.set_x(200)
mouth.set_y(450)
mouth.draw()

nose = Oval()
nose.set_width(100)
nose.set_height(100)
nose.set_color('red')
nose.set_x(250)
nose.set_y(250)
nose.draw()

left_eye = Rectangle()
left_eye.set_width(100)
left_eye.set_height(100)
left_eye.set_color('blue')
left_eye.set_x(100)
left_eye.set_y(100)
left_eye.draw()

left_pupil = Oval()
예제 #14
0
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.draw()
rect2.set_x(300)
rect2.set_y(100)

ov1 = Oval()
ov1.set_width(200)
ov1.set_height(100)
ov1.set_color("black")
ov1.set_x(200)
ov1.draw()

ov2 = Oval()
ov2.randomize()
ov2.draw()

tri = Triangle(5, 5, 100, 200)
tri.set_x(350)
tri.set_color("red")
tri.draw()
예제 #15
0
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)
cir.set_x(150)
예제 #16
0
rect1 = Rectangle()
rect1.set_width(100)
rect1.set_height(200)
rect1.set_color('blue')

rect1.draw()

rect2 = Rectangle()
rect2.set_width(50)
rect2.set_height(150)
rect2.set_color('red')
rect2.set_x(100)
rect2.set_y(100)

rect2.draw()

# Oval

oval1 = Oval()
oval1.set_color('white')
oval1.set_x(30)
oval1.set_y(90)
oval1.draw()

#Triangle

tri = Triangle()
tri.randomize()
tri.set_color('blue')
tri.draw()