Exemple #1
0
 def animation_objects(self, q):
     size_x = self.length
     size_y = 5
     an0 = sim.AnimatePolygon(
         spec=ship_polygon(self),
         fillcolor=shipcolor(self.side),
         linewidth=0,
         text=' ' + self.name(),
         textcolor='white',
         layer=1,
         fontsize=2.6,
         text_anchor=('e' if self.side == left else 'w'))
     return (size_x, size_y, an0)
 def animation_objects(self, q):
     size_x = self.length  # how much to display the ship in x-direction
     size_y = 5  # how much to display the ship in y-direction
     # an0 is an instance of Animate class - a polygon representing the ship
     an0 = sim.AnimatePolygon(
         spec=ship_polygon(self),
         fillcolor=shipcolor(self.side),
         linewidth=0,
         text=" " + self.name(),
         textcolor="white",
         layer=1,
         fontsize=2.6,
         text_anchor=("e" if self.side == left else "w"),
     )
     return (size_x, size_y, an0)
Exemple #3
0
        def process(self):

            AnimatePolar(r=100,text='A',t1=10)

            x=0
            for fontsize in range(8,30):
                sim.Animate(x0=x,y0=height-100,text='aA1',font=('Calibri,calibri'),fontsize0=fontsize)
                x+=fontsize*2
            x=0
            for fontsize in range(8,30):
                sim.Animate(x0=x,y0=height-200,text='aA1',font='CabinSketch-Bold',fontsize0=fontsize)
                x+=fontsize*2


            self.rx=sim.Animate(x0=600,y0=300,linewidth0=1,
                            rectangle0=(-200,-200,200,200),t1=10,fillcolor0='green#7f',angle1=0)
            self.rx=sim.Animate(x0=500,y0=500,linewidth0=1,line0=(-500,0,500,0),t1=10,fillcolor0='black')
            self.rx=sim.Animate(x0=500,y0=500,linewidth0=1,line0=(0,-500,0,500),t1=10,fillcolor0='black')

            self.rx=sim.Animate(x0=500,y0=500,linewidth0=10,polygon0=(0,0,100,0,100,100,50,50,0,100),offsetx1=100,offsety1=100,t1=10,fillcolor0='red#7f',angle1=360)
            self.rx=sim.Animate(x0=600,y0=300,linewidth0=1,rectangle0=(-200,-200,200,200),t1=10,fillcolor0='blue#7f',angle1=360)

#            self.t1=sim.Animate(x0=500,y0=500,fillcolor0='black',
#                text='Test text',x1=500,y1=500,t1=25,font='CabinSketch-#Bold',fontsize0=20,anchor='ne',angle1=0,fontsize1=50)


            self.i1=sim.Animate(x0=250,y0=250,offsetx0=100,offsety0=100,angle0=0,angle1=360,circle0=(20,),fillcolor0=('red',0),linewidth0=2,linecolor0='blue',circle1=(20,),t1=15)

#            self.ry=sim.Animate(x0=500,y0=300,linewidth0=1,polygon0=(-100,-100,100,-100,0,100),t1=10,fillcolor0='blue',angle1=90)

            self.i1=sim.Animate(x0=500,y0=500,angle0=0,layer=1,image='salabim.png',width0=300,x1=500,y1=500,angle1=360,t1=20,anchor='center')

            yield self.hold(3)
            self.i1.update(image='Upward Systems.jpg',angle1=self.i1.angle1,t1=self.i1.t1,width0=self.i1.width0)
            return
            self.myslider=sim.AnimateSlider(x=600,y=height,width=100,height=20,vmin=5,vmax=10,v=23,resolution=1,label='Test slider',action=self.slideraction)

            return


            self.p1=sim.AnimatePolygon(
            x0=200,y0=200,polygon0=(-100,-100,100,-100,100,100,-100,100),
            t1=25,x1=100,y1=100,fillcolor1='red',linecolor0='blue',linewidth0=3)
            self.p2=sim.Animate(linewidth0=2,linecolor0='black',linecolor1='white',
                x0=100,y0=600,fillcolor0='green',polygon0=(-50,-50,50,-50,0,0),angle1=720,t1=8)
            self.r1=sim.Animate(layer=1,x0=500,y0=500,rectangle0=(0,0,100,100),fillcolor0='yellow',linecolor0='red',linewidth0=2,angle1=180,t1=10)
            self.t1=sim.Animate(x0=200,y0=200,fillcolor0='black',
                text='Test text',x1=100,y1=100,anchor='center',t1=25,font='courier',fontsize1=50)
            self.r2=sim.Animate(rectangle0=(-5,-5,5,5))

            i=0
            for s in ['ne','n','nw','e','center','w','se','s','sw']:
                sim.Animate(x0=200,y0=200,text=s,t0=i,t1=i+1,anchor=s,keep=False,fillcolor0='red')
                i=i+1

            self.p2=sim.Animate(x0=500,y0=500,line0=(0,0,100,100),angle1=360,t1=10,linecolor0='red',linewidth0=5)
            self.r2=sim.Animate(x0=300,y0=700,rectangle0=(-300,-300,300,300),fillcolor0='',linecolor0='black', linewidth0=2)
            self.c1=sim.Animate(x0=300,y0=700,circle0=(0,),fillcolor0='blue',circle1=(60,),t1=20)
            self.i1=sim.Animate(x0=500,y0=500,angle0=0,layer=1,image='BOA.png',width0=300,x1=500,y1=500,angle1=360,t1=20,anchor='center')
#            self.i1=sim.AnimateText(text='ABCDEF',x0=500,y0=200,angle0=0,layer=1,angle1=360,t1=20,anchor='center')
            yield self.hold(10)
#            self.t1.update(color0='white',x1=100,y1=100,t1=25)
            self.r1.update()
            self.c1.update(t1=20,radius1=0)
Exemple #4
0
def do_animation():

    global xvisitor_dim
    global yvisitor_dim
    global xcar
    global capacity_last, ncars_last, topfloor_last

    env.modelname("Elevator")
    env.speed(32)
    env.background_color("20%gray")
    if make_video:
        env.video("Elevator.mp4")

    xvisitor_dim = 30
    yvisitor_dim = xvisitor_dim
    yfloor0 = 20

    xcar = {}
    xled = {}

    x = env.width()
    for car in cars:
        x -= (capacity + 1) * xvisitor_dim
        xcar[car] = x
    x -= xvisitor_dim
    xsign = x
    x -= xvisitor_dim / 2
    for direction in (up, down):
        x -= xvisitor_dim / 2
        xled[direction] = x
    x -= xvisitor_dim
    xwait = x

    for floor in floors:
        y = yfloor0 + floor.n * yvisitor_dim
        floor.y = y
        for direction in (up, down):
            if (direction == up and floor.n < topfloor) or (direction == down
                                                            and floor.n > 0):
                b = xvisitor_dim / 4
                animate_led = sim.AnimatePolygon(
                    spec=(-b, -b, b, -b, 0, b),
                    x=xled[direction],
                    y=y + 2 * b,
                    angle=0 if direction == up else 180,
                    fillcolor=direction_color(direction),
                    visible=lambda arg, t: (arg.floor_direction) in requests,
                )
                animate_led.floor_direction = (floor, direction)

        sim.AnimateLine(x=0, y=y, spec=(0, 0, xwait, 0))
        sim.AnimateText(x=xsign,
                        y=y + yvisitor_dim / 2,
                        text=str(floor.n),
                        fontsize=xvisitor_dim / 2)

        sim.AnimateQueue(queue=floor.visitors,
                         x=xwait - xvisitor_dim,
                         y=floor.y,
                         direction="w",
                         title="")

    for car in cars:
        x = xcar[car]
        car.pic = sim.AnimateRectangle(x=x,
                                       y=car.y,
                                       spec=(0, 0, capacity * xvisitor_dim,
                                             yvisitor_dim),
                                       fillcolor="lightblue",
                                       linewidth=0)
        sim.AnimateQueue(queue=car.visitors,
                         x=xcar[car],
                         y=car.y,
                         direction="e",
                         title="",
                         arg=car)

    ncars_last = ncars
    sim.AnimateSlider(
        x=510,
        y=0,
        width=90,
        height=20,
        vmin=1,
        vmax=5,
        resolution=1,
        v=ncars,
        label="#elevators",
        action=set_ncars,
        xy_anchor="nw",
    )

    topfloor_last = topfloor
    sim.AnimateSlider(
        x=610,
        y=0,
        width=90,
        height=20,
        vmin=5,
        vmax=20,
        resolution=1,
        v=topfloor,
        label="top floor",
        action=set_topfloor,
        xy_anchor="nw",
    )

    capacity_last = capacity
    sim.AnimateSlider(
        x=710,
        y=0,
        width=90,
        height=20,
        vmin=2,
        vmax=6,
        resolution=1,
        v=capacity,
        label="capacity",
        action=set_capacity,
        xy_anchor="nw",
    )

    sim.AnimateSlider(
        x=510,
        y=-50,
        width=90,
        height=25,
        vmin=0,
        vmax=400,
        resolution=25,
        v=load_0_n,
        label="Load 0->n",
        action=set_load_0_n,
        xy_anchor="nw",
    )

    sim.AnimateSlider(
        x=610,
        y=-50,
        width=90,
        height=25,
        vmin=0,
        vmax=400,
        resolution=25,
        v=load_n_n,
        label="Load n->n",
        action=set_load_n_n,
        xy_anchor="nw",
    )

    sim.AnimateSlider(
        x=710,
        y=-50,
        width=90,
        height=25,
        vmin=0,
        vmax=400,
        resolution=25,
        v=load_n_0,
        label="Load n->0",
        action=set_load_n_0,
        xy_anchor="nw",
    )

    env.animate(True)
def do_animation():  # Animation initialisation is done in this function
    # In this example, the simulation code is completely separated from the animation code

    # Some global variables accesible from any classes and functions in the code
    global xvisitor_dim  # x-dimension of the square representing a visitor
    global yvisitor_dim  # y-dimension of the square representting a visitor
    global xcar  # x-dimension of the elevator car/s
    global capacity_last, ncars_last, topfloor_last

    # Some general parameters about the simulation (See Reference: salabim.Environment)
    env.modelname("Elevator")
    env.speed(32)
    env.background_color("20%gray")
    if make_video:
        env.video("Elevator.mp4")

    # We assign values to some the global variables
    xvisitor_dim = 30  # x-dimension of the square representing a visitor
    yvisitor_dim = xvisitor_dim  # y-dimension of the square representing a visitor
    yfloor0 = 20  # y-coordinate of floor 0

    xcar = {}  # This is a dictionary containing the x-coordinates of the cars
    xled = {}  # This is a dictionary containing the x-coordinates of the leds

    x = env.width()  # Width of the animation in screen coordinates (See Reference)
    # This is the width available to display all the elements on the screen
    # Now we assign x-coordinates, from the right to left of the screen

    for car in cars:  # We assign x-coordinates to the elevator cars
        x -= (capacity + 1) * xvisitor_dim  # Each car must contain visitors
        xcar[car] = x  # We store the car x-coordinate in the dictionary
    x -= xvisitor_dim  # Additional space (one square)
    xsign = x  # Position of the text with the number of floor
    x -= xvisitor_dim / 2  # Additional space (half square)
    for direction in (up, down):  # Position of the leds (red/green)
        x -= xvisitor_dim / 2
        xled[direction] = x  # We store the led x-coordinates in the dictionary
    x -= xvisitor_dim  # Another square to the right
    xwait = x  # Where to show the queues at different floors

    for floor in floors:  # Components needed to display the floors
        y = yfloor0 + floor.n * yvisitor_dim  # y-coordinate of the floors
        floor.y = y
        for direction in (up, down):  # Led indicating the direction of the car
            if (direction == up and floor.n < topfloor) or (direction == down and floor.n > 0):
                b = xvisitor_dim / 4  # Dimension used to define the triangle
                animate_led = sim.AnimatePolygon(  # See Reference AnimatePolygon
                    spec=(-b, -b, b, -b, 0, b),  # this is triangle
                    x=xled[direction],
                    y=y + 2 * b,
                    angle=0 if direction == up else 180,  #  up points up, down points down
                    fillcolor=direction_color(direction),  #  up is red, down is green
                    visible=lambda arg, t: arg in requests,
                    arg=(floor, direction),
                )
                #  if (floor, direction) in requests, show, otherwise do not show

        sim.AnimateLine(x=0, y=y, spec=(0, 0, xwait, 0))  # Horizontal lines for floors
        sim.AnimateText(
            x=xsign, y=y + yvisitor_dim / 2, text=str(floor.n), fontsize=xvisitor_dim / 2
        )  # Text indicating the floor number

        sim.AnimateQueue(queue=floor.visitors, x=xwait - xvisitor_dim, y=floor.y, direction="w")
import salabim as sim

'''
This program demonstrates the various animation classes available in salabim.
'''

env = sim.Environment(trace=False)
env.animate(True)
env.modelname('Demo animation classes')
env.background_color('20%gray')

sim.AnimatePolygon(spec=(100, 100, 300, 100, 200,190), text='This is\na polygon')
sim.AnimateLine(spec=(100, 200, 300, 300), text='This is a line')
sim.AnimateRectangle(spec=(100, 10, 300, 30), text='This is a rectangle')
sim.AnimateCircle(radius=60, x=100, y=400, text='This is a cicle')
sim.AnimateCircle(radius=60, radius1=30, x=300, y=400,text='This is an ellipse')
sim.AnimatePoints(spec=(100,500, 150, 550, 180, 570, 250, 500, 300, 500), text='These are points')
sim.AnimateText(text='This is a one-line text', x=100, y=600)
sim.AnimateText(text='''\
Multi line text
-----------------
Lorem ipsum dolor sit amet, consectetur
adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud
exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat. Duis aute
irure dolor in reprehenderit in voluptate
velit esse cillum dolore eu fugiat nulla
pariatur.
Exemple #7
0
    def setup(
        self,
        model,
        buffer,
        img_x=None,
        img_y=None,
        img_w=GLOB_PROCESS_WIDTH,
        img_h=GLOB_PROCESS_HEIGHT,
    ):

        # model
        self.model = model

        # initial attributes
        self.buffer = buffer
        self.img_x = img_x
        self.img_y = img_y
        self.img_w = img_w
        self.img_h = img_h

        # flags
        self.job = None
        self.state = "idle"

        # visualization
        if self.model.env.animate() == True:
            self.img = sim.AnimatePolygon(
                spec=(
                    0,
                    0,
                    self.img_w - (self.img_w / 300) * 50,
                    0,
                    self.img_w,
                    self.img_h / 2,
                    self.img_w - (self.img_w / 300) * 50,
                    self.img_h,
                    0,
                    self.img_h,
                    (self.img_w / 300) * 50,
                    self.img_h / 2,
                    0,
                    0,
                ),
                x=self.img_x,
                y=self.img_y,
                fillcolor="white",
                linecolor="black",
                linewidth=2,
                text=self.name() + "\n\nidle",
                fontsize=GLOB_FONTSIZE,
                textcolor="black",
                layer=1,
                screen_coordinates=True,
            )
            self.buffer_connection = sim.AnimateLine(
                spec=(
                    self.buffer.img_x + self.buffer.img_w,
                    self.buffer.img_y + self.buffer.img_h / 2,
                    self.img_x + 50,
                    self.img_y + self.img_h / 2,
                ),
                linecolor="black",
                linewidth=2,
                layer=2,
                screen_coordinates=True,
            )