コード例 #1
0
ファイル: chezc_rep.py プロジェクト: aaabhilash97/thinkpython
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()
コード例 #2
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()
コード例 #3
0
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()
コード例 #4
0
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()
コード例 #5
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()
コード例 #6
0
ファイル: 15.1.2.3.py プロジェクト: bentd/think-python
    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()



コード例 #7
0
ファイル: draw_rectangle.py プロジェクト: debsir/Learning
#!/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()
コード例 #8
0
ファイル: 4.py プロジェクト: aswin191993/python_think
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()
コード例 #9
0
ファイル: 4.py プロジェクト: aswin191993/python_think
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()
コード例 #10
0
ファイル: 4.py プロジェクト: aswin191993/python_think
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()
# noinspection PyPep8
class Circle:
    """defines a circle"""
    def __init__(self):
        pass


# noinspection PyPep8
class Rectangle:
    """defines a rectangle"""
    def __init__(self):
        pass


# define  a canvas
canvas = world.ca(width=1000, height=1000, background='linen')


# define a function to draw a rectangle
def draw_rectangle(canvas, rect):
    bbox = [[rect.x, rect.y], [rect.x1, rect.y1]]
    canvas.rectangle(bbox, outline='black', width=4, fill='white')


# define a function to draw a rectangle with a fill color
def draw_rectangle_color(canvas, rect1, color):
    bbox = [[rect1.x, rect1.y], [rect1.x1, rect1.y1]]
    canvas.rectangle(bbox, outline='black', width=4, fill=color)


# define a function to draw a point
コード例 #12
0

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])
    canvas.rectangle(rect, outline='black', width=2, fill='green4')


def draw_rectangle_color(x, y, x2, y2, color):
    rect = ([x, y], [x2, y2])
    canvas.rectangle(rect, outline='black', width=2, fill=color)


def draw_point(x, y, z, color):
    canvas.circle([x, y], z, color)
コード例 #13
0
    """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]
    bbox = [lower_left, upper_right] 
コード例 #14
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)
コード例 #15
0
ファイル: point.py プロジェクト: aaabhilash97/thinkpython
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()
コード例 #16
0
ファイル: world.py プロジェクト: aaabhilash97/thinkpython
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()