Esempio n. 1
0
def draw_chezrep():
        world=World()
        canvas = world.ca(width=500, height=500, background='white')
	canvas.rectangle([[-150,-100], [150, 100]], outline='black', width=2, fill='white')
	canvas.rectangle([[-150,-100], [150, 15]], outline='black', width=2, fill='red')
        points = [[-150,-100], [-150,100], [0,15]]
        canvas.polygon(points, fill='blue')
        world.mainloop()
Esempio n. 2
0
    def __init__(self, interactive=False, delay=100):
        World.__init__(self)
        self.delay = delay
        self.title('AmoebaWorld')
        self.running = False

        self.make_canvas()
        if interactive:
            self.make_control_panel()
def draw_circle(cir):
    hello = World()
    e = hello.ca(width=window.width,
                 height=window.height,
                 background=window.color)
    e.circle([cir.point.x, cir.point.y],
             cir.radius,
             outline="green",
             fill="black")
    hello.mainloop()
Esempio n. 4
0
def flag_czech():
	world=World()
	canvas=world.ca(width=1500, height=500, background='white')
	points = [[0,00], [150, -100], [0, -200]]
	canvas.polygon(points, fill='blue4')
	points=[[0,00],[500,00],[500,-100],[150,-100],[0,00]]
	canvas.polygon(points, fill='white', outline='black')
	points=[[150,-100],[500,-100],[500,-200],[0,-200],[150,-100]]
	canvas.polygon(points, fill='red',outline='black')
	world.mainloop()
    def __init__(self, canvas_size=500, cell_size=5, interactive=False):
        World.__init__(self)
        self.title('CellWorld')
        self.canvas_size = canvas_size
        self.cell_size = cell_size

        # cells is a map from index tuples to Cell objects
        self.cells = {}

        if interactive:
            self.make_canvas()
            self.make_control()
    def __init__(self, interactive=False):
        World.__init__(self)
        self.title('TurtleWorld')

        # the interpreter executes user-provided code
        g = globals()
        g['world'] = self
        self.make_interpreter(g)

        # make the GUI
        self.setup()
        if interactive:
            self.setup_interactive()
def czech_flag():
	c=canvas()
	c.w=500
	c.h=500

	r1=rectangle()
	r1.color='red'

	r1.p1=point()
	r1.p1.x=-200
	r1.p1.y=-200

	r1.p2=point()
	r1.p2.x=200
	r1.p2.y=0

	r2=rectangle()
	r2.color='white'
	r2.p1=point()
	r2.p1.x=-200
	r2.p1.y=0

	r2.p2=point()
	r2.p2.x=200
	r2.p2.y=200

	world=World()
	can=world.ca(width=c.w,height=c.h,background='white')

	bbox1=[[r1.p1.x,r1.p1.y],[r1.p2.x,r1.p2.y]]
	can.rectangle(bbox1,outline='black',width=1,fill=r1.color)

	bbox2=[[r2.p1.x,r2.p1.y],[r2.p2.x,r2.p2.y]]
	can.rectangle(bbox2,outline='black',width=1,fill=r2.color)

	points = [[-200,-200], [-200, 200], [0, 0]]
	can.polygon(points, fill='blue')

	world.mainloop()
Esempio n. 8
0
def main():
	box = rectangle()
	box.width = 100.0
	box.height = 200.0
	box.ll = point()
	box.ll.x = 10.0
	box.ll.y=10.0
	box.ur = point()
	box.ur.x = 200.0
	box.ur.y=200.0
	box.color='red'
	bbox=[[box.ll.x,box.ll.y],[box.ur.x,box.ur.y]]
	world=World()
	canvas=world.ca(width=500, height=500, background='white')
	draw_rectangle(canvas,box)
	draw_point(canvas,box.ll)
	circle=Circle()
	circle.center=point()
	circle.center.x=100.0
	circle.center.y=100.0
	circle.radius=10.0
	draw_circle(canvas,circle)

	world.mainloop()
def main():
    # Create World object
    # print  sys.version_info
    world = World()
    # Create our canvas
    canvas = create_canvas(world, 500, 500, 'grey')
    # canvas = world.ca(width=500, height=500, background='white')
    # Create our rectangle
    my_rect = create_rectangle(100, 200, 'blue')
    # Create a new Point object
    new_point = Point()
    # Put new point at 0,0
    new_point.x = -30
    new_point.y = -30

    draw_point(canvas, new_point)

    my_circle = create_circle(new_point, 5, 'green')
    # draw_circle(canvas, my_circle)

    my_circle = create_circle(new_point, 30, 'red')
    # draw_circle(canvas, my_circle)


    # Polygon are made of points, so we should create a list of points
    point_a = Point(-100, -100)
    point_b = Point(50, 0)
    point_c = Point(-100, 100)

    my_points = (point_a, point_b, point_c)

    my_polygon = Polygon()
    # Create an attribute that is a list
    my_polygon.points = []
    # Append our point objects to the Polygon object's list
    my_polygon.points.append(point_a)
    my_polygon.points.append(point_b)
    my_polygon.points.append(point_c)

    # Add fill color attribute
    my_polygon.fill = 'blue'

    # After the polygon has all the points in question, we need a "draw_polygon"
    # function.
    draw_polygon(canvas, my_polygon)

    # Polygon are made of points, so we should create a list of points
    point_a = Point(-100, -100)
    point_b = Point(50, 0)
    point_c = Point(200, 0)
    point_d = Point(200,-100)
    my_points = (point_a, point_b, point_c, point_d)
    
    my_polygon = Polygon()
    # Create an attribute that is a list
    my_polygon.points = []
    # Append our point objects to the Polygon object's list
    my_polygon.points.append(point_a)
    my_polygon.points.append(point_b)
    my_polygon.points.append(point_c)
    my_polygon.points.append(point_d)
    
    # Add fill color attribute
    my_polygon.fill = 'red'
    # After the polygon has all the points in question, we need a "draw_polygon"
    # function.
    draw_polygon(canvas, my_polygon)


    # Polygon are made of points, so we should create a list of points
    point_a = Point(-100, 100)
    point_b = Point(50, 0)
    point_c = Point(200, 0)
    point_d = Point(200, 100)
    my_points = (point_a, point_b, point_c, point_d)
    
    my_polygon = Polygon()
    # Create an attribute that is a list
    my_polygon.points = []
    # Append our point objects to the Polygon object's list
    my_polygon.points.append(point_a)
    my_polygon.points.append(point_b)
    my_polygon.points.append(point_c)
    my_polygon.points.append(point_d)
    
    # Add fill color attribute
    my_polygon.fill = 'white'
    # After the polygon has all the points in question, we need a "draw_polygon"
    # function.
    draw_polygon(canvas, my_polygon)


    world.mainloop()
Esempio n. 10
0
	rect2.corner.y += dy
	return rect2.corner.x, rect2.corner.y, rect2 ==rect 

# print move_rectangleCopy(box, 20, 40)
# print hasattr(box.corner, 'x')
# print type(box)


#--------------------------------------------------------------------------------
"""
ex.15.4 swampy
"""

from swampy.World import World

world = World()
# canvas = world.ca(width=500, height=500, background='white')
# bbox = [[-150, -100], [150, 100]]
# canvas.rectangle(bbox, outline='black', width=2, fill='green4')
# canvas.circle([-25, 0], 70, outline=None, fill='red')

def draw_rectangle(canvas, rectangle):
	canvas = world.ca(width=400, height=500, background='gray')
	rectangle = Rectangle()


world.mainloop()



Esempio n. 11
0
def draw_point(x,y):
        point=World()
        canvas=point.ca(width=500,height=500,background='white')
        bbox=[[x,y],[x,y]]
        canvas.rectangle(bbox)
        point.mainloop()
Esempio n. 12
0
def draw_point(c,p):
	world=World()
	can=world.ca(width=c.w,height=c.h,background='white')
	pt=[[p.x,p.y],[p.x,p.y]]
	can.rectangle(pt)
	world.mainloop()
Esempio n. 13
0
def draw_circle(c,cir):
	world=World()
	can=world.ca(width=c.w,height=c.h,background='white')
	can.circle(cir.o,cir.r,outline='black',width=2,fill='red')
	world.mainloop()
Esempio n. 14
0
def draw_rectangle(c,r):
	world=World()
	can=world.ca(width=c.w,height=c.h,background='white')
	bbox=[[r.p1.x,r.p1.y],[r.p2.x,r.p2.y]]
	can.rectangle(bbox,outline='black',width=0,fill=r.color)
	world.mainloop()
Esempio n. 15
0
    rect1=Rectangle()
    rect2=Rectangle()
    rect1.color='white'
    rect2.color='red'
    dimensions(rect1,300,100)
    dimensions(rect2,300,100)
    corner(rect1,-150,0)
    corner(rect2,-150,-100)
    print (find_center(rect1))

    circle=Circle()
    center(circle,-25,0)
    circle.radius=70
    circle.color='blue'


    world=World()
    canvas = world.ca(width=500, height=500, background='white')

    draw_point(canvas,point1)
    draw_rectangle(canvas, rect1)
    draw_rectangle(canvas, rect2)
    points=[[-150,-100],[-150,100],[-150+(100*(3**0.5)),0]]
    canvas.polygon(points,fill='blue')

    world.mainloop()



Esempio n. 16
0
from Tkinter import *
from swampy.World import World
def drawrect(can,rec,col):
    can.rectangle(rec,outline='green',width=5,fill=col)
    
def drawpoint(can,point):
    can.rectangle(point,outline='white',fill='white')
    
def czhech(can):
    can.polygon([[-50,-50],[100,-50],[100,10],[10,10]],fill='red')
    can.polygon([[10,10],[100,10],[100,70],[-50,70]],fill='white')
    can.polygon([[-50,-50],[10,10],[-50,70]],fill='blue')
    world.mainloop()
    
world=World()
col='black'
can=world.ca(width=500,height=400,background='black')
rec=[[-100,-100],[100,100]]
point=[[150,150],[150,150]]
#drawrect(can,rec,col)
#drawpoint(can,point)
czhech(can)
Esempio n. 17
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from swampy.World import World

world = World()


class Canvas(object):
    def __init__(self, width, height, background):
        self.width = width
        self.height = height
        self.background = background


class Rectangle(object):
    def __init__(self, c1x, c1y, c2x, c2y, outline, width, fill):
        self.corner1 = [c1x, c1y]
        self.corner2 = [c2x, c2y]
        self.outline = outline
        self.width = width
        self.fill = fill


class Point(object):
    def __init__(self, x, y):
        self.x = x
        self.y = y


class Circle(object):
    def __init__(self, x, y, rad, outline, width, fill):
def move_rectangle2(rect, dx, dy):
    """A version of move_rectangle that creates and returns a new Rectangle 
    instead of modifying the old one.
    
    """
    # copy both rect and the Point object representing its corner
    new_rect = copy.deep_copy(rect)
    
    # modify the Point coords
    new_rect.corner.x += dx
    new_rect.corner.y += dy
    
    return new_rect
    
# Draw something resembling the flag of Bangladesh
world = World()
canvas = world.ca(width=500, height=500, background='white')
bbox = [[-150,-100], [150, 100]]
canvas.rectangle(bbox, outline='black', width=2, fill='green4')
canvas.circle([-25,0], 70, outline=None, fill='red')
world.mainloop()

# solution to exercise 4.1 and 4.2
def draw_rectangle(canvas, rect):
    """Takes a Canvas and a Rectangle as arguments and draws a representation
    of the Rectangle on the Canvas.
    
    """
    # specify bounds of the rectangle
    lower_left = [rect.corner.x, rect.corner.y]
    upper_right = [rect.corner.x + rect.width, rect.corner.y + rect.height]
Esempio n. 19
0
#!/usr/bin/python

from swampy.World import World
from rectangle import Rectangle, Point

def draw_rectangle(Canvas, Rectangle):
    bbox = [[Rectangle.corner.x, Rectangle.corner.y], 
            [Rectangle.corner.x + Rectangle.width, 
             Rectangle.corner.y + Rectangle.height]]
    Canvas.rectangle(bbox, outline="black", width=2, fill="green4")
    

world = World()

canvas = world.ca(width=500, height=500, background="white")
box = Rectangle()
box.corner = Point()
box.corner.x = 50
box.corner.y = 50
box.width = 100
box.height = 100

draw_rectangle(canvas, box)
world.mainloop()
Esempio n. 20
0
# import swampy
from swampy.World import World

world = World()


class Point(object):
    """
    This shows a point in 2-d space
    Accepts point x, point y, width, color attributes
    """


class Circle(object):
    """The describes a circle
    Accepts point x, point y, radius, and color
    """


class Rectangle(object):
    """
    This creates a rectangle. Accepts box width and heights, and color.
    Accepts width 1, width 2, height 1, height 2, and color
    """


canvas = world.ca(width=750, height=750, background='red')


def draw_rectangle(x, y, x1, y1):
    rect = ([x, y], [x1, y1])
# Phyllis Torres
# Create and Draw Objects
# Due Date: November 3, 2016

# import swampy
from swampy.World import World

# create a world object from World class
world = World()


# define classes for point, circle, and rectangel
# noinspection PyPep8
class Point:
    """defines a point in 2 dimensional space
            """
    def __init__(self):
        pass


# noinspection PyPep8
class Circle:
    """defines a circle"""
    def __init__(self):
        pass


# noinspection PyPep8
class Rectangle:
    """defines a rectangle"""
    def __init__(self):
Esempio n. 22
0
def draw_rec(x,y,col):
	world=World()
	canvas = world.ca(width=500, height=500, background='white')
	bbox = [[-x,-y], [x, y]]
	canvas.rectangle(bbox, outline='black', width=2, fill=col)
	world.mainloop()