Esempio n. 1
0
def do_animation():
    global ylevel, xdoor, waterdepth

    lockheight = 5
    waterdepth = 2
    ylevel = {left: 0, right: lockheight}
    xdoor = {left: -0.5 * locklength, right: 0.5 * locklength}
    xbound = {left: -1 * locklength, right: 1 * locklength}
    yspace = 5

    env.animation_parameters(
        x0=xbound[left], y0=-waterdepth, x1=xbound[right], modelname='Lock', speed=8)

    for side in [left, right]:
        x = xdoor[side]
        for i in range(10):
            y = 10 + ylevel[side] + i * yspace
            AnimateWaitShip(part=0, index=i, x=x, y=y, side=side)
            AnimateWaitShip(part=1, index=i, x=x, y=y, side=side)
    for i in range(4):
        y = ylevel[left]
        AnimateLockShip(part=0, index=i, y=y)
        AnimateLockShip(part=1, index=i, y=y)

    sim.Animate(rectangle0=(
        xbound[left], ylevel[left] - waterdepth,
        xdoor[left], ylevel[left]), fillcolor0='aqua', linewidth0=0)
    sim.Animate(rectangle0=(
        xdoor[right], ylevel[right] - waterdepth,
        xbound[right], ylevel[right]), fillcolor0='aqua', linewidth0=0)
    a = sim.Animate(rectangle0=(0, 0, 0, 0), fillcolor0='aqua', linewidth0=0)
    a.rectangle = lock_water_rectangle
    a = sim.Animate(rectangle0=(0, 0, 0, 0), fillcolor0='black', linewidth0=0)
    a.rectangle = lock_door_left_rectangle
    a = sim.Animate(rectangle0=(0, 0, 0, 0), fillcolor0='black', linewidth0=0)
    a.rectangle = lock_door_right_rectangle

    a = sim.Animate(text='', x0=10, y0=650, screen_coordinates=True,
        fontsize0=15, font='narrow', anchor='w')
    a.text = lambda t: 'mean waiting left : {:5.1f} (n={})'.\
        format(key_in[left].requesters().length_of_stay.mean(),
           key_in[left].requesters().length_of_stay.number_of_entries())
    a = sim.Animate(text='', x0=10, y0=630, screen_coordinates=True,
        fontsize0=15, font='narrow', anchor='w')
    a.text = lambda t: 'mean waiting right: {:5.1f} (n={})'.\
        format(key_in[right].requesters().length_of_stay.mean(),
           key_in[right].requesters().length_of_stay.number_of_entries())
    a = sim.Animate(text='xx=12.34', x0=10, y0=610, screen_coordinates=True,
        fontsize0=15, font='narrow', anchor='w')
    a.text = lambda t: '  nr waiting left : {:3d}'.format(
        key_in[left].requesters().length())
    a = sim.Animate(text='xx=12.34', x0=10, y0=590, screen_coordinates=True,
        fontsize0=15, font='narrow', anchor='w')
    a.text = lambda t: '  nr waiting right: {:3d}'.format(
        key_in[right].requesters().length())

    sim.AnimateSlider(x=520, y=env.height, width=100, height=20,
        vmin=16, vmax=60, resolution=4, v=iat, label='iat', action=set_iat)
    sim.AnimateSlider(x=660, y=env.height, width=100, height=20,
        vmin=10, vmax=60, resolution=5, v=meanlength, label='mean length', action=set_meanlength)
Esempio n. 2
0
def do_animation():
    global nphilosophers, eatingtime_mean, thinkingtime_mean
    global nphilosophers_last
    env.animation_parameters(
        x0=-50 * env.width() / env.height(),
        y0=-50,
        x1=+50 * env.width() / env.height(),
        modelname="Dining philosophers",
        speed=8,
        background_color="20%gray",
    )
    for i, _ in enumerate(philosopher):
        AnimatePhilosopher(i=i)
        AnimateFork(i=i)
    sim.AnimateSlider(
        x=520,
        y=env.height(),
        width=100,
        height=20,
        vmin=10,
        vmax=40,
        resolution=5,
        v=eatingtime_mean,
        label="eating time",
        action=set_eatingtime_mean,
    )
    sim.AnimateSlider(
        x=660,
        y=env.height(),
        width=100,
        height=20,
        vmin=10,
        vmax=40,
        resolution=5,
        v=thinkingtime_mean,
        label="thinking time",
        action=set_thinkingtime_mean,
    )
    sim.AnimateSlider(
        x=520 + 50,
        y=env.height() - 50,
        width=200,
        height=20,
        vmin=3,
        vmax=40,
        resolution=1,
        v=nphilosophers,
        label="# philosophers",
        action=set_nphilosophers,
    )
    nphilosophers_last = nphilosophers
def do_animation():
    global nphilosophers, eatingtime_mean, thinkingtime_mean
    global nphilosophers_last
    env.animation_parameters(x0=-50 * env.width / env.height, y0=-50, x1=+50 * env.width / env.height,
                             modelname='Dining philosophers',
                             speed=8)
    for i in philosopher:
        AnimatePhilosopher(i=i)
        AnimateFork(i=i)
    sim.AnimateSlider(x=520, y=env.height, width=100, height=20,
        vmin=10, vmax=40, resolution=5, v=eatingtime_mean, label='eating time', action=set_eatingtime_mean)
    sim.AnimateSlider(x=660, y=env.height, width=100, height=20,
        vmin=10, vmax=40, resolution=5, v=thinkingtime_mean, label='thinking time', action=set_thinkingtime_mean)
    sim.AnimateSlider(x=520 + 50, y=env.height - 50, width=200, height=20,
        vmin=3, vmax=40, resolution=1, v=nphilosophers, label='# philosophers', action=set_nphilosophers)
    nphilosophers_last = nphilosophers
Esempio n. 4
0
def test17():
    def actiona():
        bb.remove()
        sl.remove()

    def actionb():
        ba.remove()

    de = sim.Environment()

    for x in range(10):
        for y in range(10):
            a = sim.Animate(rectangle0=(0, 0, 95, 65),
                            x0=5 + x * 100,
                            y0=5 + y * 70,
                            fillcolor0='blue',
                            linewidth0=0)
    ba = sim.AnimateButton(x=100, y=700, text='A', action=actiona)
    bb = sim.AnimateButton(x=200, y=700, text='B', action=actionb)
    sl = sim.AnimateSlider(x=300, y=700, width=300)
    sim.Animate(text='Text',
                x0=700,
                y0=750,
                font='Times NEWRomian Italic',
                fontsize0=30)
    de.animation_parameters(animate=True)
    sim.run(5)
    sim.animation_parameters(animate=False)
    sim.run(100)
    sim.animation_parameters(animate=True, background_color='yellow')
    sim.run(10)
Esempio n. 5
0
def test52():
    class X(sim.Component):
        def process(self):
#            env.animation_parameters(animate=False)
            while env.now()<=6:
                an.update(text=str(env.now()), x0=env.now()*10)
                yield self.hold(1)
            env.animate(True)
            while env.now()<=12:
                an.update(text=str(env.now()),x0=env.now()*10)
                yield self.hold(1)
            env.animation_parameters(animate=False)
            while env.now()<=20:
                an.update(text=str(env.now()),x0=env.now()*10)
                yield self.hold(1)
            env.animation_parameters(animate=True, modelname='something else', background_color='90%gray',x0=-100, width =500, height=500)
            env.x0(-100)
            while env.now()<=25:
                an.update(text=str(env.now()),x0=env.now()*10, textcolor0='red')
                yield self.hold(1)

    def printt(str2prn):
        return '['+str(env.now())+']',str2prn
    sim.reset()
    logging.basicConfig(filename='sim.log', filemode='w', level=logging.DEBUG)
    print('***can_animate',sim.can_animate(try_only=True))

    try:
        print('***can_animate',sim.can_animate(try_only=False))
    except:
        print('failed')
    print('***can_video',sim.can_video())
    print('passed.')
    env=sim.Environment(trace=True)
    logging.debug(printt('piet'))
    env.animation_parameters(animate=True, modelname='test52', video='')
    s = sim.AnimateSlider(x=300,y=-50,xy_anchor='nw')
    a=sim.Animate(line0=(0,-50,300,-50), xy_anchor='nw',screen_coordinates=True)
#    env.animate(True)

    X()
    an = sim.Animate(text='Test',x0=100, y0 =100)
    r = sim.Animate(rectangle0=(100,100,200,200),x0=0,y0=10)
    r = sim.Animate(circle0=(1.11,),x0=0,y0=10,fillcolor0='red')
    l = sim.Animate(polygon0=(10,10,20,20,10,20), fillcolor0='bg',linecolor0='fg',linewidth0=0.1)
    b = sim.AnimateButton(text='My button', x=-100, y=-20, xy_anchor='ne')
    env.run(10)
    env.run(20)
    env.quit()
def do_animation():
    global nphilosophers, eatingtime_mean, thinkingtime_mean
    global nphilosophers_last
    env.animation_parameters(x0=-50 * env.width() / env.height(),
                             y0=-50,
                             x1=+50 * env.width() / env.height(),
                             modelname='Dining philosophers',
                             speed=8)

    alpha = 360 / nphilosophers
    r1 = 25
    r2 = r1 * sin(radians(alpha) / 4)
    for philosopher in philosophers:
        angle = philosopher.sequence_number() * alpha
        an = sim.AnimateCircle(x=r1 * cos(radians(angle)),
                               y=r1 * sin(radians(angle)),
                               radius=r2,
                               linewidth=0,
                               fillcolor=philosopher_fillcolor,
                               screen_coordinates=False)
        an.philosopher = philosopher

    for fork in forks:
        angle = (fork.sequence_number() + 0.5) * alpha
        an = sim.AnimateLine(x=0,
                             y=0,
                             spec=(r1 - r2, 0, r1 + r2, 0),
                             linewidth=r2 / 4,
                             linecolor='green',
                             angle=fork_angle)
        an.fork = fork
        an.left_philosopher = philosophers[fork.sequence_number()]
        an.angle_mid = angle
        an.angle_left = angle - 0.2 * alpha
        an.angle_right = angle + 0.2 * alpha


#        an.angle = forkangle

    sim.AnimateSlider(x=520,
                      y=0,
                      width=100,
                      height=20,
                      vmin=10,
                      vmax=40,
                      resolution=5,
                      v=eatingtime_mean,
                      label='eating time',
                      action=set_eatingtime_mean,
                      xy_anchor='nw')
    sim.AnimateSlider(x=660,
                      y=0,
                      width=100,
                      height=20,
                      vmin=10,
                      vmax=40,
                      resolution=5,
                      v=thinkingtime_mean,
                      label='thinking time',
                      action=set_thinkingtime_mean,
                      xy_anchor='nw')
    sim.AnimateSlider(x=520 + 50,
                      y=-50,
                      width=200,
                      height=20,
                      vmin=3,
                      vmax=40,
                      resolution=1,
                      v=nphilosophers,
                      label='# philosophers',
                      action=set_nphilosophers,
                      xy_anchor='nw')
    nphilosophers_last = nphilosophers
Esempio n. 7
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)
def do_animation():
    global ylevel, xdoor, waterdepth

    lockheight = 5
    waterdepth = 2
    ylevel = {left: 0, right: lockheight}
    xdoor = {left: -0.5 * locklength, right: 0.5 * locklength}
    xbound = {left: -1.2 * locklength, right: 1.2 * locklength}

    sim.Environment.animation_pre_tick = animation_pre_tick
    env.animation_parameters(x0=xbound[left],
                             y0=-waterdepth,
                             x1=xbound[right],
                             modelname='Lock',
                             speed=8,
                             background_color='20%gray')

    for side in [left, right]:
        wait[side].animate(x=xdoor[side], y=10 + ylevel[side], direction='n')

    sim.Animate(rectangle0=(xbound[left], ylevel[left] - waterdepth,
                            xdoor[left], ylevel[left]),
                fillcolor0='aqua')
    sim.Animate(rectangle0=(xdoor[right], ylevel[right] - waterdepth,
                            xbound[right], ylevel[right]),
                fillcolor0='aqua')
    a = sim.Animate(rectangle0=(0, 0, 0, 0), fillcolor0='aqua')
    a.rectangle = lock_water_rectangle
    a = sim.Animate(rectangle0=(0, 0, 0, 0))
    a.rectangle = lock_door_left_rectangle
    a = sim.Animate(rectangle0=(0, 0, 0, 0))
    a.rectangle = lock_door_right_rectangle

    a = sim.Animate(text='',
                    x0=10,
                    y0=650,
                    screen_coordinates=True,
                    fontsize0=15,
                    font='narrow',
                    anchor='w')
    a.text = lambda t: 'mean waiting left : {:5.1f} (n={})'.\
        format(wait[left].length_of_stay.mean(),
        wait[left].length_of_stay.number_of_entries())
    a = sim.Animate(text='',
                    x0=10,
                    y0=630,
                    screen_coordinates=True,
                    fontsize0=15,
                    font='narrow',
                    anchor='w')
    a.text = lambda t: 'mean waiting right: {:5.1f} (n={})'.\
        format(wait[right].length_of_stay.mean(),
        wait[right].length_of_stay.number_of_entries())
    a = sim.Animate(text='xx=12.34',
                    x0=10,
                    y0=610,
                    screen_coordinates=True,
                    fontsize0=15,
                    font='narrow',
                    anchor='w')
    a.text = lambda t: '  nr waiting left : {:3d}'.format(wait[left].length())
    a = sim.Animate(text='xx=12.34',
                    x0=10,
                    y0=590,
                    screen_coordinates=True,
                    fontsize0=15,
                    font='narrow',
                    anchor='w')
    a.text = lambda t: '  nr waiting right: {:3d}'.format(wait[right].length())

    sim.AnimateSlider(x=520,
                      y=0,
                      width=100,
                      height=20,
                      vmin=16,
                      vmax=60,
                      resolution=4,
                      v=iat,
                      label='iat',
                      action=set_iat,
                      xy_anchor='nw')
    sim.AnimateSlider(x=660,
                      y=0,
                      width=100,
                      height=20,
                      vmin=10,
                      vmax=60,
                      resolution=5,
                      v=meanlength,
                      label='mean length',
                      action=set_meanlength,
                      xy_anchor='nw')
Esempio n. 9
0
def do_animation():

    global xvisitor_dim
    global yvisitor_dim
    global capacity_last, ncars_last, topfloor_last

    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.values():
        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):
                AnimateLED(x=xled[direction], y=y + 6, floor=floor, direction=direction)
        sim.Animate(x0=0, y0=y, line0=(0, 0, xwait, 0), linecolor0='black')
        sim.Animate(x0=xsign, y0=y + yvisitor_dim / 2,
            text=str(floor.n), fontsize0=xvisitor_dim / 2, anchor='center')

        x = xwait - xvisitor_dim
        index = 0
        while x > 0:
            AnimateFloorVisitor(x=x, y=y, floor=floor, index=index, part=0)
            AnimateFloorVisitor(x=x, y=y, floor=floor, index=index, part=1)
            x -= xvisitor_dim
            index += 1

    for car in cars:
        AnimateCar(x=xcar[car], car=car)
        x = xcar[car]
        for index in range(capacity):
            AnimateCarVisitor(x=x, car=car, index=index, part=0)
            AnimateCarVisitor(x=x, car=car, index=index, part=1)
            x += xvisitor_dim

    ncars_last = ncars
    ui_ncars = sim.AnimateSlider(x=540, y=env.height, width=90, height=20,
        vmin=1, vmax=5, resolution=1, v=ncars, label='#elevators', action=set_ncars)

    topfloor_last = topfloor
    ui_topfloor = sim.AnimateSlider(x=640, y=env.height, width=90, height=20,
        vmin=5, vmax=20, resolution=1, v=topfloor, label='top floor', action=set_topfloor)

    capacity_last = capacity
    ui_capacity = sim.AnimateSlider(x=740, y=env.height, width=90, height=20,
        vmin=2, vmax=6, resolution=1, v=capacity, label='capacity', action=set_capacity)

    ui_load_0_n = sim.AnimateSlider(x=540, y=env.height - 50, width=90, height=25,
        vmin=0, vmax=400, resolution=25, v=load_0_n, label='Load 0->n', action=set_load_0_n)

    ui_load_n_n = sim.AnimateSlider(x=640, y=env.height - 50, width=90, height=25,
        vmin=0, vmax=400, resolution=25, v=load_n_n, label='Load n->n', action=set_load_n_n)

    ui_load_n_0 = sim.AnimateSlider(x=740, y=env.height - 50, width=90, height=25,
        vmin=0, vmax=400, resolution=25, v=load_n_0, label='Load n->0', action=set_load_n_0)

    if make_video:
        sim.animation_parameters(modelname='Elevator',speed=32,video='Elevator.mp4',
            show_speed=False,show_fps=False)
    else:
        sim.animation_parameters(modelname='Elevator', speed=32)
Esempio n. 10
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)
Esempio n. 11
0
def do_animation():
    global ylevel, xdoor, waterdepth

    lockheight = 5
    waterdepth = 2
    ylevel = {left: 0, right: lockheight}
    xdoor = {left: -0.5 * locklength, right: 0.5 * locklength}
    xbound = {left: -1.2 * locklength, right: 1.2 * locklength}

    env.animation_parameters(x0=xbound[left],
                             y0=-waterdepth,
                             x1=xbound[right],
                             modelname='Lock',
                             speed=8,
                             background_color='20%gray')

    for side in [left, right]:
        sim.AnimateQueue(queue=wait[side],
                         x=xdoor[side],
                         y=10 + ylevel[side],
                         direction='n')

    sim.AnimateRectangle(spec=(xbound[left], ylevel[left] - waterdepth,
                               xdoor[left], ylevel[left]),
                         fillcolor='aqua')
    sim.AnimateRectangle(spec=(xdoor[right], ylevel[right] - waterdepth,
                               xbound[right], ylevel[right]),
                         fillcolor='aqua')
    sim.AnimateRectangle(spec=lock_water_rectangle, fillcolor='aqua')
    sim.AnimateRectangle(spec=lock_door_left_rectangle)
    sim.AnimateRectangle(spec=lock_door_right_rectangle)

    sim.AnimateSlider(x=520,
                      y=0,
                      width=100,
                      height=20,
                      vmin=16,
                      vmax=60,
                      resolution=4,
                      v=iat,
                      label='iat',
                      action=set_iat,
                      xy_anchor='nw')
    sim.AnimateSlider(x=660,
                      y=0,
                      width=100,
                      height=20,
                      vmin=10,
                      vmax=60,
                      resolution=5,
                      v=meanlength,
                      label='mean length',
                      action=set_meanlength,
                      xy_anchor='nw')
    sim.AnimateMonitor(
        wait[left].length,
        linecolor='orange',
        fillcolor='bg',
        x=-225,
        y=-200,
        xy_anchor='n',
        horizontal_scale=1,
        width=450,
        linewidth=2,
        title=lambda: 'Number of waiting ships left. Mean={:10.2f}'.format(
            wait[left].length.mean()))
    sim.AnimateMonitor(
        wait[right].length,
        linecolor='orange',
        fillcolor='bg',
        x=-225,
        y=-300,
        xy_anchor='n',
        horizontal_scale=1,
        width=450,
        linewidth=2,
        title=lambda: 'Number of waiting ships right. Mean={:10.2f}'.format(
            wait[right].length.mean()))
    sim.AnimateMonitor(
        wait[left].length_of_stay,
        linecolor='white',
        fillcolor='bg',
        x=-225,
        y=-400,
        xy_anchor='n',
        vertical_scale=0.5,
        horizontal_scale=5,
        as_points=True,
        width=450,
        height=75,
        linewidth=4,
        title=lambda: 'Waiting time of ships left. Mean={:10.2f}'.format(wait[
            left].length_of_stay.mean()))
    sim.AnimateMonitor(
        wait[right].length_of_stay,
        linecolor='white',
        fillcolor='bg',
        x=-225,
        y=-500,
        xy_anchor='n',
        vertical_scale=0.5,
        horizontal_scale=5,
        as_points=True,
        width=450,
        height=75,
        linewidth=4,
        title=lambda: 'Waiting time of ships left. Mean={:10.2f}'.format(wait[
            right].length_of_stay.mean()))

    sim.AnimateQueue(queue=lockqueue,
                     x=lambda: xdoor[-lock.sideq],
                     y=lock_y,
                     direction=lambda: 'w' if lock.sideq == left else 'e')
Esempio n. 12
0
def do_animation():

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

    if make_video:
        env.animation_parameters(modelname='Elevator',
                                 speed=32,
                                 video='Elevator.mp4',
                                 show_fps=False,
                                 background_color='20%gray')
    else:
        env.animation_parameters(modelname='Elevator',
                                 speed=32,
                                 background_color='20%gray')

    sim.Environment.animation_pre_tick = animation_pre_tick

    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):
                AnimateLED(x=xled[direction],
                           y=y + 6,
                           floor=floor,
                           direction=direction)
        sim.Animate(x0=0, y0=y, line0=(0, 0, xwait, 0))
        sim.Animate(x0=xsign,
                    y0=y + yvisitor_dim / 2,
                    text=str(floor.n),
                    fontsize0=xvisitor_dim / 2,
                    anchor='center')

        floor.visitors.animate(x=xwait - xvisitor_dim,
                               y=floor.y,
                               direction='w')

    for car in cars:
        x = xcar[car]
        car.pic = sim.Animate(x0=x,
                              rectangle0=(0, 0, capacity * xvisitor_dim,
                                          yvisitor_dim),
                              fillcolor0='lightblue',
                              linewidth0=0)
        car.visitors.animate(x=xcar[car], y=600, direction='e')

    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.animating = True
Esempio n. 13
0
def do_animation():
    global ylevel, xdoor, waterdepth

    lockheight = 5
    waterdepth = 2
    ylevel = {left: 0, right: lockheight}
    xdoor = {left: -0.5 * locklength, right: 0.5 * locklength}
    xbound = {left: -1.2 * locklength, right: 1.2 * locklength}

    env.animation_parameters(
        x0=xbound[left], y0=-waterdepth, x1=xbound[right], modelname="Lock", speed=8, background_color="20%gray"
    )

    for side in [left, right]:
        sim.AnimateQueue(queue=wait[side], x=xdoor[side], y=10 + ylevel[side], direction="n", title="")

    sim.AnimateRectangle(spec=(xbound[left], ylevel[left] - waterdepth, xdoor[left], ylevel[left]), fillcolor="aqua")
    sim.AnimateRectangle(
        spec=(xdoor[right], ylevel[right] - waterdepth, xbound[right], ylevel[right]), fillcolor="aqua"
    )
    sim.AnimateRectangle(spec=lock_water_rectangle, fillcolor="aqua")
    sim.AnimateRectangle(spec=lock_door_left_rectangle)
    sim.AnimateRectangle(spec=lock_door_right_rectangle)

    sim.AnimateSlider(
        x=520,
        y=0,
        width=100,
        height=20,
        vmin=16,
        vmax=60,
        resolution=4,
        v=iat,
        label="iat",
        action=set_iat,
        xy_anchor="nw",
    )
    sim.AnimateSlider(
        x=660,
        y=0,
        width=100,
        height=20,
        vmin=10,
        vmax=60,
        resolution=5,
        v=meanlength,
        label="mean length",
        action=set_meanlength,
        xy_anchor="nw",
    )
    sim.AnimateMonitor(
        wait[left].length,
        linecolor="orange",
        fillcolor="bg",
        x=-225,
        y=-200,
        xy_anchor="n",
        horizontal_scale=1,
        width=450,
        linewidth=2,
        title=lambda: "Number of waiting ships left. Mean={:10.2f}".format(wait[left].length.mean()),
    )
    sim.AnimateMonitor(
        wait[right].length,
        linecolor="orange",
        fillcolor="bg",
        x=-225,
        y=-300,
        xy_anchor="n",
        horizontal_scale=1,
        width=450,
        linewidth=2,
        title=lambda: "Number of waiting ships right. Mean={:10.2f}".format(wait[right].length.mean()),
    )
    sim.AnimateMonitor(
        wait[left].length_of_stay,
        linecolor="white",
        fillcolor="bg",
        x=-225,
        y=-400,
        xy_anchor="n",
        vertical_scale=0.5,
        horizontal_scale=1,
        width=450,
        height=75,
        linewidth=4,
        title=lambda: "Waiting time of ships left. Mean={:10.2f}".format(wait[left].length_of_stay.mean()),
    )
    sim.AnimateMonitor(
        wait[right].length_of_stay,
        linecolor="white",
        fillcolor="bg",
        x=-225,
        y=-500,
        xy_anchor="n",
        vertical_scale=0.5,
        horizontal_scale=1,
        width=450,
        height=75,
        linewidth=4,
        title=lambda: "Waiting time of ships left. Mean={:10.2f}".format(wait[right].length_of_stay.mean()),
    )

    sim.AnimateQueue(
        queue=lockqueue,
        x=lambda: xdoor[-lock.sideq],
        y=lock_y,
        direction=lambda: "w" if lock.sideq == left else "e",
        title="",
    )
            linewidth=0,
        )
        sim.AnimateQueue(queue=car.visitors, x=xcar[car], y=car.y, direction="e", arg=car)
        #  note that both the rectangle and the queue have a dynamic y-coordinate that
        #  is controlled by the car.y method

    # The following Animate elements are sliders, which allow controlling different variables
    # on the animation screen
    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,
Esempio n. 15
0
def do_animation():
    env.animation_parameters(x0=-50 * env.width() / env.height(),
                             y0=-50,
                             x1=+50 * env.width() / env.height(),
                             modelname='Dining philosophers',
                             speed=8)

    alpha = 360 / nphilosophers
    r1 = 25
    r2 = r1 * sin(radians(alpha) / 4)
    for philosopher in philosophers:
        angle = philosopher.sequence_number() * alpha
        an = sim.Animate(x0=r1 * cos(radians(angle)),
                         y0=r1 * sin(radians(angle)),
                         circle0=r2,
                         linewidth0=0)
        an.philosopher = philosopher
        an.fillcolor = types.MethodType(philosopher_fillcolor, an)

    for fork in forks:
        angle = (fork.sequence_number() + 0.5) * alpha
        an = sim.Animate(x0=0,
                         y0=0,
                         line0=(r1 - r2, 0, r1 + r2, 0),
                         linewidth0=r2 / 4,
                         linecolor0='green')
        an.fork = fork
        an.left_philosopher = philosophers[fork.sequence_number()]
        an.angle_mid = angle
        an.angle_left = angle - 0.2 * alpha
        an.angle_right = angle + 0.2 * alpha
        an.angle = types.MethodType(fork_angle, an)

    sim.AnimateSlider(x=520,
                      y=0,
                      width=100,
                      height=20,
                      vmin=10,
                      vmax=40,
                      resolution=5,
                      v=eatingtime_mean,
                      label='eating time',
                      action=set_eatingtime_mean,
                      xy_anchor='nw')
    sim.AnimateSlider(x=660,
                      y=0,
                      width=100,
                      height=20,
                      vmin=10,
                      vmax=40,
                      resolution=5,
                      v=thinkingtime_mean,
                      label='thinking time',
                      action=set_thinkingtime_mean,
                      xy_anchor='nw')
    sim.AnimateSlider(x=520 + 50,
                      y=-50,
                      width=200,
                      height=20,
                      vmin=3,
                      vmax=40,
                      resolution=1,
                      v=nphilosophers,
                      label='# philosophers',
                      action=set_nphilosophers,
                      xy_anchor='nw')
    nphilosophers_last = nphilosophers
Esempio n. 16
0
def do_animation():
    global ylevel, xdoor, waterdepth

    lockheight = 5  # Maximum height of the water inside the lock
    waterdepth = 2  # Minimum level of water
    ylevel = {
        left: 0,
        right: lockheight
    }  # Dictionary, defining the (fixed) water level at both sides of the lock
    xdoor = {
        left: -0.5 * locklength,
        right: 0.5 * locklength
    }  # x-coordinate of the doors
    xbound = {
        left: -1.2 * locklength,
        right: 1.2 * locklength
    }  # x-coordinate of the limits of the screen

    # animation_parameters is a method of salabim.Environment to set animation parameters and to start the animation
    env.animation_parameters(x0=xbound[left],
                             y0=-waterdepth,
                             x1=xbound[right],
                             modelname="Lock",
                             speed=8,
                             background_color="20%gray")

    for side in [left, right]:
        sim.AnimateQueue(queue=wait[side],
                         x=xdoor[side],
                         y=10 + ylevel[side],
                         direction="n")
        # AnimateQueue is a class of Salabim to animate the component in a queue
        # wait[left] and wait[right] are ship queues at both sides of the lock

    # AnimateRectangle is a class of Salabim to display a rectangle, optinally with a text
    # The first rectangle represents the water at the left side of the lock (fixed level)
    sim.AnimateRectangle(spec=(xbound[left], ylevel[left] - waterdepth,
                               xdoor[left], ylevel[left]),
                         fillcolor="aqua")
    # The second rectangle represents the water at the right side of the lock (fixed level)
    sim.AnimateRectangle(spec=(xdoor[right], ylevel[right] - waterdepth,
                               xbound[right], ylevel[right]),
                         fillcolor="aqua")
    # The third rectangle represents the water inside the lock, which will be switching
    sim.AnimateRectangle(spec=lock_water_rectangle, fillcolor="aqua")
    # The fourth rectangle is the left door, which will be apearing and dissapearing
    sim.AnimateRectangle(spec=lock_door_left_rectangle)
    # The fifth rectangle is the right door, which will be apearing and dissapearing
    sim.AnimateRectangle(spec=lock_door_right_rectangle)

    # AnimateSlider is a class of Salabim to allow adjusting some parameters on the screen during the simulation
    # In this example, we can adjust the interarrival time and the ships mean length
    sim.AnimateSlider(
        x=520,
        y=0,
        width=100,
        height=20,
        vmin=16,
        vmax=60,
        resolution=4,
        v=iat,
        label="iat",
        action=set_iat,
        xy_anchor="nw",
    )
    sim.AnimateSlider(
        x=660,
        y=0,
        width=100,
        height=20,
        vmin=10,
        vmax=60,
        resolution=5,
        v=meanlength,
        label="mean length",
        action=set_meanlength,
        xy_anchor="nw",
    )

    # The class AnimateMonitor allows display monitors on the screen while running the simulation
    sim.AnimateMonitor(
        wait[left].length,
        linecolor="orange",
        fillcolor="bg",
        x=-225,
        y=-200,
        xy_anchor="n",
        horizontal_scale=1,
        width=450,
        linewidth=2,
        title=lambda: "Number of waiting ships left. Mean={:10.2f}".format(
            wait[left].length.mean()),
    )
    sim.AnimateMonitor(
        wait[right].length,
        linecolor="orange",
        fillcolor="bg",
        x=-225,
        y=-300,
        xy_anchor="n",
        horizontal_scale=1,
        width=450,
        linewidth=2,
        title=lambda: "Number of waiting ships right. Mean={:10.2f}".format(
            wait[right].length.mean()),
    )
    sim.AnimateMonitor(
        wait[left].length_of_stay,
        linecolor="white",
        fillcolor="bg",
        x=-225,
        y=-400,
        xy_anchor="n",
        vertical_scale=0.5,
        horizontal_scale=5,
        as_points=True,
        width=450,
        height=75,
        linewidth=4,
        title=lambda: "Waiting time of ships left. Mean={:10.2f}".format(wait[
            left].length_of_stay.mean()),
    )
    sim.AnimateMonitor(
        wait[right].length_of_stay,
        linecolor="white",
        fillcolor="bg",
        x=-225,
        y=-500,
        xy_anchor="n",
        vertical_scale=0.5,
        horizontal_scale=5,
        as_points=True,
        width=450,
        height=75,
        linewidth=4,
        title=lambda: "Waiting time of ships left. Mean={:10.2f}".format(wait[
            right].length_of_stay.mean()),
    )

    # There is another queue in the system, the one inside the lock while switching: lockqueue
    sim.AnimateQueue(queue=lockqueue,
                     x=lambda: xdoor[-lock.sideq],
                     y=lock_y,
                     direction=lambda: "w" if lock.sideq == left else "e")