Beispiel #1
0
def run():
    clear()
    smooth()

    imagefile = os.path.join(pf.cfg['pyformexdir'],'data','butterfly.png')
    image = image2numpy(imagefile,indexed=False)

    import simple
    F = simple.cuboid().centered()
    G = Formex('4:0123').replic2(3,2).toMesh().setProp(range(1,7)).centered()
    draw([F,G],texture=image)
    view('iso')
    zoom(0.5)

    from gui.decors import Rectangle
    R = Rectangle(100,100,400,300,color=yellow,texture=image)
    decorate(R)

    bgcolor(color=white,image=imagefile)
Beispiel #2
0
def run():
    clear()
    smooth()

    imagefile = os.path.join(pf.cfg['pyformexdir'], 'data', 'butterfly.png')
    image = image2numpy(imagefile, indexed=False)

    import simple
    F = simple.cuboid().centered()
    G = Formex('4:0123').replic2(3, 2).toMesh().setProp(range(1, 7)).centered()
    draw([F, G], texture=image)
    view('iso')
    zoom(0.5)

    from gui.decors import Rectangle
    R = Rectangle(100, 100, 400, 300, color=yellow, texture=image)
    decorate(R)

    bgcolor(color=white, image=imagefile)
CS0 = CS = CoordinateSystem()
# some text

# A storage for the scenes
script = []

# Scene 0: The story starts idyllic
T = 'There once was a white horse running free in the wood.'
script += [ createScene(text=T,caged=False,color=7) ]
pause()

# Scene 1: Things turn out badly
T = 'Some wicked pyFormex user caged the horse and transported it around.'
# apply same transformations on model and coordinate system
H,CS = [ i.translate([0.,3.,6.]) for i in [H,CS] ]
C = simple.cuboid(*H.bbox())
script += [ createScene(text=T) ]
pause()

# Scene 2..n: caged movements
T = 'The angry horse randomly changed colour at each step.'
script += [ createScene(text=T,move=1) ]
m = len(script)
n = 16
script += [ createScene(move=i) for i in range(m,n,1) ]
pause()


# Scene n+1: the escape
T = 'Finally the horse managed to escape from the cage.\nIt wanted to go back home and turned black, so it would not be seen in the night.'
escape = script[-1]
Beispiel #4
0
def hex_mesh_huge():
    nx, ny, nz = 20, 20, 8
    F = simple.cuboid().replic2(nx, ny).replic(nz, 1., 2)
    F += F.trl([nx, ny, nz])
    return F.toMesh()
Beispiel #5
0
def hex_mesh_orig():
    x, y, z = 10, 10, 8
    F = simple.cuboid().replic2(x, x).replic(z, 1., 2)
    F += F.trl([x, y, z])
    return F.toMesh()
Beispiel #6
0
def hex_mesh():
    nx, ny, nz = 3, 2, 2
    F = simple.cuboid().replic2(nx, ny).replic(nz, 1., 2)
    F += F.trl([nx, ny, 0])
    F += F.trl([2 * nx, 2 * ny, nz])
    return F.toMesh()
Beispiel #7
0
def hex_mesh_huge():
    nx,ny,nz = 20,20,8
    F = simple.cuboid().replic2(nx,ny).replic(nz,1.,2)
    F += F.trl([nx,ny,nz])
    return F.toMesh()
Beispiel #8
0
def hex_mesh_orig():
    x, y, z = 10, 10, 8
    F = simple.cuboid().replic2(x, x).replic(z, 1., 2)
    F += F.trl([x, y, z])
    return F.toMesh()
Beispiel #9
0
def hex_mesh():
    nx,ny,nz = 3,2,2
    F = simple.cuboid().replic2(nx,ny).replic(nz,1.,2)
    F += F.trl([nx,ny,0])
    F += F.trl([2*nx,2*ny,nz])
    return F.toMesh()
Beispiel #10
0
def run():
    global line, H, C, CS, savewait
    savewait = delay(2.0)
    clear()
    lights(True)
    view('iso')
    smooth()
    transparent(state=False)
    linewidth(2)
    setDrawOptions({'bbox': None})

    # read the model of the horse
    F = Formex.read(getcfg('datadir') + '/horse.pgf')
    # make sure it is centered
    F = F.centered()
    # scale it to unity size and head it in the x-direction
    xmin, xmax = F.bbox()
    H = F.scale(1. / (xmax[0] - xmin[0])).rotate(180, 1)
    # create the global coordinate system
    CS0 = CS = CoordinateSystem()
    # some text

    # A storage for the scenes
    script = []

    # Scene 0: The story starts idyllic
    T = 'There once was a white horse running free in the wood.'
    script += [createScene(text=T, caged=False, color=7)]
    sleep(5)

    # Scene 1: Things turn out badly
    T = 'Some wicked pyFormex user caged the horse and transported it around.'
    # apply same transformations on model and coordinate system
    H, CS = [i.translate([0., 3., 6.]) for i in [H, CS]]
    C = simple.cuboid(*H.bbox())
    script += [createScene(text=T)]
    sleep(5)

    # Scene 2..n: caged movements
    T = 'The angry horse randomly changed colour at each step.'
    script += [createScene(text=T, move=1)]
    m = len(script)
    n = 16
    script += [createScene(move=i) for i in range(m, n, 1)]
    sleep(5)

    # Scene n+1: the escape
    T = 'Finally the horse managed to escape from the cage.\nIt wanted to go back home and turned black, so it would not be seen in the night.'
    escape = script[-1]
    script += [createScene(text=T, color=0, caged=False)]
    undraw(escape)
    sleep(5)

    # The problem
    T = "But alas, it couldn't remember how it got there!!!"
    drawText(T, 20, line, size=20)
    line += line_inc
    for s in script[:-2]:
        #sleep(0.1)
        undraw(s)
    sleep(5)

    # The solution
    T = "But thanks to pyFormex's orientation,\nit could go back in a single step, straight through the bushes."
    drawText(T, 20, line, size=20)
    line += line_inc
    H = H.transformCS(CS0, CS)
    draw(Formex([[CS[3], CS0[3]]]))
    sleep(5)

    T = "And the horse lived happily ever after."
    script += [createScene(text=T, color=7, caged=False)]
    undraw(script[-2])