Example #1
0
    def test_get_total_perimeter_of_rectangles(self):
        r1 = shapes.Rectangle(geo.Point(1, 1), geo.Point(6, 4))
        r2 = shapes.Rectangle(geo.Point(5, 0), geo.Point(8, 2))
        r3 = shapes.Rectangle(geo.Point(7, 1), geo.Point(9, 4))
        r4 = shapes.Rectangle(geo.Point(4, 3), geo.Point(10, 6))

        actual = shapes.get_total_perimeter_of_rectangles([r1, r2, r3, r4])

        self.assertEqual(actual, 34)
Example #2
0
def create_pause_button():
    button_area = shapes.Rectangle(0, 0, 30, 30)
    button = rendering.Button(button_area)
    for x in (-4, 4):
        button_icon_left = shapes.Rectangle(0, 0, 6, 20)
        button_graphic_icon = rendering.SimpleMonoColouredGraphic(
            button_icon_left, colours.grey(100))
        button.add_and_center_canvas(button_graphic_icon)
        button_graphic_icon.translate((x, 0))
    return button
Example #3
0
def create_refresh_button():
    button_area = shapes.Rectangle(0, 0, 30, 30)
    button = rendering.Button(button_area)
    points = []
    dy = None
    y = 0
    for angle in range(0, 270, 15):
        point_outer = (-math.sin(math.radians(angle)) * 9,
                       -math.cos(math.radians(angle)) * 9)
        point_inner = (-math.sin(math.radians(angle)) * 7,
                       -math.cos(math.radians(angle)) * 7)
        points.append(point_outer)
        points.insert(0, point_inner)
        if dy is None:
            dy = (point_outer[1] - point_inner[1])
            y = (point_outer[1] + point_inner[1]) / 2
    polygon_points = [(5, y), (0, y + 5), (0, y - 5)]
    arrow = shapes.Polygon(polygon_points)
    open_circle = shapes.Polygon(points)
    shape_graphic = rendering.SimpleMonoColouredGraphic(
        open_circle, colours.GREEN)
    arrow_graphic = rendering.SimpleMonoColouredGraphic(arrow, colours.GREEN)
    old_pos = (open_circle.left, open_circle.down)
    button.add_and_center_canvas(shape_graphic)
    new_pos = (open_circle.left, open_circle.down)
    arrow.translate([x - y for x, y in zip(new_pos, old_pos)])
    button.add_canvas(arrow_graphic)

    return button
Example #4
0
def pixel_coord_to_box(pt):

    xmin = pt.x - 0.5
    ymin = pt.y - 0.5
    xmax = pt.x + 0.5
    ymax = pt.x + 0.5
    return shapes.Rectangle(xmin, ymin, xmax, ymax)
Example #5
0
    def load_skin_selection_menu():
        print("Loading the skin selection menu...")
        x_arrow, y_arrow = game.Game.LENGTH / 3.5, - game.Game.LENGTH / 6
        arrow_height, arrow_width = 34.6, 30
        rect_txt_p1 = - (y_arrow + arrow_height / 2), - x_arrow + arrow_width / 2
        rect_txt_p2 = - (y_arrow - arrow_height / 2), x_arrow - arrow_width / 2
        rect_window_p1 = rect_txt_p1[0] - 20, rect_txt_p1[1]  # 20 : shift between the two rectangles
        rect_window_p2 = rect_txt_p1[0] - 20 - Menu.SKIN_WINDOW_HEIGHT, rect_txt_p2[1]

        engine.init_engine()
        engine.set_keyboard_handler(Menu.keyboard_skin)
        _ = engine.GameObject(x_arrow, y_arrow, 0, 0, "arrow_right_skin", "gray", True)
        _ = engine.GameObject(- x_arrow, y_arrow, 0, 0, "arrow_left_skin", "gray", True)
        _ = shapes.Rectangle(rect_window_p1, rect_window_p2)
        Menu.skin_rect = shapes.Rectangle(rect_txt_p1, rect_txt_p2)
        Menu.display_skin()
def Miller():
	'''rectangle for main body'''
	r = s.Rectangle()
	r.setWidth(3)
	r.setColor('SlateGray')
	r.draw(-150,-200, 1.75, 90)
	
	'''cubes for side of library'''
	c = s.Cube()
	c.setWidth(3)
	c.draw(-330, -200, 1.75, 90)
	c.draw(380, -200, 1.75, 90)
	
	'''trapezoid for middle body'''
	t = s.Trapezoid()
	t.setWidth(3)
	t.setColor('SlateGray')
	t.draw(-150, -25, 1.75, 90)
	
	'''rectangles for top and steps'''
	r.draw(-35, 128, 1, 90, zpos = 40)
	r.draw(40, 228, 0.5, 90, zpos = 60)
	r.draw(-110,-300, 1.5, 90)
	
	'''pyramids for the tops of side buildings'''
	p = s.Pyramid()
	p.setWidth(3)
	p.setColor('Gray')
	p.draw(-155, -25, 1.75, 90)
	p.draw(555, -25, 1.75, 90)
	
#==================================================================
	# EXTENSION WORK 
	# stars on sides of miller instead of diamonds
	'''decoration'''
	star = s.Star2()
	star.setWidth(2)
	star.setColor("LightBlue")
	star.draw(-223, 155, .5, 12, zpos = 110)
	star.draw(427, 155, .5, 12, zpos = 110)
	
	# EXTENSION WORK 
	# star on top of miller instead of cross
	'''decoration'''
	star = s.Star2()
	star.setColor("Blue")
	star.setWidth(3)
	star.draw(125, 340, 0.75, 90, zpos = 80)
	
	#Extension Work
	#TREEEEEES
	t1 = tree.Tree(filename= 'project11extension2a.txt')
	t1.setIterations(3)
	t1.setColor('OliveDrab')
	t1.draw(-130, -300, 2, 90, zpos = 300)
	t2 = tree.Tree(filename= 'project11extension2b.txt')
	t2.setIterations(3)
	t2.setColor('LawnGreen')
	t2.draw(330, -300, 2, 90, zpos = 300)	
Example #7
0
def create_play_button():
    button_area = shapes.Rectangle(0, 0, 30, 30)
    button_icon = shapes.Polygon([(6, 0), (-6, -10), (-6, 10)])
    # self.button_graphic_background = rendering.SimpleMonoColouredGraphic(button_rect_background, )
    button_graphic_icon = rendering.SimpleMonoColouredGraphic(
        button_icon, colours.GREEN)
    button = rendering.Button(button_area)
    button.add_and_center_canvas(button_graphic_icon)
    return button
Example #8
0
 def create_food(self, position):
     from components import component
     food_id = self.create_entity()
     self.create_component(food_id, component.Food)
     self.create_component(food_id, component.Position, position=position)
     self.create_component(
         food_id, component.Render,
         shapes.Rectangle(color=colors.green, size=(8, 8)))
     return food_id
Example #9
0
    def __init__(self, boardSize, game):
        self.game = game
        self.boxSize = 80
        self.orbSize = 60
        self.boxPad = 5
        self.boardSize = boardSize
        self.gridBatch = pyglet.graphics.Batch()
        self.orbBatch = pyglet.graphics.Batch()
        self.transferring = 0

        # Drawing Background Rectangle
        bgVertices = (0, 0, self.boxPad + (self.boardSize *
                                           (self.boxSize + self.boxPad)), 0,
                      self.boxPad + (self.boardSize *
                                     (self.boxSize + self.boxPad)),
                      self.boxPad + (self.boardSize *
                                     (self.boxSize + self.boxPad)), 0,
                      self.boxPad + (self.boardSize *
                                     (self.boxSize + self.boxPad)))
        bgColors = constants.rgbColors[self.game.getCurrPlayer().color]
        self.bgRectangle = shapes.Rectangle(bgVertices, bgColors,
                                            self.gridBatch)

        # Drawing Tiles
        self.grid = []
        for i in range(boardSize):
            newRow = []
            for j in range(boardSize):
                # Corner and side tiles have different max
                if (i == 0 or i == boardSize - 1) and (j == 0
                                                       or j == boardSize - 1):
                    maxHold = 1
                elif (i == 0 or i == boardSize - 1) and (
                        0 < j < boardSize - 1) or (0 < i < boardSize - 1) and (
                            j == 0 or j == boardSize - 1):
                    maxHold = 2
                else:
                    maxHold = 3

                vertices = ((i * (self.boxSize + self.boxPad)) + self.boxPad,
                            (j * (self.boxSize + self.boxPad)) + self.boxPad,
                            (i * (self.boxSize + self.boxPad)) + self.boxPad +
                            self.boxSize, (j * (self.boxSize + self.boxPad)) +
                            self.boxPad, (i * (self.boxSize + self.boxPad)) +
                            self.boxPad + self.boxSize,
                            (j * (self.boxSize + self.boxPad)) + self.boxPad +
                            self.boxSize, (i * (self.boxSize + self.boxPad)) +
                            self.boxPad, (j * (self.boxSize + self.boxPad)) +
                            self.boxPad + self.boxSize)
                newRow.append(
                    shapes.Tile(vertices, constants.rgbColors["white"],
                                self.gridBatch, i, j, maxHold))
            self.grid.append(newRow)
Example #10
0
    def load_level_selection_menu():
        print("Loading the level selection menu...")
        pos_arrow = - game.Game.LENGTH // 5, 3 * Menu.LEVEL_LINE_HEIGHT + Menu.FONT_SIZE
        rect_p1 = game.Game.LENGTH // 2, game.Game.LENGTH // 2
        rect_p2 = - game.Game.LENGTH // 2, - game.Game.LENGTH // 2

        engine.init_engine()
        engine.set_keyboard_handler(Menu.keyboard_lvl)
        Menu.cursor_position = Menu.cursor_position_on_screen = 1
        assert Menu.select_arrow is None, "Select arrow already initialized"
        Menu.lvl_rect = shapes.Rectangle(rect_p1, rect_p2, color_edge="white")
        Menu.select_arrow = engine.GameObject(*pos_arrow, 0, 0, "select_arrow", "black")
        engine.add_obj(Menu.select_arrow)
        Menu.display_level()
Example #11
0
def create_visualise_bounding_button():
    button_area = shapes.Rectangle(0, 0, 30, 30)
    button = rendering.Button(button_area)
    icon_shapes = [
        shapes.Circle((8, 10), 7),
        shapes.LineSegment((5, 28), (28, 18))
    ]
    for shape in icon_shapes:
        if shape.has_area():
            shape_graphic = rendering.SimpleMonoColouredGraphic(
                shape, colours.BLUE)
        else:
            shape_graphic = rendering.SimpleOutlineGraphic(shape, colours.BLUE)
        button.add_canvas(shape_graphic)
        button.add_canvas(
            rendering.SimpleOutlineGraphic(shape.to_bounding_rectangle(),
                                           colours.RED))

    return button
Example #12
0
 def divide(self, tree_pos, tree_dimension, current_depth, to_depth):
     if current_depth < to_depth:
         split_dimension = 1 if tree_dimension[0] > tree_dimension[1] else 0
         other_dimension = (split_dimension + 1) % 2
         next_dimensions = [tree_dimension[0], tree_dimension[1]]
         next_dimensions[other_dimension] /= 2
         higher_pos = [tree_pos[0], tree_pos[1]]
         higher_pos[other_dimension] += next_dimensions[other_dimension]
         lower = self.divide(tree_pos, next_dimensions, current_depth + 1, to_depth)
         higher = self.divide(higher_pos, next_dimensions, current_depth + 1, to_depth)
         true_position = self.tree_to_true_position(higher_pos)
         axis = shapes.Axis(true_position[other_dimension], split_dimension)
         node = Node(axis, lower, higher)
         return node
     else:
         true_pos = self.tree_to_true_position(tree_pos)
         true_dim = self.tree_to_true_position(tree_dimension)
         leaf = Leaf(self, tree_pos, shapes.Rectangle(true_pos[0], true_pos[1], true_dim[0], true_dim[1]))
         self.leaves[int(tree_pos[0] + tree_pos[1] * self.tree_dimension[0])] = leaf
         return leaf
Example #13
0
def readShapesFromJson(data):
    shapes_list = []
    if 'Figures' not in data.keys():
        return []
    palette = data['Palette']
    i = 1
    for shape in data['Figures']:
        if (validate.validateShape(shape)):
            color = ''
            if 'color' in shape:
                if validate.validateColor(shape['color'], palette):
                    color = shape['color']
            if shape['type'] == 'point':
                shapes_list.append(shapes.Point(shape['x'], shape['y']))
            elif shape['type'] == 'polygon':
                points = []
                for point in shape['points']:
                    points.append(shapes.Point(point[0], point[1]))
                shapes_list.append(shapes.Polygon(points, color))
            elif shape['type'] == 'rectangle':
                point = shapes.Point(shape['x'], shape['y'])
                rect = shapes.Rectangle(point, shape['width'], shape['height'],
                                        color)
                shapes_list.append(rect)
            elif shape['type'] == 'square':
                point = shapes.Point(shape['x'], shape['y'])
                shapes_list.append(
                    shapes.Square(point, shape.get('size'), color))
            elif shape['type'] == 'circle':
                point = shapes.Point(shape['x'], shape['y'])
                shapes_list.append(
                    shapes.Circle(point, shape.get('radius'), color))
            else:
                print('Wrong type in Figure number', i, 'in file.')
        else:
            print('Wrong parameters in Figure number', i, 'in file.')
        i = i + 1
    return shapes_list
Example #14
0
def Miller():
    '''rectangle for main body'''
    r = s.Rectangle()
    r.setWidth(3)
    r.setColor('SlateGray')
    r.draw(-150, -200, 1.75, 90)
    '''cubes for side of library'''
    c = s.Cube()
    c.setWidth(3)
    c.draw(-330, -200, 1.75, 90)
    c.draw(380, -200, 1.75, 90)
    '''trapezoid for middle body'''
    t = s.Trapezoid()
    t.setWidth(3)
    t.setColor('SlateGray')
    t.draw(-150, -25, 1.75, 90)
    '''rectangles for top and steps'''
    r.draw(-35, 128, 1, 90, zpos=40)
    r.draw(40, 228, 0.5, 90, zpos=60)
    r.draw(-110, -300, 1.5, 90)
    '''pyramids for the tops of side buildings'''
    p = s.Pyramid()
    p.setWidth(3)
    p.setColor('Gray')
    p.draw(-155, -25, 1.75, 90)
    p.draw(555, -25, 1.75, 90)
    '''decoration'''
    d = s.Diamond()
    d.setWidth(2)
    d.setColor("LightBlue")
    d.draw(-263, 195, 1, 12, zpos=110)
    d.draw(447, 195, 1, 12, zpos=110)
    '''decoration'''
    cross = s.Cross()
    cross.setColor("Blue")
    cross.setWidth(4)
    cross.draw(130, 278, 0.35, 90, zpos=70)
Example #15
0
h.set_name()
h.get_name()
print("side is ", end="")
h.get_side()
print("\n")


o1 = shapes.Octagon()
o1.set_name()
o1.get_name()
print("side is ", end="")
o1.get_side()
print("\n")


r1 = shapes.Rectangle()
r1.set_name()
r1.get_name()
print("side is ", end="")
r1.get_side()
print("\n")


s1 = shapes.Square()
s1.set_name()
s1.get_name()
print("side is ", end="")
s1.get_side()
print("\n")

 def test_perimeter(self):
     rect = shapes.Rectangle(2, 4)
     expected = 12
     actual = rect.perimeter()
     self.assertEqual(expected, actual)
Example #17
0
import shapes
import pygame
import random

pygame.init()
size = [400, 300]
screen = pygame.display.set_mode(size)
print(screen)
pygame.display.set_caption('Snowflakes')
clock = pygame.time.Clock()
running = True
print('hi')
ground = shapes.Rectangle([0, 200], 400, 100, pygame.Color(0, 255, 0))
sky = shapes.Rectangle([0, 0], 400, 200, pygame.Color(0, 0, 255))
drawables = [ground, sky]
print('test')
paused = True
while running:
    clock.tick(30)
    screen.fill(pygame.Color(255, 255, 255))
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            exit()
        if event.type == pygame.KEYDOWN:
            if event.unicode == ' ':
                paused = not paused
    if paused:
        for thing in drawables:
            thing.draw(screen)
        pygame.display.update()
        continue
Example #18
0
def main():
	'''
	Draws a painting of a house with two trees, a hexagonal sun, 
	a parallelogram window, and grass
	'''

	'''Draws the frame of the painting'''
	rect1=shapes.Rectangle()
	rect1.setColor('brown')
	rect1.draw(-200,100,2.1,0)
	
	'''Draws the light blue sky inside frame of painting'''
	rect2=shapes.Rectangle()
	rect2.setColor('lightblue')
	rect2.draw(-190,95,2.0,0)
	
	'''Draws left half of green grass'''
	rect3=shapes.Rectangle()
	rect3.setDistance(100)
	rect3.setColor('green')
	rect3.draw(-190,-5,1.0,0)
	
	'''Draws right half of green grass'''
	rect4=shapes.Rectangle()
	rect4.setDistance(100)
	rect4.setColor('green')
	rect4.draw(10,-5,1.0,0)
	
	'''Draws tree from L-system in file systemCL.txt'''
	Tree1=tree.Tree()
	Tree1.lsystem.read('systemCL.txt')
	Tree1.setIterations(3)
	Tree1.draw(-130,-70)
	
	'''Draws tree from L-system in filed systemFL.txt'''
	Tree2=tree.Tree()
	Tree2.lsystem.read('systemFL.txt')
	Tree2.setIterations(4)
	Tree2.draw(130,-70)
	
	
	'''Draws rectangular red base of house'''
	rect5=shapes.Rectangle()
	rect5.setDistance(100)
	rect5.setColor('red')
	rect5.draw(-35,-25,0.5,0)
	
	'''Draws black trapezoidal roof'''
	trap1=shapes.Trapezoid()
	trap1.setDistance(30)
	trap1.setColor('black')
	trap1.draw(-36,-25,1.7,0)
	
	'''Draws yellow hexagonal sun oriented at 90'''
	hex1=shapes.Hexagon()
	hex1.setDistance(60)
	hex1.setColor('yellow')
	hex1.draw(-170,65,0.3,90)
	
	'''Draws white parallelogram shaped-window on roof'''
	para1=shapes.Parallelogram()
	para1.setDistance(40)
	para1.setColor('white')
	para1.draw(7,0,0.2,0)
	
	raw_input("Enter to exit")
 def test_area(self):
     rect = shapes.Rectangle(2, 4)
     expected = 8
     actual = rect.area()
     self.assertEqual(expected, actual)
Example #20
0
import shapes
import base

xy = [0, 0]

triangle = shapes.Triangle(xy, 1, 4)
circle = shapes.Circle(xy, 2)
square = shapes.Square(xy, 1)
ellipse = shapes.Ellipse(xy, 3, 2)
rectangle = shapes.Rectangle(xy, 14, 3)

mylist = [triangle, square, rectangle, circle, ellipse]

for item in mylist:
    if isinstance(item, base.Polygon):
        print(f"{item} located at {item.center} of size {item._size}")
    else:
        print(f"{item} located at {item.center} of radius {item.radius}")
Example #21
0
    def test_get_area_of_intersection_rectangles(self):
        r1 = shapes.Rectangle(geo.Point(0, 0), geo.Point(5, 3))
        r2 = shapes.Rectangle(geo.Point(3, 1), geo.Point(8, 4))

        actual = shapes.get_area_of_intersection_rectangles([r1, r2])
        self.assertEquals(actual, 4)
Example #22
0
# Implementation of classes for various animals and shapes (10 classes each) to learn concepts like virtual functions,  abstract classes, base class, derive class, interfaces, polymorphism , modularity and hierarchy in Python
import shapes
import animals 
import abstract

#s = abstract.Shape() This line gives an error since abstract classes cannot be instantiated
#A class that is derived from an abstract class cannot be instantiated unless all of its abstract methods are overridden.
#An abstract method can have an implementation in the abstract class! Even if they are implemented, designers of subclasses will be forced to override the implementation.
print("\n RECTANGLE\n")
r = shapes.Rectangle(100, 60)
r.printarea()
r.get_sides()
r.printperimeter()
r.draw()

print("\n SQUARE\n")
s = shapes.Square(4, 120)
s.printarea("square")
s.get_sides("square")
s.printperimeter("square")
s.diagonal()
s.draw()

print("\n EQUILATERAL TRIANGLE \n")
t = shapes.Triangle(3, 140)
t.printarea("equilateral triangle")
t.get_sides("equilateral triangle")
t.printperimeter("equilateral triangle")
t.draw()

print("\n RHOMBUS \n")
import shapes
import random

rect1 = shapes.Rectangle()

rect1.set_x(100)
rect1.set_y(100)
rect1.set_width(random.randint(50, 200))
rect1.set_height(random.randint(50, 100))
rect1.set_color("red")
rect1.draw()

rect2 = shapes.Rectangle()

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

oval1 = shapes.Oval()
oval1.randomize()
oval1.draw()
Example #24
0
	pm2 = core.Elements()
	disk1 = shapes.Disk((0,0), 100/2)
	disk2 = shapes.Disk((0,0), 400/2)
	pm1.add(utils.translate(disk1,(-200,0)))
	pm1.add(utils.translate(disk1,(200,0)))
	pm1.add(utils.translate(disk1,(0,200)))
	pm1.add(utils.translate(disk1,(0,-200)))
	pm2.add(utils.translate(disk2,(200,0)))
	pm2.add(utils.translate(disk2,(-200,0)))
	substraction3 = substraction(pm1,pm2)
	Wafer.add(utils.translate(pm2,(-1000,-3000)))
	Wafer.add(utils.translate(pm1,(-2000,-3000)))
	Wafer.add(utils.translate(substraction3,(0,-3000)))


	rect1 = shapes.Rectangle((-400,-400),(400,400))
	rect2 = shapes.Rectangle((-200,-400),(200,400))
	# rect3 = shapes.Rectangle((-200,-200),(200,200))
	substraction1 = substraction(rect1,rect2)

	rect2 = shapes.Rectangle((-600,-600),(600,600))

	substraction2 = substraction(rect2,substraction1)
	Wafer.add(utils.translate(substraction2,(-3000,-4000)))



	# Wafer.add(substraction2)


	layout = core.Layout('LIBRARY',unit=1e-06, precision=1e-09)
Example #25
0
"""
@author: Raymond F. Pauszek III, Ph.D. (2020)
script: try shapes package
"""

import matplotlib.pyplot as plt
import shapes

# ==============================================================================
c1 = shapes.Circle(0, 0, 1)
ax = plt.subplot(1, 1, 1, aspect="equal", projection="shape")
ax.plot_shape(c1)
c1b = c1
c1b.translate(2, 2)
ax.plot_shape(c1)

plt.show()

# ==============================================================================
shapesList = [c1]
shapesList.append(shapes.Circle(5, 5, 3))
shapesList.append(shapes.Square(0, 0, 2))
shapesList.append(shapes.Square(-5, -5, 7))
shapesList.append(shapes.Rectangle(0, 0, 2, 3.14))
shapesList.append(shapes.Rectangle(5, -5, 3.14, 6))

ax = plt.subplot(1, 1, 1, aspect="equal", projection="shape")
for sh in shapesList:
    ax.plot_shape(sh)
plt.show()
Example #26
0
	def __init__(self, map_id):
		self.__polygons = []
		self.__boundary_polygon = None
		self.__all_polygons = None # Includes all the obstacle polygons as well as boundary polygon
		self.__map_name = 'id_' + str(map_id) + '.polygons'
		print('Map name:', self.__map_name)

		self.__expansion_factor = 2.50
		self.__expanded_polygons = []

		self.__bbox_length = 250

		self.__rtree_idx = rtree.index.Index()

		print('Path:', self.__map_name)
		assert(os.path.isfile(self.__map_name))
		f = open(self.__map_name, 'r')
		first = True
		for line in f:
			line.strip()
			if len(line) != 0:
				if first:
					points_list = line.split(',')
					self.__width = int(points_list[0])
					self.__height = int(points_list[1])

					points_tuple = (0, 0, self.__width, 0, self.__width, self.__height, 0, self.__height)
					self.__boundary_polygon = shapes.Polygon(points_tuple)

					offset = 10
					points_tuple = (offset, offset, self.__width - offset, offset, self.__width - offset, self.__height - offset, offset, self.__height-offset)
					self.__imaginary_boundary = shapes.Polygon(points_tuple)
					first = False
				else:
					geometry_type = line.split(':')[0].strip()
					# print(geometry_type)
					points_string = line.split(':')[1]
					points_list = points_string.split(',')
					# print(points_list)
					points_list = [int(point) for point in points_list]
					points_tuple = tuple(points_list)
					polygon = None
					if geometry_type == 'polygon':
						polygon = shapes.Polygon(points_tuple)
						# print(' ')
						# print(polygon)
						
						# print('Expanded polygon:')
						e_polygon = shapes.Polygon(points_tuple, self.__expansion_factor)
						# print(e_polygon)
						self.__expanded_polygons.append(e_polygon)
					if geometry_type == 'square':
						centre = (points_tuple[0], points_tuple[1])
						length = points_tuple[2]
						# print(centre)
						# print(length)
						polygon = shapes.Square(centre, length)
					if geometry_type == 'rectangle':
						centre = (points_tuple[0], points_tuple[1])
						width = points_tuple[2]
						height = points_tuple[3]
						# print(centre)
						# print(length)
						polygon = shapes.Rectangle(centre, width, height)
						print(str(polygon))
					if geometry_type == 'circle':
						centre = (points_tuple[0], points_tuple[1])
						radius = points_tuple[2]
						num_approx_points = points_tuple[3]
						polygon = shapes.Circle(centre, radius, num_approx_points)
						# print(str(polygon))

					self.__rtree_idx.insert(len(self.__polygons), polygon.get_rtree_bbox(), obj=polygon)
					self.__polygons.append(polygon)
					
		self.__num_polygons = len(self.__polygons)
		self.__all_polygons = self.__polygons + [self.__boundary_polygon]
Example #27
0
lumpy.class_diagram()
del p, Line_Parabola


def f(x):
    return x + 1.0 / x**2


lumpy = Lumpy()

import Diff2

diff = []
for classname in dir(Diff2):
    if not classname.startswith('_'):
        diff.append(eval('Diff2.%s(f)' % classname))
lumpy.class_diagram()
del diff, Diff2, f, classname

import shapes

lumpy = Lumpy()
r = shapes.Rectangle((0, 0), 2, 3)
lumpy.class_diagram()
del r

lumpy = Lumpy()
w = shapes.Wheel((0, 0), 1)
lumpy.class_diagram()
del w
Example #28
0
def main():
    '''
	Draws a painting of a house with two trees, a hexagonal sun, 
	a parallelogram window, and grass
	'''
    '''Draws the frame of the painting'''
    rect1 = shapes.Rectangle()
    rect1.setColor('brown')
    rect1.draw(-200, 100, 2.1, 0)
    '''Draws the light blue sky inside frame of painting'''
    rect2 = shapes.Rectangle()
    rect2.setColor('lightblue')
    rect2.draw(-190, 95, 2.0, 0)
    '''Draws left half of green grass'''
    rect3 = shapes.Rectangle()
    rect3.setDistance(100)
    rect3.setColor('green')
    rect3.draw(-190, -5, 1.0, 0)
    '''Draws right half of green grass'''
    rect4 = shapes.Rectangle()
    rect4.setDistance(100)
    rect4.setColor('green')
    rect4.draw(10, -5, 1.0, 0)
    '''
	Draws tree from L-system in file lsys1.txt in whateverstyle the user inputs
	'''

    print(
        "Hello, welcome to the painting: Here you can paint a scene with trees, a house, a sun, and a window any way you want"
    )

    Tree1 = tree.Tree()
    Tree1.lsystem.read('lsys1.txt')
    Tree1.setIterations(3)
    answer1 = raw_input("What style would you like for the first tree: ")
    Tree1.setStyle(answer1)
    for i in ('jitter', 'jitter3'):
        if answer1 == i:
            '''
			If the style user input is either jitter or jitter 3 the tree
			is drawn in that style with whatever jitter value user inputs
			'''
            jitteranswer1 = float(
                raw_input(
                    "What would you like the jitter to be for the first tree: "
                ))
            Tree1.setJitter(jitteranswer1)

    Tree1.draw(-130, -70, 1)
    '''
	Draws tree from L-system in file sysTree3.txt, in whatever style the user inputs
	
	'''
    Tree2 = tree.Tree()
    Tree2.lsystem.read('sysTree3.txt')
    Tree2.setIterations(4)
    answer2 = raw_input("What style would you like for the second tree: ")
    Tree2.setStyle(answer2)
    for i in ('jitter', 'jitter3'):
        if answer2 == i:
            '''
			If the style user input is either jitter or jitter 3 the tree
			is drawn in that style with whatever jitter value user inputs
			'''
            jitteranswer1 = float(
                raw_input(
                    "What would you like the jitter to be for the second tree: "
                ))
            Tree1.setJitter(jitteranswer1)

    Tree2.draw(130, -40, 1)
    '''Draws rectangular red base of house in whatever style user inputs'''
    rect5 = shapes.Rectangle()
    rect5.setDistance(100)
    rect5.setColor('red')
    answer3 = raw_input("What style would you like for the house: ")
    rect5.setStyle(answer3)
    for i in ('jitter', 'jitter3'):
        if answer3 == i:
            '''
			If the style user inputs is either jitter or jitter 3 jitter for all sides
			of house drawn is controlled by user input
			'''
            jitteranswer1 = float(
                raw_input(
                    "What would you like the jitter to be for the first side: "
                ))
            rect5.setJitter(jitteranswer1)
            jitteranswer2 = float(
                raw_input(
                    "What would you like the jitter to be for the second side: "
                ))
            rect5.setJitter(jitteranswer2)
            jitteranswer3 = float(
                raw_input(
                    "What would you like the jitter to be for the third side: "
                ))
            rect5.setJitter(jitteranswer3)
            jitteranswer4 = float(
                raw_input(
                    "What would you like the jitter to be for the fourth side: "
                ))
            rect5.setJitter(jitteranswer4)
    rect5.draw(-35, -25, 0.5, 0)
    '''Draws black trapezoidal roof in whatever style user inputs'''
    trap1 = shapes.Trapezoid()
    trap1.setDistance(30)
    trap1.setColor('black')
    answer4 = raw_input("What style would you like for the roof: ")
    trap1.setStyle(answer4)
    for i in ('jitter', 'jitter3'):
        if answer4 == i:
            '''
			If the style user inputs is either jitter or jitter 3 jitter for all sides
			of roof drawn is controlled by user input
			'''
            jitteranswer1 = float(
                raw_input(
                    "What would you like the jitter to be for the first side: "
                ))
            trap1.setJitter(jitteranswer1)
            jitteranswer2 = float(
                raw_input(
                    "What would you like the jitter to be for the second side: "
                ))
            trap1.setJitter(jitteranswer2)
            jitteranswer3 = float(
                raw_input(
                    "What would you like the jitter to be for the third side: "
                ))
            trap1.setJitter(jitteranswer3)
            jitteranswer4 = float(
                raw_input(
                    "What would you like the jitter to be for the fourth side: "
                ))
            trap1.setJitter(jitteranswer4)

    trap1.draw(-36, -25, 1.7, 0)
    '''Draws yellow hexagonal sun oriented at 90 in whatever style user inputs'''
    hex1 = shapes.Hexagon()
    hex1.setDistance(60)
    hex1.setColor('yellow')
    answer5 = raw_input("What style would you like for the sun: ")
    hex1.setStyle(answer5)
    for i in ('jitter', 'jitter3'):
        if answer5 == i:
            '''
			If the style user inputs is either jitter or jitter 3 jitter for all sides
			of sun drawn is controlled by user input
			'''
            jitteranswer1 = float(
                raw_input(
                    "What would you like the jitter to be for the first side: "
                ))
            hex1.setJitter(jitteranswer1)
            jitteranswer2 = float(
                raw_input(
                    "What would you like the jitter to be for the second side: "
                ))
            hex1.setJitter(jitteranswer2)
            jitteranswer3 = float(
                raw_input(
                    "What would you like the jitter to be for the third side: "
                ))
            hex1.setJitter(jitteranswer3)
            jitteranswer4 = float(
                raw_input(
                    "What would you like the jitter to be for the fourth side: "
                ))
            hex1.setJitter(jitteranswer4)
            jitteranswer5 = float(
                raw_input(
                    "What would you like the jitter to be for the fifth side: "
                ))
            hex1.setJitter(jitteranswer5)
            jitteranswer6 = float(
                raw_input(
                    "What would you like the jitter to be for the sixth side: "
                ))
            hex1.setJitter(jitteranswer6)

    hex1.draw(-170, 65, 0.3, 90)
    '''Draws white parallelogram shaped-window on roof in whatever style user inputs'''
    para1 = shapes.Parallelogram()
    para1.setDistance(40)
    para1.setColor('white')
    answer6 = raw_input("What style would you like for the window: ")
    para1.setStyle(answer6)
    for i in ('jitter', 'jitter3'):
        if answer6 == i:
            '''
			If the style user inputs is either jitter or jitter 3 jitter for all sides
			of the paralellogram shaped window drawn is controlled by user input
			'''
            jitteranswer1 = float(
                raw_input(
                    "What would you like the jitter to be for the first side : "
                ))
            para1.setJitter(jitteranswer1)
            jitteranswer2 = float(
                raw_input(
                    "What would you like the jitter to be for the second side: "
                ))
            para1.setJitter(jitteranswer2)
            jitteranswer3 = float(
                raw_input(
                    "What would you like the jitter to be for the third side: "
                ))
            para1.setJitter(jitteranswer3)
            jitteranswer4 = float(
                raw_input(
                    "What would you like the jitter to be for the fourth side: "
                ))
            para1.setJitter(jitteranswer4)
    para1.draw(7, 0, 0.2, 0)

    raw_input("Enter to exit")
Example #29
0
#!/usr/bin/python3
import shapes

s1 = shapes.Shape(4,8)
print(s1)
r1 = shapes.Rectangle(5,10,6,8)
print(r1)
Example #30
0
def plot_sample(sample, x_limits, y_limits, **kwargs):
    plt.style.use(MPL_STYLE)
    fig = plt.figure(figsize=FIGSIZE, dpi=FIGDPI)
    for s in sample:
        plt.scatter(s.x, s.y, **kwargs)
    fig.axes[0].set_xlim(x_limits)
    fig.axes[0].set_ylim(y_limits)
    return fig

if __name__ == "__main__":

    radius = float(sys.argv[1])

    # shape = shapes.AxisAlignedRectangle(Vector([-1, 0]), Vector([5, 2]))

    # a = Vector([-10, -6])
    # b = Vector([-5, 5])
    # c = Vector([10, 0])
    # shape = shapes.Triangle(a, c, b)

    bl_corner = Vector([-4, -2])
    dimensions = Vector([8, 10])
    orientation = 60.0
    shape = shapes.Rectangle(bl_corner, dimensions, orientation)

    sample = poisson_sample_2d_square(radius, shape, draw_algorithm=False, max_sample_attempts=100)

    fig = plot_sample(sample, (shape.xmin, shape.xmax), (shape.ymin, shape.ymax), s=3.0, cmap=plt.cm.jet)

    plt.show()