def create_image(color, right, down, left, up):
    #the grid cell size is 25*25, but we want a little bleed over
    #for the black outline
    width = 26
    height =26

    margin = 4

    im = Image.new("RGBA", (width, height))

    draw = ImageDraw.Draw(im)

    #each corner of the square, starting in the upper-left and moving clockwise
    a = Point(0,0)
    b = Point(width-1, 0)
    c = Point(width-1, height) - Point(0,1)
    d = Point(0, height) - Point(0,1)
    corners = [a,b,c,d]

    if up:    draw.line([a.tuple(), b.tuple()], fill=color)
    if right: draw.line([b.tuple(), c.tuple()], fill=color)
    if down:  draw.line([c.tuple(), d.tuple()], fill=color)
    if left:  draw.line([d.tuple(), a.tuple()], fill=color)

    return im
Example #2
0
def make_img(fractal):
    size = Point(200,200)
    
    bbox = BoundingBox(Point(0,0), size)

    im = Image.new("RGB", size.tuple(), "white")
    draw = ImageDraw.Draw(im)
    fractal.draw(draw, bbox)
    return im
def create_image(color):
    #the grid cell size is 25*25, but we want a little bleed over
    #for the black outline
    width = 26
    height =26

    margin = 4

    im = Image.new("RGB", (width, height))

    draw = ImageDraw.Draw(im)

    #each corner of the square, starting in the upper-left and moving clockwise
    a = Point(0,0)
    b = Point(width-1, 0)
    c = Point(width-1, height)
    d = Point(0, height)

    #bounds of the interior square
    inner_left = margin
    inner_right = width-margin-1
    inner_top = margin
    inner_bottom = height-margin

    #points of the interior square
    e = Point(inner_left, inner_top)
    f = Point(inner_right, inner_top)
    g = Point(inner_right, inner_bottom)
    h = Point(inner_left, inner_bottom)

    #left and right bevels
    draw.rectangle([a.tuple(), c.tuple()], fill=mid_color(color,black,0.1))

    #interior square
    draw.rectangle([e.tuple(), g.tuple()], fill=color)

    #upper bevel
    draw.polygon([p.tuple() for p in [a,b,f,e]], fill=mid_color(color, white, 0.5))
    #lower bevel
    draw.polygon([p.tuple() for p in [h,g,c,d]], fill=mid_color(color, black, 0.5))

    #outline
    draw.rectangle([a.tuple(), (c-Point(0,1)).tuple()], outline=black, fill=None)
    return im
Example #4
0
def make_zoomed_img(fractal, amt, foci_idx=0):
    zoom = fractal.zoom_change ** amt
    size = Point(200,200)
    focus = fractal.foci[foci_idx]
    cam_center = Point(focus.x * size.x, focus.y * size.y)
    def transform(p):
        return ((p-cam_center)*zoom)+cam_center
    bbox = BoundingBox(transform(Point(0,0)), transform(size))

    im = Image.new("RGB", size.tuple(), "white")
    draw = ImageDraw.Draw(im)
    fractal.draw(draw, bbox)
    return im
Example #5
0
from geometry import Point, distance
from event import Event, ChainedEvent, SimulEvent
from animation import make_gif
from PIL import Image

ticks_per_second = 30
levelDurationInSeconds = 0.5
framesPerLevel = int(levelDurationInSeconds * ticks_per_second)

white = (255,255,255)
black = (0,0,0)

windowSize = Point(400,400)

pygame.init()
screen = pygame.display.set_mode(windowSize.tuple())

class LineSegment:
    def __init__(self, a, b):
        self.a, self.b = a,b
    def draw(self, surface):
        if self.a == self.b:
            return
        pygame.draw.line(surface, white, self.a.map(round).tuple(), self.b.map(round).tuple())

def image_from_surface(surface):
    data = pygame.image.tostring(surface, "RGB")
    return Image.fromstring("RGB", surface.get_size(), data)

def solveTriangle(A,B, theta):
    c = distance(A,B)