def test_animal(self):
     world = World.World()
     animal = World.Animal()
     animal.step()
     animal.draw()
     animal.undraw()
     animal.redraw()
     animal.die()
    def test_delay(self):
        world = World.World()
        animal = World.Animal()

        world.delay = 0.3
        self.assertEqual(animal.delay, 0.3)
        self.assertEqual(world.delay, 0.3)

        animal.delay = 0.4
        self.assertEqual(animal.delay, 0.4)
        self.assertEqual(world.delay, 0.4)
Example #3
0
    def test_step(self):
        world = World.World()
        a1 = World.Animal()
        a1.x = 100
        a2 = World.Animal()
        a2.x = 200

        self.assertEqual(len(world.animals), 2)

        def get_x(animal): return animal.x

        res = world.map_animals(get_x)
        self.assertEqual(len(res), 2)
        self.assertEqual(res[1], 200)

        world.step()

        world.canvas = world.ca()
        world.clear()
    def test_interpreter(self):
        global x
        x = 7

        world = World.World()
        world.make_interpreter(globals())

        world.inter.run_code('x=3', 'user-provided code')
        self.assertEqual(x, 3)

        thread = world.inter.run_code_thread('x=5', 'user-provided code')
        thread.join()
        self.assertEqual(x, 5)
 def test_world(self):
     world = World.World()
     world.stop()
     world.quit()
    new_rect.corner.x += dx
    new_rect.corner.y += dy
    return new_rect


class polygon:
    """Represents a polygon

       attributes: list of corners point objects"""


class circle(object):
    """Represents a circle

    attributes: radius ,corner ,color"""
world = World()


def create_bbox_rect(rect):
    p1 = []
    p1.append(rect.corner.x)
    p1.append(rect.corner.y)
    p2 = []
    p2.append(rect.corner.x + rect.width)
    p2.append(rect.corner.y + rect.height)
    box = []
    box.append(p1)
    box.append(p2)
    return box

Example #7
0
"""Solution to an exercise from
Think Python: An Introduction to Software Design

Copyright 2010 Allen B. Downey
License: GNU GPLv3 http://www.gnu.org/licenses/gpl.html

This program requires Gui.py, which is part of
Swampy; you can download it from thinkpython.com/swampy.

"""

from swampy.World import *

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

bbox = [[-150, -110], [150, 110]]

canvas.rectangle(bbox, outline='purple', width=5, fill='green')

canvas.oval(bbox, outline='purple', width=5, fill='yellow')

canvas.circle([0, 0], 100, outline='purple', width=5, fill='orange')

canvas.line(bbox, fill='purple', width=5)

photo = Tkinter.PhotoImage(file='allen.ppm')
image = canvas.image([0, 0], image=photo)

bbox = image.bbox()
Example #8
0
p1.x = 5
p1.y = 5

p2 = Point()
p2.p = Point()
p2.p.x = 5
p2.p.y = 10


import math
def distance(P1, p2):
    return math.sqrt( (p1.x-p2.p.x)**2 + (p1.y-p2.p.y)**2 )


print distance(p1,p2)
'''


from swampy.World import *

world = World()

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

bbox=[[-150, -100], [150, 100], [150, -100]]

canvas.polygon(bbox, outline='pink', width=5, fill='green4')
canvas.circle([250, 0], 75, outline='blue', width=2, fill='pink')

world.mainloop()
Example #9
0
"""Solution to an exercise from
Think Python: An Introduction to Software Design

Copyright 2010 Allen B. Downey
License: GNU GPLv3 http://www.gnu.org/licenses/gpl.html

This program requires Gui.py, which is part of
Swampy; you can download it from thinkpython.com/swampy.

"""

from swampy.World import *

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

bbox = [[-150,-110], [150, 110]]

canvas.rectangle(bbox, outline='purple', width=5, fill='green')

canvas.oval(bbox, outline='purple', width=5, fill='yellow')

canvas.circle([0,0], 100, outline='purple', width=5, fill='orange')

canvas.line(bbox, fill='purple', width=5)

photo = PhotoImage(file='allen.ppm')
image = canvas.image([0,0], image=photo)

bbox = image.bbox()