Exemplo n.º 1
0
def main():

    from iutils.render import Animate
    from differentialLine import DifferentialLine

    from modules.show import show_closed
    from modules.show import show_detail
    from modules.show import show

    DF = DifferentialLine(NMAX, FARL * 2, NEARL, FARL, PROCS)

    angles = sorted(random(INIT_NUM) * TWOPI)
    DF.init_circle_segment(MID, MID, INIT_RAD, angles)

    def wrap(render):

        global i

        # animation stops when res is False
        res = steps(DF)

        ## if fn is a path each image will be saved to that path
        fn = None

        ## render outline with marked circles
        num = DF.np_get_edges_coordinates(np_coords)
        show_detail(render, np_coords[:num, :], fn)

        i += 1

        return res

    render = Animate(SIZE, BACK, FRONT, wrap)
    render.start()
def main():

  from differentialMesh import DifferentialMesh
  from iutils.render import Animate
  from modules.helpers import darts


  DM = DifferentialMesh(NMAX, 2*FARL, NEARL, FARL, PROCS)

  DM.new_faces_in_ngon(MID,MID, H, 3, 0)
  DM.set_edge_intensity(1, 1)

  sources = [(x,y) for x,y in darts(NUM_SOURCES, MID, MID, 0.40, 3*NEARL)]
  DM.initialize_sources(sources, NEARL)

  def wrap(render):

    res = steps(DM)
    show(render, DM, sources)

    return res

  render = Animate(SIZE, BACK, FRONT, wrap)
  render.set_line_width(LINEWIDTH)
  render.start()
Exemplo n.º 3
0
def main():

  from iutils.render import Animate
  from differentialLine import DifferentialLine
  from modules.helpers import get_exporter

  # from modules.show import show_closed
  # from modules.show import show_detail
  from modules.show import show


  DF = DifferentialLine(NMAX, FARL*2, NEARL, FARL, PROCS)

  angles = sorted(random(INIT_NUM)*TWOPI)
  DF.init_circle_segment(MID,MID,INIT_RAD, angles)

  from fn import Fn
  fn = Fn(prefix='./res/')

  exporter = get_exporter(
    NMAX,
    {
      'nearl': NEARL,
      'farl': FARL,
      'stp': STP,
      'size': SIZE,
      'procs': PROCS
    }
  )

  def wrap(render):

    global i

    # animation stops when res is False
    res = steps(DF)

    ## if fn is a path each image will be saved to that path

    ## render outline
    num = DF.np_get_edges_coordinates(np_edges)
    if not i % 100:
      show(render,np_edges[:num,:], None, r=1.3*ONE)
      # render.write_to_png(fn.name())
      exporter(
        DF,
        fn.name()+'.2obj'
      )

    ## render solid
    # num = DF.get_sorted_vert_coordinates(np_verts)
    #show_closed(render,np_verts[:num,:],fn)

    i += 1

    return res

  render = Animate(SIZE, BACK, FRONT, wrap)
  render.start()
Exemplo n.º 4
0
def main():

  from modules.differentialLine import DifferentialLine
  from iutils.render import Animate

  colors = {
      'back': [1,1,1,1],
      'front': [0,0,0,0.6],
      'cyan': [0,0.6,0.6,0.6],
      'light': [0,0,0,0.2],
      }

  threads = 512

  render_steps = 10
  export_steps = 14

  size = 512
  one = 1.0/size

  init_num = 20
  init_rad = 0.001

  stp = one*0.4
  spring_stp = 1.0
  reject_stp = 13.0

  near_rad = one*3
  far_rad = 30.*one

  spawn_limit = near_rad
  spawn_prob = 0.1

  DL = DifferentialLine(
      size,
      stp,
      spring_stp,
      reject_stp,
      near_rad,
      far_rad,
      threads = threads
      )

  DL.init_circle(init_num, init_rad)

  wrap = get_wrap(
      DL,
      colors,
      spawn_limit,
      spawn_prob,
      export_steps=export_steps,
      render_steps=render_steps
      )

  render = Animate(size, colors['back'], colors['front'], wrap)
  render.start()
Exemplo n.º 5
0
def main():

    from iutils.render import Animate
    from modules.fracture import Fractures

    # from dddUtils.ioOBJ import export_2d as export
    from fn import Fn
    fn = Fn(prefix='./res/', postfix='.2obj')

    F = Fractures(INIT_NUM,
                  INIT_RAD,
                  SOURCE_DST,
                  FRAC_DOT,
                  FRAC_DST,
                  FRAC_STP,
                  FRAC_SPD,
                  FRAC_DIMINISH,
                  FRAC_SPAWN_DIMINISH,
                  domain='rect')

    print(F.sources.shape)

    # uniform square distribution
    from numpy.random import random
    for _ in range(5):
        F.blow(2, random(size=2))

    # uniform circular distribution
    # for _ in xrange(5):
    # F.blow(3, random_uniform_circle(INIT_RAD, num=1))

    def wrap(render):

        if not F.i % 20:
            show(render, F)
            # vertices, paths = F.get_vertices_and_paths()
            # export('fractures', fn.name(), vertices, lines=paths)
            render.write_to_png(fn.name() + '.png')

        F.print_stats()
        res = F.step(dbg=False)
        n = F.spawn_front(factor=SPAWN_FACTOR, angle=SPAWN_ANGLE)
        print('spawned: {:d}'.format(n))

        # fn = './asdf_{:04d}.png'.format(F.i)
        # render.write_to_png(fn)

        # if not res:
        # vertices, paths = F.get_vertices_and_paths()
        # export('fractures', fn.name(), vertices, lines=paths)

        return res

    render = Animate(SIZE, BACK, FRONT, wrap)
    render.start()
Exemplo n.º 6
0
def main():

    from modules.differentialLine import DifferentialLine
    from iutils.render import Animate

    colors = {
        'back': [1, 1, 1, 1],
        'front': [0, 0, 0, 0.6],
        'cyan': [0, 0.6, 0.6, 0.6],
        'light': [0, 0, 0, 0.2],
    }

    threads = 512

    render_steps = 10
    export_steps = 14

    size = 512
    one = 1.0 / size

    init_num = 20
    init_rad = 0.001

    stp = one * 0.4
    spring_stp = 1.0
    reject_stp = 13.0

    near_rad = one * 3
    far_rad = 30. * one

    spawn_limit = near_rad
    spawn_prob = 0.1

    DL = DifferentialLine(size,
                          stp,
                          spring_stp,
                          reject_stp,
                          near_rad,
                          far_rad,
                          threads=threads)

    DL.init_circle(init_num, init_rad)

    wrap = get_wrap(DL,
                    colors,
                    spawn_limit,
                    spawn_prob,
                    export_steps=export_steps,
                    render_steps=render_steps)

    render = Animate(size, colors['back'], colors['front'], wrap)
    render.start()
def main():

  from differentialMesh import DifferentialMesh
  from iutils.render import Animate

  DM = DifferentialMesh(NMAX, 2*FARL, NEARL, FARL, PROCS)

  DM.new_faces_in_ngon(MID,MID, H, 6, 0.0)

  def wrap(render):

    res = steps(DM)
    show(render, DM)

    return res

  render = Animate(SIZE, BACK, FRONT, wrap)
  render.set_line_width(LINEWIDTH)
  render.start()
Exemplo n.º 8
0
def main():

    from differentialMesh import DifferentialMesh
    from iutils.render import Animate
    from modules.helpers import darts

    DM = DifferentialMesh(NMAX, 2 * FARL, NEARL, FARL, PROCS)

    DM.new_faces_in_ngon(MID, MID, H, 3, 0)
    DM.set_edge_intensity(1, 1)

    sources = [(x, y)
               for x, y in darts(NUM_SOURCES, MID, MID, 0.40, 3 * NEARL)]
    DM.initialize_sources(sources, NEARL)

    def wrap(render):

        res = steps(DM)
        show(render, DM, sources)

        return res

    render = Animate(SIZE, BACK, FRONT, wrap)
    render.set_line_width(LINEWIDTH)
    render.start()
def main():

    import gtk

    from differentialMesh import DifferentialMesh
    from iutils.render import Animate

    DM = DifferentialMesh(NMAX, 2 * FARL, NEARL, FARL, PROCS)

    DM.new_faces_in_ngon(MID, MID, H, 6, 0.0)

    def wrap(render):

        res = steps(DM)
        show(render, DM)

        return res

    render = Animate(SIZE, BACK, FRONT, wrap)
    # render.get_colors_from_file('../colors/red_earth.gif')
    render.set_line_width(LINEWIDTH)

    gtk.main()
Exemplo n.º 10
0
def main():

    import gtk

    from differentialMesh import DifferentialMesh
    from iutils.render import Animate

    DM = DifferentialMesh(NMAX, 2 * FARL, NEARL, FARL, PROCS)

    DM.new_faces_in_ngon(MID, MID, H, 6, 0.0)

    def wrap(render):

        res = steps(DM)
        show(render, DM)

        return res

    render = Animate(SIZE, BACK, FRONT, wrap)
    # render.get_colors_from_file('../colors/red_earth.gif')
    render.set_line_width(LINEWIDTH)

    gtk.main()
def main():
    from modules.fracture import Fracture
    from iutils.render import Animate
    from numpy.random import random
    from iutils.random import darts_rect
    from time import time
    from fn import Fn

    fn = Fn(prefix='./res/')

    start = time()

    initial_sources = darts_rect(SOURCES, 0.5, 0.5, 1.0 - 2.0 * EDGE,
                                 1.0 - 2.0 * EDGE, FRAC_STP)

    F = Fracture(FRAC_DOT,
                 FRAC_DST,
                 FRAC_STP,
                 initial_sources=initial_sources,
                 zone_leap=ZONE_LEAP,
                 nmax=NMAX)

    for _ in range(20):
        F.blow(1, EDGE + random((1, 2)) * (1.0 - 2.0 * EDGE))

    def wrap(render):
        print('itt', F.itt, 'num', F.num, 'fnum', F.fnum, 'anum', F.anum,
              'time',
              time() - start)
        res = F.step()

        n = F.frac_front(factor=SPAWN_FACTOR, angle=SPAWN_ANGLE, dbg=DBG)
        if n > 0:
            print('new fracs: {:d}'.format(n))

        if not F.itt % DRAW_ITT:
            show(render, F)

        return res

    render = Animate(SIZE, BACK, FRONT, wrap)
    render.set_line_width(LINEWIDTH)
    render.start()

    name = fn.name()
    render.write_to_png(name + '.png')
    export(name + '.2obj', F)
def main():

  from iutils.render import Animate
  from differentialLine import DifferentialLine

  from modules.show import show_closed
  from modules.show import show_detail
  from modules.show import show


  DF = DifferentialLine(NMAX, FARL*2, NEARL, FARL, PROCS)

  angles = sorted(random(INIT_NUM)*TWOPI)
  DF.init_circle_segment(MID,MID,INIT_RAD, angles)


  def wrap(render):

    global i

    # animation stops when res is False
    res = steps(DF)

    ## if fn is a path each image will be saved to that path
    fn = None

    ## render outline with marked circles
    num = DF.np_get_edges_coordinates(np_coords)
    show_detail(render,np_coords[:num,:],fn)

    i += 1

    return res

  render = Animate(SIZE, BACK, FRONT, wrap)
  render.start()
def main():

    from differentialMesh import DifferentialMesh
    from iutils.render import Animate

    DM = DifferentialMesh(NMAX, 2 * FARL, NEARL, FARL, PROCS)

    DM.new_faces_in_ngon(MID, MID, H, 6, 0.0)

    def wrap(render):

        res = steps(DM)
        show(render, DM)

        return res

    render = Animate(SIZE, BACK, FRONT, wrap)
    render.set_line_width(LINEWIDTH)
    render.start()
Exemplo n.º 14
0
def main():

  from iutils.render import Animate
  from differentialLine import DifferentialLine

  from fn import Fn

  from modules.show import sandstroke
  from modules.show import dots

  DF = DifferentialLine(NMAX, FARL*2, NEARL, FARL, PROCS)

  ## arc
  # angles = sorted(random(INIT_NUM)*pi*1.5)
  # xys = []
  # for a in angles:
    # x = 0.5 + cos(a)*0.06
    # y = 0.5 + sin(a)*0.06
    # xys.append((x,y))
  # DF.init_line_segment(xys, lock_edges=1)

  ## vertical line
  #xx = sorted(0.45+0.1*random(INIT_NUM))
  #yy = MID+0.005*(0.5-random(INIT_NUM))
  #xys = []
  #for x,y in zip(xx,yy):
    #xys.append((x,y))
  #DF.init_line_segment(xys, lock_edges=1)

  # diagonal line
  # yy = sorted(0.3+0.4*random(INIT_NUM))
  # xx = 0.3+linspace(0,0.4,num=INIT_NUM)
  # xys = []
  # for x,y in zip(xx,yy):
    # xys.append((x,y))
  # DF.init_line_segment(xys, lock_edges=1)


  angles = sorted(random(INIT_NUM)*TWOPI)
  DF.init_circle_segment(MID,MID,FARL*0.2, angles)

  fn = Fn(prefix='./res/', postfix='.png')


  def wrap(render):

    global np_coords
    global np_vert_coords
    global grains

    ## if fn is a path each image will be saved to that path

    if not render.steps%3:
      f = fn.name()
    else:
      f = None

    grains += (-1)**floor(2*random())
    print(grains)
    if grains<0:
      grains = 0

    res = steps(DF)
    render.set_front(FRONT)

    coord_num = DF.np_get_edges_coordinates(np_coords)
    sandstroke(render,np_coords[:coord_num,:],grains,f)

    if not random()<0.1:
      vert_num = DF.np_get_vert_coordinates(np_vert_coords)
      dots(render,np_vert_coords[:vert_num,:],None)

    return res

  render = Animate(SIZE, BACK, FRONT, wrap)
  render.start()
Exemplo n.º 15
0
def main():
  from numpy import array
  from modules.differentialLattice import DifferentialLattice
  from iutils.render import Animate
  from modules.helpers import spawn_circle

  colors = {
      'back': [1, 1, 1, 1],
      'front': [0, 0, 0, 0.7],
      'cyan': [0, 0.6, 0.6, 0.7],
      'purple': [0.6, 0.0, 0.6, 0.7],
      'light': [0, 0, 0, 0.2],
      }

  threads = 512
  zone_leap = 512

  size = 2048
  one = 1.0/size

  export_steps = 100
  render_steps = 100

  init_num = 20

  line_width = one*2.5

  stp = one*0.03
  spring_stp = 5
  reject_stp = 0.1
  cohesion_stp = 1.0

  max_capacity = 30


  node_rad = 4*one
  spring_reject_rad = node_rad*1.9
  spring_attract_rad = node_rad*2.0
  outer_influence_rad = 10.0*node_rad
  link_ignore_rad = 0.5*outer_influence_rad

  DL = DifferentialLattice(
      size,
      stp,
      spring_stp,
      reject_stp,
      cohesion_stp,
      max_capacity,
      node_rad,
      spring_reject_rad,
      spring_attract_rad,
      outer_influence_rad,
      link_ignore_rad,
      threads=threads,
      zone_leap=zone_leap,
      nmax=50000000
      )

  spawn_circle(DL, init_num, xy=array([[0.5, 0.5]]), dst=node_rad*0.8, rad=0.01)
  wrap = get_wrap(DL, colors, render_steps, export_steps)
  render = Animate(size, colors['back'], colors['front'], wrap)

  render.set_line_width(line_width)
  render.start()
Exemplo n.º 16
0
def main():

  from modules.leaf import LeafClosed as Leaf
  from iutils.render import Animate
  from numpy.random import random
  from numpy import array

  colors = {
    'back': [1,1,1,1],
    'front': [0,0,0,0.3],
    'vein': [0,0,0,0.9],
    'edge': [0,0,0,0.6],
    'cyan': [0,0.6,0.6,0.3],
    'red': [0.7,0.0,0.0,0.8],
    'blue': [0.0,0.0,0.7,0.8],
    'light': [0,0,0,0.2],
  }

  threads = 512

  render_steps = 3
  export_steps = 3

  size = 512
  one = 1.0/size

  node_rad = 0.5*one

  area_rad = 20*node_rad
  stp = node_rad*2
  kill_rad = 2*stp
  sources_dst = 2*kill_rad

  # init_num_sources = 4
  # init_veins = 0.2+0.6*random((init_num_sources,2))
  init_veins = array([[0.5, 0.5]])

  init_num_sources = 10000

  from iutils.random import darts
  init_sources = darts(init_num_sources, 0.5, 0.5, 0.45, sources_dst)
  # from iutils.random import darts_rect
  # init_sources = darts_rect(init_num_sources, 0.5, 0.5, 0.95, 0.95, sources_dst)

  L = Leaf(
    size,
    stp,
    init_sources,
    init_veins,
    area_rad,
    kill_rad,
    threads = threads
  )
  print('nz', L.nz)
  print('dens', L.sv_leap)

  wrap = get_wrap(
    L,
    colors,
    node_rad=node_rad,
    export_steps=export_steps,
    render_steps=render_steps
  )

  render = Animate(size, colors['back'], colors['front'], wrap)
  render.set_line_width(L.one*2)
  render.start()
Exemplo n.º 17
0
def main():

    from iutils.render import Animate
    from differentialLine import DifferentialLine

    from fn import Fn

    from modules.show import sandstroke
    from modules.show import dots

    DF = DifferentialLine(NMAX, FARL * 2, NEARL, FARL, PROCS)

    ## arc
    # angles = sorted(random(INIT_NUM)*pi*1.5)
    # xys = []
    # for a in angles:
    # x = 0.5 + cos(a)*0.06
    # y = 0.5 + sin(a)*0.06
    # xys.append((x,y))
    # DF.init_line_segment(xys, lock_edges=1)

    ## vertical line
    #xx = sorted(0.45+0.1*random(INIT_NUM))
    #yy = MID+0.005*(0.5-random(INIT_NUM))
    #xys = []
    #for x,y in zip(xx,yy):
    #xys.append((x,y))
    #DF.init_line_segment(xys, lock_edges=1)

    # diagonal line
    # yy = sorted(0.3+0.4*random(INIT_NUM))
    # xx = 0.3+linspace(0,0.4,num=INIT_NUM)
    # xys = []
    # for x,y in zip(xx,yy):
    # xys.append((x,y))
    # DF.init_line_segment(xys, lock_edges=1)

    angles = sorted(random(INIT_NUM) * TWOPI)
    DF.init_circle_segment(MID, MID, FARL * 0.2, angles)

    fn = Fn(prefix='./res/', postfix='.png')

    def wrap(render):

        global np_coords
        global np_vert_coords
        global grains

        ## if fn is a path each image will be saved to that path

        if not render.steps % 3:
            f = fn.name()
        else:
            f = None

        grains += (-1)**floor(2 * random())
        print(grains)
        if grains < 0:
            grains = 0

        res = steps(DF)
        render.set_front(FRONT)

        coord_num = DF.np_get_edges_coordinates(np_coords)
        sandstroke(render, np_coords[:coord_num, :], grains, f)

        if not random() < 0.1:
            vert_num = DF.np_get_vert_coordinates(np_vert_coords)
            dots(render, np_vert_coords[:vert_num, :], None)

        return res

    render = Animate(SIZE, BACK, FRONT, wrap)
    render.start()