Beispiel #1
0
        else:
            raise StopIteration

    def truncate(self):
        """Truncate the position of the point by making the x and y components integers."""
        self.x=int(self.x)
        self.y=int(self.y)

    def __str__(self):
        """Return the string representation of a point."""
        return "Point:"+str(self.__dict__)

if __name__=="__main__":
    from mysurface import Surface
    from myvector import Vector
    surface=Surface(fullscreen=True)
    p1=Point(0,0,color=mycolors.RED,fill=True)
    p2=Point(5,0,color=mycolors.GREEN,fill=True)
    p3=Point(10,0,color=mycolors.BLUE,fill=True)
    p4=Point(15,0,color=mycolors.YELLOW,fill=True)
    p5=Point(20,0,color=mycolors.ORANGE,fill=True)
    points=[p1,p2,p3,p4,p5]
    points=[Point(5*i,0,radius=0.2) for i in range(10)]
    angles=[i/1000 for i in range(1,len(points))]
    while surface.open:
        surface.check()
        surface.control()
        surface.clear()
        surface.show()
        Point.turnPoints(angles,points)
        Point.showPoints(surface,points)
Beispiel #2
0
        ]

    abstract = property(getAbstract, setAbstract, delAbstract,
                        "Representation of the point as an abstract point.")
    components = property(
        getComponents, setComponents, delComponents,
        "Representation of the components of the material point.")
    step = property(getStep, setStep, delStep,
                    "Representation of the step of the material point.")


FallingPoint = lambda: MaterialPoint()

if __name__ == "__main__":
    from mysurface import Surface
    surface = Surface(name="Material Point Test")
    points = [
        MaterialPoint.random(color=mycolors.darken(mycolors.YELLOW))
        for i in range(5)
    ]
    while surface.open:
        surface.check()
        surface.clear()
        surface.control()
        surface.show()
        for point in points:
            #point.showText(surface,point)
            point.update(t=0.001)
            t = point.getTrajectory(1,
                                    3,
                                    point_color=mycolors.darken(mycolors.RED))
Beispiel #3
0
from mysurface import Surface
from mydraw import Draw

from math import sqrt, atan, pi, cos, sin, pi
from cmath import polar
from mycolors import *

from myabstract import Point, Form, Vector

import random
import time

if __name__ == "__main__":
    real_window = Window(size=[1440, 900], fullscreen=True)
    draw = Draw(window=real_window)
    window = Surface(
        draw)  #Create not a real window but a surface to display on screen.
    #window=Window(fullscreen=True)
    p1 = Point(1, -6)
    p2 = Point(-2, 4)
    p3 = Point(8, 5)
    p4 = Point(4, 4, color=(0, 255, 0))
    points = [p1, p3, p2, p4]
    f = Form([
        Point(random.randint(-10, 10), random.randint(-10, 10))
        for i in range(10)
    ])
    #f.show(window)
    f2 = f.getSparse()
    p1.show(window)
    p2.show(window)
    v1 = Vector(p2[0] - p1[0], p2[1] - p1[1], color=(255, 0, 0))
Beispiel #4
0
from myabstract import Form, Segment, Line, Vector, Point

from mysurface import Surface
surface = Surface(name="Test")

#line=Line.random()
#segment=Segment.random()
#print(line|segment)

import mycolors
import math

vector = Vector(1, 0)
point = Point(0, 0)

while surface.open:
    surface.check()
    surface.control()
    surface.clear()
    surface.show()
    vector.rotate(0.1)
    a = vector.angle
    wl = mycolors.bijection(a, [-math.pi, math.pi], [380, 780])
    c = mycolors.setFromWavelength(wl)
    vector.show(surface, point, color=c)
    surface.console("angle: ", str(a), nmax=20)
    #surface.print('something',(10,10),size=100,conversion=False)
    surface.flip()
Beispiel #5
0
        self.position = [-12, -10]
        self.size = [1, 20]
        self.generate()

    def generate(self):
        """Generate random cases for the board."""
        x, y = self.position
        sx, sy = self.size
        self.cases = [
            Case([x, y - sy // 2], color=mycolors.random()) for y in range(sy)
        ]

    def show(self, surface):
        """Show the paint by showing all its cases."""
        f = self.getForm()
        for case in self.cases:
            case.show(surface, side_color=mycolors.BLACK)
        f.side_color = mycolors.BLACK
        f.side_width = 3
        f.show(surface)
        f[0].showText(surface, "Board")


if __name__ == "__main__":
    from mysurface import Surface
    from myzone import Zone
    surface = Surface(name="Painter")
    painter = Painter([0, 0], [8, 8])
    #print([0,0] in painter.paints[0])
    painter(surface)
Beispiel #6
0
from mypoint import Point
from myform import Form
from myvector import Vector
from mywindow import Window
from mysurface import Surface
from mycolors import RED, WHITE

from random import randint
"""This is a demonstration of the potential of the project, it shows the easiness
to make complex interactions between defined forms using only few lines of codes."""
#window=Window()

window = Surface()
#The trick is to use the surface as a window since the behavious are mainly alike
#Indeed the surface was designed to answer all the needs of the clients as if it
#was a window but is in reality a completely different type using somekind of
#kernel pattern using only a true window as a attribute and being a intermediary.
#This intermediary is necessary in order to change the coordonnate system of the window.
#It is pivotal that all the coordonnates involved in future programs remain in plane's
#coordonnates' system for simplicity.
wsx, wsy = window.draw.window.size
X = wsx // 4
Y = wsy // 4

#posAlea=lambda :[randint(X,3*X),randint(Y,3*Y)] #Obsolete
#posAlea=lambda:(randint(-5,5),randint(-5,5))

#f1=Form([Point(*posAlea()) for i in range(5)],fill=True) #Obsolete
#f1=f1.getSparse()
f1 = Form.random(5, -10, 10)
#f2=Form([Point(*posAlea()) for i in range(5)])
Beispiel #7
0
            return value
        else:
            raise StopIteration

    def __str__(self):
        """Return the string representation of a point."""
        return "Point:"+str(self.__dict__)

    __repr__=__str__



FallingPoint=lambda :MaterialPoint(Motion.random(),[myforce.gravity])

if __name__=="__main__":
    #Only used for testing
    from mysurface import Surface
    surface=Surface()
    points=[MaterialPoint.random() for i in range(5)]
    while surface.open:
        surface.check()
        surface.clear()
        surface.control()
        surface.show()
        for point in points:
            surface.print(str(point),tuple(point))
            point.show(surface)
            point.showMotion(surface)
            point.update(t=0.1)
        surface.flip()
Beispiel #8
0
    def __call__(self):
        """Return all coordonnates of the circle."""
        return [self.x,self.y,self.radius]

    def crossCircle(self,other):
        """Determine if two circles are crossing."""
        vector=Vector.createFromTwoPoints(self.center,other.center)
        return vector.norm<self.radius+other.radius

if __name__=="__main__":
    from mysurface import Surface
    from myzone import Zone
    from mywindow import Window

    surface=Surface(plane=Zone(),window=Window())
    c1=Circle(4,2,2,color=mycolors.BLUE)
    c2=Circle(1,2,1,color=mycolors.BLUE)

    corners=[-1,-1,1,1]
    cs=[Circle.random(corners,color=mycolors.random()) for i in range(10)]

    fill=False
    c1_border_color=mycolors.random()
    c2_border_color=mycolors.random()
    c1_area_color=mycolors.random()
    c2_area_color=mycolors.random()

    while surface.open:
        surface.check()
        surface.control()
    def correct(self, Z, N):
        """Correct the Z and N matrices by only returning a matrix M."""
        log_horizon = np.log(np.log(self.horizon)) / np.log(2)
        with np.errstate(invalid='ignore'):
            M = np.nan_to_num(N + 1 - np.log(np.log(abs(Z))) / np.log(2) +
                              log_horizon)
        return M

    def show(self, surface):
        """Show the mandelbrot set on the surface."""
        corners = surface.getCorners()
        Z, N = self.getMatrices(corners)
        M = self.correct(Z, N)
        maximum = np.max(M)
        minimum = np.min(M)
        self.showFromMatrix(surface, M)
        print(minimum, maximum)

    def showFromMatrix(self, surface, matrix):
        """Show the mandelbrot set using the surface and the matrix."""
        ly = len(matrix)
        lx = len(matrix[0])


if __name__ == "__main__":
    from mysurface import Surface
    surface = Surface()
    set = Mandelbrot()
    set.show(surface)
    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 mysurface import Surface
    from myplane import Plane
    p = Plane(theme={"grid nscale": 2})
    surface = Surface(name="Complex Form", plane=p)
    arguments = {
        "number": 5,
        "cross_point_color": mycolors.GREEN,
        "cross_point_mode": 1,
        "cross_point_size": (0.01, 0.01),
        "cross_point_width": 2
    }
    f = ComplexForm.random(**arguments)
    while surface.open:
        surface.check()
        surface.control()
        surface.clear()
        surface.show()
        for p in f:
            p.rotate(0.01)
            entity1.velocity = self.rotate2(v1, -angle)
            entity2.velocity = self.rotate2(v2, -angle)

    def affectOneVelocity(self, v1, v2, m1, m2):
        return (m1 - m2) / (m1 + m2) * v1 + (2 * m2) / (m1 + m2) * v2

    def rotate2(self, velocity, angle):
        vx, vy = velocity
        nvx = vx * cos(angle) - vy * sin(angle)
        nvy = vx * sin(angle) + vy * cos(angle)
        return [nvx, nvy]


if __name__ == "__main__":
    from mysurface import Surface
    surface = Surface(name="Material Form Handler")
    ps1 = [Point(0, 0), Point(0, 1), Point(1, 1), Point(1, 0)]
    f1 = Form(ps1)
    f1 = MaterialForm.createFromForm(f1)
    f1.velocity = Vector(1, 1)
    ps2 = [Point(0, 0), Point(0, 2), Point(2, 2), Point(2, 0)]
    f2 = Form(ps2)
    f2 = MaterialForm.createFromForm(f2)
    forms = [f1, f2]
    handler = MaterialFormHandler(forms)

    while surface.open:
        surface.check()
        surface.control()
        surface.clear()
        surface.show()
from myabstract import Segment,Point,Vector
from mysurface import Surface
import mycolors

p1=Point(-1,-1)
p2=Point(1,1)
p3=Point(0,1)

s1=Segment(p1,p2,width=3)
s2=Segment(p2,p3,width=3)

e=10e-10

surface=Surface()

while surface.open:
    surface.check()
    surface.control()
    surface.clear()
    surface.show()

    p=Point(list(surface.point()))
    #if p in surface:
    s1.p2=p
    if s1.crossSegment(s2):
        s1.color=mycolors.RED
        s2.color=mycolors.RED
    else:
        s1.color=mycolors.WHITE
        s2.color=mycolors.WHITE
    l1=s1.getLine()
    def updateForces(self):
        """Update all the forces of the dynamic objects."""
        for field in self.fields:
            for entity in self.dynamic:
                if entity in field:
                    entity.subject(field)

    def updatePhysics(self):
        """Update all the objects according to physics rules."""

    def show(self, context):
        """Show all the entities on the screen."""
        self.showStatic()
        self.showDynamic()

    def showStatic(self):
        """Show all the statics entities on screen."""
        for entity in self.static:
            entity.show(self.context)

    def showDynamic(self):
        """Show all the dynamics entities on screen."""
        for entity in self.dynamic:
            entity.show(self.context)


if __name__ == "__main__":
    context = Surface()
    system = System()
    game = GameEngine(context)
Beispiel #14
0
        """Allow the user to push the button."""


class Circuit:
    def __init__(self, logic_gates=[]):
        """Create a circuit object."""
        self.logic_gates = logic_gates
        self.connexions = []

    def show(self, surface):
        """Show the circuit by showing all its logic gates."""
        for gate in self.logic_gates:
            gate.show(surface)


if __name__ == "__main__":
    from mysurface import Surface
    surface = Surface(name="Logic Gates")
    g1 = OrGate([1, 1])
    g2 = AndGate([2, 1])
    gs = [g1, g2]
    c = Circuit(gs)

    while surface.open:
        surface.check()
        surface.control()
        surface.clear()
        surface.show()
        c.show(surface)
        surface.flip()
Beispiel #15
0
            plane.flip()

    def control(self, window):
        keys = window.press()
        if keys[K_UP]:
            self.acceleration[1] += 1
        if keys[K_DOWN]:
            self.acceleration[1] -= 1
        if keys[K_LEFT]:
            self.rotate(0.1)
        if keys[K_LEFT]:
            self.rotate(-0.1)

    def attack(self, other):
        other.life -= self.dammage

    def isAlive(self):
        return self.life > 0


if __name__ == "__main__":
    surface = Surface()
    spaceship = Spaceship()
    while surface.open:
        surface.check()
        surface.clear()
        surface.show()
        spaceship.control(surface.draw.window)
        spaceship.show(surface)
        surface.flip()
Beispiel #16
0
                        if p2 < p1:
                            p = np
                    else:
                        p = np
            points.append(p)
        return points

    def update(self, surface):
        """Update the ray caster."""
        self.emiter.update(surface)


if __name__ == "__main__":
    from mysurface import Surface
    from myzone import Zone
    surface = Surface(name="RayCasting", plane=Zone())
    #forms=[Form.random([-10,-10,10,10],number=5,side_color=mycolors.RED) for i in range(10)]
    forms = [
        Form.random([10 * (i - 5), -5, 10 * (i - 4), 5],
                    number=5,
                    side_color=mycolors.RED) for i in range(10)
    ]
    #forms=[Segment.random([10*(i-5),-5,10*(i-4),5],number=5,side_color=mycolors.RED) for i in range(10)]
    emiter = Emiter()
    caster = RayCaster(emiter, forms)
    origin = Point(0, 0)

    while surface.open:
        surface.check()
        surface.control()
        surface.clear()
Beispiel #17
0
from myabstract import Form, Segment, Line, Vector, Point, HalfLine

from mysurface import Surface
surface = Surface(name="Test")

#line=Line.random()
#segment=Segment.random()
#print(line|segment)

import mycolors
import math

ps = [Point(-1, -1), Point(1, -1), Point(1, 1), Point(-1, 1)]
f = Form(ps)

while surface.open:
    surface.check()
    surface.control()
    surface.clear()
    surface.show()

    position = tuple(surface.point())
    p = Point(*position)
    h = HalfLine(p, 0)
    ps = f.crossHalfLine(h)

    print(ps)

    f.color = mycolors.WHITE
    if p in f:
        f.color = mycolors.RED
        form = RotatingForm(points, **kwargs)
        form.makeSparse()
        return form

    def update(self, surface):
        """Rotate the form."""
        self.rotate(0.01)


class RotatingSegment(Segment):
    def random(corners=[-1, -1, 1, 1], width=1, color=mycolors.WHITE):
        """Create a random segment."""
        p1 = Point.random(corners)
        p2 = Point.random(corners)
        return RotatingSegment(p1, p2, width, color)

    def update(self, surface):
        """Rotate the segment."""
        self.rotate(-0.01)


if __name__ == "__main__":
    from mysurface import Surface
    surface = Surface(name="Abstract Handler")
    f1 = RotatingForm.random()
    f2 = RotatingForm.random([-5, 0, 5, 5])
    s3 = RotatingSegment.random()
    fs = [f1, f2, s3]
    a = AbstractHandler(fs)
    a(surface)