Beispiel #1
0
def test57():
    class X(sim.Component):
        def process(self):
            while env.now()<run_length:
                an.update(text=str(run_length - env.now()))
                yield self.hold(1)
            env.animation_parameters(animate=False)
            print(self.env._animate)
#            yield self.hold(0)
            env.video('')
            env.main().activate()
     
    env = sim.Environment()
    env.animation_parameters(background_color='blue', modelname='test')
    env.video('test.gif')
    env.video_pingpong(False)
    env.video_repeat(2)

#    env.animation_parameters(video='test.avi+MP4V', speed=0.5)
    an = sim.Animate(text='', x0=100,y0=100, fontsize0=100)
    run_length = 1
    
    X()
    sim.Animate(line0=(0,50,None,None), line1=(0,50,1024,None), linewidth0=4,t1=run_length)
    sim.Animate(circle0=(40,), x0=200, y0=200)
    sim.Animate(circle0=40, x0=300, y0=200)
    env.run()
    print('done')
    env.quit()
Beispiel #2
0
def do_animation():
    servers.requesters().animate(x=800, y=200)
    servers.claimers().animate(x=900, y=200, direction='n')

    sim.Animate(text='Server', x0=900, y0=200 - 50, anchor='n')
    sim.Animate(text='<-- Waiting line', x0=900 - 145, y0=200 - 50, anchor='n')
    env.animation_parameters(modelname='M/M/c')
Beispiel #3
0
 def setup(self, job_generator):
     self.tasks = sim.Queue(fill=[
         Task(job_generator=job_generator,
              job=self,
              name='Task ' + str(self.sequence_number()) + '.')
         for _ in range(job_generator.number_of_tasks_dist())
     ],
                            name='tasks.')
     self.task_in_execution = sim.Queue(name='task_in_execution.')
     self.slack = start_slack
     self.an_slack = sim.Animate(x0=90, text='', fontsize0=12, anchor='se')
     self.an_label = sim.Animate(x0=50,
                                 text=str(self.sequence_number()),
                                 fontsize0=12,
                                 anchor='se')
     self.an_execute_bar = sim.Animate(x0=100, rectangle0=(0, 0, 70, 12))
     self.an_execute_text = sim.Animate(x0=100,
                                        text='',
                                        fontsize0=12,
                                        anchor='sw',
                                        textcolor0='white',
                                        offsetx0=2,
                                        offsety0=1)
     self.an_due = sim.Animate(line0=(0, -1, 0, 13))
     self.enter(self.tasks[0].group.jobs)
     if self.tasks.head().group.idle_machines:
         self.tasks.head().group.idle_machines.head().activate()
     self.enter(plant)
Beispiel #4
0
def animation():
    env.animation_parameters(synced=False,
                             modelname='Job shop',
                             background_color='20%gray')
    sim.Environment.animation_pre_tick = animation_pre_tick

    max_len = 0
    for i, group in enumerate(groups):
        x = i * 70 + 100 + 2
        y = env.height() - 140 + 20
        sim.Animate(text=group.name(), x0=x, y0=y, anchor='sw', fontsize0=12)
        for machine in group.machines:
            AnimateMachineBox(machine=machine)
            AnimateMachineText(machine=machine)
        max_len = max(max_len, len(group.machines))
    env.y_top = y - max_len * 15 - 15
    sim.Animate(line0=(0, env.y_top, 2000, env.y_top))
    sim.Animate(text='job',
                x0=50,
                y0=env.y_top - 15,
                anchor='ne',
                fontsize0=12)
    sim.Animate(text='slack',
                x0=90,
                y0=env.y_top - 15,
                anchor='ne',
                fontsize0=12)
Beispiel #5
0
 def process(self):
     an1 = sim.Animate(text='sim', x0=227, y0=768 / 2, fontsize0=200)
     an2 = sim.Animate(text='ulation',
                       x0=654,
                       y0=768 / 2,
                       fontsize0=200)
     yield self.hold(3)
     an2.update(y1=900, t1=env.now() + 3)
     an1.update(x1=176, t1=env.now() + 3)
     yield self.hold(3)
     an3 = sim.Animate(text='salabim',
                       x0=676,
                       y0=-100,
                       y1=768 / 2,
                       fontsize0=200,
                       t1=env.now() + 3)
     yield self.hold(6)
     an1.update(x1=-130, t1=env.now() + 3)
     an3.update(x1=512, t1=env.now() + 1.5)
     yield self.hold(4)
     an3.update(fontsize1=300, t1=env.now() + 4, textcolor1='red')
     yield self.hold(6)
     an4 = sim.Animate(text='discrete event simulation',
                       x0=512,
                       y0=220,
                       fontsize0=87)
Beispiel #6
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)
Beispiel #7
0
 def animation_objects(self, value):
     if value=='blue':
         an1=sim.Animate(circle0=(40,),fillcolor0=value, linewidth0=0)
     else:
         an1=sim.Animate(rectangle0=(-40,-20,40,20), fillcolor0=value,linewidth0=0)
     an2=sim.Animate(text=value,textcolor0='white')
     return (an1,an2)
def do_animation():
    waiting_clients.animate(x=800, y=200)
    for i, server in enumerate(servers):
        server.atwork.animate(x=900, y=200 + i * 50)

    sim.Animate(text='Server', x0=900, y0=200 - 50, anchor='n')
    sim.Animate(text='<-- Waiting line', x0=900 - 145, y0=200 - 50, anchor='n')
    env.animation_parameters(modelname='M/M/c')
Beispiel #9
0
def test16():
    de = sim.Environment()
    sim.animation_parameters()
    a = sim.Animate(text='Test',
                    x0=100,
                    y0=100,
                    fontsize0=30,
                    fillcolor0='red')
    a = sim.Animate(line0=(0, 0, 500, 500), linecolor0='white', linewidth0=6)
    sim.run()
Beispiel #10
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)
Beispiel #11
0
def test50():
    env=sim.Environment()
    for i, c in enumerate(string.printable):
        if i <= 94:
            print(i,c)
            sim.Animate(text=c,x0=10+i*10,y0=100,anchor='w')
    sim.Animate(line0=(0, 100, 1024, 100), linecolor0='red')

    env.animation_parameters(modelname='Test')
    env.animating = True
    env.trace(True)
    env.run(5)
    print (env.main()._scheduled_time)
Beispiel #12
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()
Beispiel #13
0
def test20():
    de=sim.Environment()
    y=650
    if Pythonista:
        for t in ('TimesNewRomanPSItalic-MT','Times.NewRoman. PSItalic-MT',
          'TimesNewRomanPSITALIC-MT','TimesNoRomanPSItalic-MT'):
            sim.Animate(text=t,x0=100,y0=y,font=t,fontsize0=30,anchor='w')
            y=y-50
    else:
        for t in ('Times New Roman Italic','TimesNEWRoman   Italic','Times No Roman Italic','timesi','TIMESI'):
            sim.Animate(text=t,x0=100,y0=y,font=t,fontsize0=30,anchor='w')
            y=y-50

    de.animation_parameters(animate=True)
    env.run()
Beispiel #14
0
 def animation_objects(self, q):
     size_x = xvisitor_dim
     size_y = yvisitor_dim
     b = 0.1 * xvisitor_dim
     an1 = sim.Animate(rectangle0=(b, 2, xvisitor_dim - b,
                                   yvisitor_dim - b),
                       linewidth0=0,
                       fillcolor0=direction_color(self.direction))
     an2 = sim.Animate(text=str(self.tofloor.n),
                       fontsize0=xvisitor_dim * 0.7,
                       anchor='center',
                       offsetx0=5 * b,
                       offsety0=2 + 4 * b,
                       textcolor0='white')
     return size_x, size_y, an1, an2
Beispiel #15
0
def do_animation():
    env.animation_parameters()
    for i in range(10):
        AnimateWaitSquare(i)
        AnimateWaitText(i)
    show_length=sim.Animate(text='',x0=330,y0=100,textcolor0='black',anchor='w')
    show_length.text=lambda t: 'Length= '+str(len(q))
Beispiel #16
0
 def process(self):
     car_animate = sim.Animate(x0=100, y0=100, image='')
     while True:
         car_animate.update(image='red.png')
         yield self.hold(1, mode='drive')
         car_animate.update(image='blue.png')
         yield self.hold(1, mode='stand_still')
 def animation_objects(self, q):
     size_x = self.length
     size_y = 5
     if self.side == left:
         anchor = 'se'
     else:
         anchor = 'sw'
     an1 = sim.Animate(polygon0=ship_polygon(self),
                       fillcolor0=shipcolor(self.side),
                       anchor=anchor,
                       linewidth0=0)
     an2 = sim.Animate(text=shortname(self),
                       textcolor0='white',
                       anchor=anchor,
                       fontsize0=2.5,
                       offsetx0=self.side * 5)
     return (size_x, size_y, an1, an2)
Beispiel #18
0
def do_animation():
    env.animation_parameters()
    for i in range(10):
        AnimateWaitSquare(i)
        AnimateWaitText(i)
    show_length = sim.Animate(text="",
                              x0=330,
                              y0=100,
                              textcolor0="black",
                              anchor="w")
    show_length.text = lambda t: "Length= " + str(len(q))
Beispiel #19
0
 def setup(self, v):
     self.x = env.x_dis()
     self.y = env.y_dis()
     self.v = v
     self.orders = sim.Queue(self.name() + '.orders')
     self.color = ('red', 'blue', 'green', 'purple', 'black',
                   'pink')[self.sequence_number()]
     self.pic_driver = sim.Animate(circle0=10,
                                   x0=self.x,
                                   y0=self.y,
                                   fillcolor0='',
                                   linecolor0=self.color,
                                   linewidth0=2)
Beispiel #20
0
def test58():
    env = sim.Environment()
    names = sorted(sim.colornames().keys())
    x=10
    y=env.height() - 80
    sx= 155
    sy=23
    sim.Animate(text='Salabim colornames', x0=x, y0=y, fontsize0=20, anchor='sw', textcolor0='white')
    y -= 30
    for name in names:
        if env.is_dark(name):
            textcolor = 'white'
        else:
            textcolor = 'black'
        sim.Animate(rectangle0=(x, y, x + sx, y + sy), fillcolor0=name)
        sim.Animate(text='<null string>' if name =='' else name, x0=x + sx / 2, y0=y + sy /2, anchor='c', textcolor0=textcolor, fontsize0=15)
        x += sx + 5
        if x + sx > 1024:
            y -= sy + 4
            x = 10

    env.background_color('20%gray')
    env.animate(True)
    env.run()
def draw_legend():
    delta = x_max - x_min

    size = 0.75

    sim.AnimateText(text="""\

    Legend
-----------------
    Movable Bridge
    Unmovable Bridge
    Lock
    Vessel
    Crossroad
    Water
-----------------
""",
                    textcolor='black',
                    fontsize=2,
                    text_anchor='nw',
                    x=x_min + 0.7 * delta,
                    y=y_min + 0.3 * delta)

    sim.Animate(circle0=(size, ),
                fillcolor0="yellow",
                x0=x_min + 0.7 * delta,
                y0=y_min + 0.238 * delta)
    sim.Animate(circle0=(size, ),
                fillcolor0="turquoise",
                x0=x_min + 0.7 * delta,
                y0=y_min + 0.2205 * delta)
    sim.Animate(circle0=(size, ),
                fillcolor0="orangered",
                x0=x_min + 0.7 * delta,
                y0=y_min + 0.203 * delta)
    sim.Animate(circle0=(size, ),
                fillcolor0="black",
                x0=x_min + 0.7 * delta,
                y0=y_min + 0.1855 * delta)
    sim.Animate(circle0=(size, ),
                fillcolor0="red",
                x0=x_min + 0.7 * delta,
                y0=y_min + 0.168 * delta)
    sim.Animate(circle0=(size, ),
                fillcolor0="blue",
                x0=x_min + 0.7 * delta,
                y0=y_min + 0.1505 * delta)
Beispiel #22
0
 def do_next():
     global ans
     global min_n
     
     for an in ans:
         an.remove()
     ans = []
 
     x=10
     y=env.height() - 80
     sx= 230
     sy=14
     y -= 30
     fontnames = []
     n=0
     
     for fns, ifilename in sim.fonts():
         for fn in fns:
             fontnames.append(fn)
     fontnames.extend(sim.standardfonts().keys())
     last = ''
     any = False
     for font in sorted(fontnames, key=sim.normalize):
         if font != last:  # remove duplicates
             last = font
             n += 1
             if n >= min_n:
                 any = True
                 ans.append(sim.Animate(text=font, x0=x, y0=y, anchor='sw', fontsize0=15, font=font))
                 x += sx + 5
                 if x + sx > 1024:
                     y -= sy + 4
                     x = 10
                     if y<0:
                         break
     min_n = n + 1
     if not any:
         env.quit()
    def perform_animation(self):
        start = (self.current_node.x, self.current_node.y)
        end = (self.next_node.x, self.next_node.y)
        size = 1
        if GlobalVars.network.graph.has_edge(start, end):
            edge = GlobalVars.network.graph.edges[start, end, 0]
            required_time = edge['time']
            start_xy = Utilities.normalize(*start)
            end_xy = Utilities.normalize(*end)
            if self.animation is None:
                self.animation = sim.Animate(circle0=(size, ),
                                             fillcolor0="black",
                                             x0=start_xy[0],
                                             x1=end_xy[0],
                                             y0=start_xy[1],
                                             y1=end_xy[1],
                                             t1=GlobalVars.environment.now() +
                                             required_time,
                                             layer=1)
            else:
                self.animation.update(x1=end_xy[0],
                                      y1=end_xy[1],
                                      t1=GlobalVars.environment.now() +
                                      required_time)

            if required_time <= self.stop_time:
                yield self.hold(required_time)
                self.stop_time -= required_time
            else:
                yield self.hold(self.stop_time)
                self.remaining_time = required_time - self.stop_time
                self.stop_time = 0
                self.animation.update(x1=self.animation.x(),
                                      y1=self.animation.y())
        else:
            yield self.hold(0)
Beispiel #24
0
 def animation_objects(self, q):
     an1 = sim.Animate(rectangle0=(0, 0, 60, 12), fillcolor0=self.group.color)
     an2 = sim.Animate(text=str(self.name()), anchor='sw', textcolor0='white', fontsize0=12, offsetx0=2, offsety0=2)
     return (70, 15, an1, an2)
Beispiel #25
0
 def process(self):
     sim.Animate(text='Piet' ,x0=100,y0=100,x1=500,y1=500,t1=10)
     while True:
         print(sim.default_env())
         yield self.hold(1)
Beispiel #26
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)
Beispiel #27
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)
Beispiel #28
0
# Show colornames

import salabim as sim

env = sim.Environment()
names = sorted(sim.colornames().keys())
env.animation_parameters(modelname="show colornames",
                         background_color="20%gray")
x = 10
y = env.height() - 110
sx = 165
sy = 21

for name in names:
    sim.Animate(rectangle0=(x, y, x + sx, y + sy), fillcolor0=name)
    sim.Animate(
        text=(name, "<null string>")[name == ""],
        x0=x + sx / 2,
        y0=y + sy / 2,
        anchor="c",
        textcolor0=("black", "white")[env.is_dark(name)],
        fontsize0=15,
    )
    x += sx + 4
    if x + sx > 1024:
        y -= sy + 4
        x = 10

env.run()
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')
Beispiel #30
0
 def setup(self, job_generator, job):
     self.group = job_generator.group_dist()
     self.duration = job_generator.duration_dist()
     self.start_execution = None
     self.an_bar = sim.Animate(rectangle0=(0, 0, 0, 0))