Пример #1
0
        xmax = max([p.x for p in points])
        ymin = min([p.y for p in points])
        ymax = max([p.y for p in points])
        corners = [xmin, ymin, xmax, ymax]
        coordonnates = self.getCoordonnatesFromCorners(corners)
        self.position = coordonnates[:2]
        self.size = coordonnates[2:]

    points = property(
        getPoints, setPoints,
        "Allow the user to manipulate the points of the rectangle.")


if __name__ == "__main__":
    from mycontext import Surface
    surface = Surface(name="Rectangle Test")
    r1 = Rectangle([0, 0], [3, 2],
                   side_width=3,
                   side_color=mycolors.BLUE,
                   area_color=mycolors.WHITE,
                   area_show=True)
    r2 = Rectangle([-1, -1], [2, 1],
                   side_width=3,
                   side_color=mycolors.BLUE,
                   area_color=mycolors.WHITE,
                   area_show=True)
    print(r1.size)
    while surface.open:
        surface.check()
        surface.control()
        surface.clear()
Пример #2
0
from myabstract import Segment, Point, Vector
from mycontext 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(name="Segment Demonstration")

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()
Пример #3
0
    velocity = property(getVelocity, setVelocity, delVelocity,
                        "Representation of the velocity of the form.")
    acceleration = property(getAcceleration, setAcceleration, delAcceleration,
                            "Representation of the acceleration of the form.")
    #abstract_center=property(getAbstractCenter,setAbstractCenter,delAbstractCenter,"Representation of the abstract center of the material form.")
    #abstract_points=property(getAbstractPoints,setAbstractPoints,delAbstractPoints,"Representation of the abstract points of the material form.")
    steps = property(getSteps, setSteps, delSteps,
                     "Representation of the steps of the material form.")


FallingForm = lambda: MaterialForm(
    [mymaterialpoint.FallingPoint() for i in range(5)])

if __name__ == "__main__":
    from mycontext import Surface
    surface = Surface()
    c1 = [-10, -10, 10, 10]
    f1 = Form.random(c1, n=5)
    f1 = MaterialForm.createFromForm(f1)
    f1.velocity = Vector(0, 1)
    f1.acceleration = Vector(0, -0.01)
    print(f1)

    c2 = [-10, -10, 10, 10]
    f2 = Form.random(c2, n=5)
    f2 = MaterialForm.createFromForm(f2)

    #print(form[0].forces)
    #print(form.getMass())
    origin = Point.origin()
    while surface.open:
Пример #4
0
from myabstract import Vector, Point

from mycontext import Surface

import mycolors
import math

surface = Surface(name="Test")

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

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()
Пример #5
0
            Vector(points[i], points[i + 1]) for i in range(0, p - 1, 5)
        ]
        self.showPoints(surface, points)
        self.showSegments(surface, segments)
        self.showVectors(surface, vectors)

    def showVectors(self, surface, vectors, color=None):
        """Show the vectors on the surface."""
        if not color: color = self.vector_color
        for vector in vectors:
            vector.show(surface, color=color)


if __name__ == "__main__":
    from mycontext import Surface
    surface = Surface(name="Curves demonstration")
    l = 10
    points = [Point(2 * x, random.randint(-5, 5)) for x in range(l)]
    t = Trajectory(points, segment_color=mycolors.GREEN)
    b = BezierCurve(points, segment_color=mycolors.RED)
    #st=t.sampleSegments(3)
    #t1=Trajectory(st,segment_color=mycolors.BLUE)
    #print(b.points[-1])
    #print(b(1))
    #print(b.segments[-1])
    #c=CurvedForm(points)
    n = 0
    ncp = 50  #number construction points

    while surface.open:
        surface.check()
Пример #6
0
from myabstract import Form, Point, HalfLine

from mycontext import Surface
import mycolors

surface = Surface(name="Test")

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
    if len(ps) % 2 == 1:
        f.color = mycolors.ORANGE

    h.show(surface)
    f.show(surface)
Пример #7
0
    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)
        f.show(surface)
Пример #8
0
                            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 mycontext 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()
        surface.show()
        for form in forms:
            form.rotate(0.1, origin)
        caster.update(surface)