Exemplo n.º 1
0
 def ellipse(self, screen, color, rect, fill=False):
     coordonnates = Plane.getCoordonnatesFromRect(rect)
     x, y, sx, sy = coordonnates
     py, px = self.plane.getToScreen((x, y), self.window)
     psx, psy = self.plane.getToScreen((sx, sy), self.window)
     pmx, pmy, pMx, pMy = Plane.getRectFromCoordonnates([px, py, psx, psy])
     rect = [pmx, pmy, pMx, pMy]
     self.window.draw.ellipse(screen, color, rect, fill)
Exemplo n.º 2
0
 def __init__(self, functions):
     """Create a grapher and stores its functions with its predefined colors."""
     Plane.__init__(self)
     self.functions = functions
     self.colors = (
         [RED, BLUE, GREEN, YELLOW] +
         [window.randomColor()
          for i in range(len(functions) - 4)])[:len(functions)]
Exemplo n.º 3
0
 def __init__(self, window=None, plane=None):
     """Create a draw object using the window and optional plane."""
     if window:
         self.window = window
     else:
         self.window = Window()
     if plane:
         self.plane = plane
     else:
         self.plane = Plane(offset=[window.w / 2, window.h / 2],
                            zoom=min(window.size) / 10)
Exemplo n.º 4
0
 def __init__(self, plane=Plane(), window=None, **kwargs):
     if window:
         self.window = window
     else:
         window = Window(**kwargs)
     self.plane = plane
     self.window = window
     self.window.text_size = 30
Exemplo n.º 5
0
class Draw:
    """Act like a window but convert coordinates."""
    def __init__(self, window=None, plane=None):
        """Create a draw object using the window and optional plane."""
        if window:
            self.window = window
        else:
            self.window = Window()
        if plane:
            self.plane = plane
        else:
            self.plane = Plane(offset=[window.w / 2, window.h / 2],
                               zoom=min(window.size) / 10)

    def circle(self, screen, color, position, radius, fill=None):
        """Draw a circle using plane coordinates."""
        position = self.plane.getToScreen(position)
        radius *= self.plane.zoom
        pygame.draw.circle(screen, color, position, radius, fill)

    def line(self, screen, color, p1, p2, width=None):
        """Draw a line using plane coordinates."""

        pygame.draw.line(screen, color, p1, p2, width)
Exemplo n.º 6
0
 def __init__(self,plane=Plane(),window=Window()):
     self.plane=plane
     self.window=window
Exemplo n.º 7
0
    def lines(self,color,positions,connected=True,width=1):
        new_positions=self.plane.getAllToScreen(positions,self.window)
        self.window.draw.lines(screen,color,connected,positions,width)

    def show(self):
        self.plane.showGrid(self.window)
        self.window.flip()

    def clear(self):
        self.plane.clear(self.window)

    def check(self):
        self.window.check()

    def control(self):
        self.plane.control(self.window)



if __name__=="__main__":
    window=Window("mydraw")
    plane=Plane()
    draw=Draw(plane,window)
    while draw.window.open:
        draw.check()
        draw.control()
        draw.clear()
        draw.line(WHITE,(3,-5),(-2,6))
        draw.show()
Exemplo n.º 8
0
 def __init__(self, forms=[], theme={}, view=None):
     Plane.__init__(self, theme, view)
     self.forms = forms
     self.selection = None
Exemplo n.º 9
0
 def __init__(self,size=[20,20],theme={},view=None):
     Plane.__init__(self,theme,view)
     self.size=size
     if not "borders_color" in theme: self.theme["borders_color"]=(255,255,255)
Exemplo n.º 10
0
        links = [(p, 0) for p in self.points]

    def countContacts(self):
        """Return the list of contacts for each points, which means how many points
        is a given point connected to."""
        return [np.sum(self.network[:][j]) for j in range(len(self.points))]

    segments = property(
        getSegments, setSegments, delSegments,
        "Allow the user to manipulate the segments of the form.")


if __name__ == "__main__":
    from mycontext import Surface
    from myplane import Plane
    p = Plane(theme={"grid nscale": 2})
    surface = Surface(name="Complex Form", plane=p)
    arguments = {
        "n": 5,
        "cross_point_color": mycolors.GREEN,
        "cross_point_mode": 1,
        "cross_point_size": (0.01, 0.01),
        "cross_point_width": 2
    }
    while surface.open:
        surface.check()
        surface.control()
        surface.clear()
        surface.show()
        for p in f:
            p.rotate(0.01)
Exemplo n.º 11
0
 def __init__(self,size=[20,20],theme={},view=None):
     Plane.__init__(self,theme,view)
     self.size=size
     if "borders" in theme: self.borders_color=borders_color
     else: self.borders_color=(255,255,255)
Exemplo n.º 12
0
from myplane import Plane
from mywindow import Window

from sand import Sand

import mycolors
import math


SAND_NUMBER = 10

sand = [Sand.random(9e-1, 11e-1) for i in range(SAND_NUMBER)]


window = Window()
plane = Plane(offset=[window.w/2, window.h/2], zoom=min(window.size)/10)
angle = 0

while window.open:
    window.check()
    window.clear(mycolors.WHITE)

    angle += 0.01
    angle %= 2*math.pi

    xoffset = math.cos(angle)
    yoffset = math.sin(angle)

    for grain in sand:
        x, y = plane.getToScreen(grain.center)