Пример #1
0
def paginate_table(table_rows, rows_per_page, title, output_dir):
    if rows_per_page <= 0:
        rows_per_page = int(1e100)
    split_table = list(ut.split_n(table_rows, rows_per_page))
    #html_pages = [ut.make_temp('.html', dir = output_dir) for x in split_table]
    page_names = ['index.html'] + [
        'page_%d.html' % i for i in xrange(2, 1 + len(split_table))
    ]
    page_paths = [os.path.join(output_dir, fname) for fname in page_names]
    for i in xrange(len(split_table)):
        table_html = '<table border = 1><tr>' + '\n<tr>'.join(
            split_table[i]) + '</table>'
        footer = None
        if len(split_table) == 1:
            footer = ''
        else:
            footer = ''
            footer += ("Back " if i == 0 else "<a href = '%s'>Back</a> " %
                       page_names[i - 1])
            footer += ("Next " if i == -1 +
                       len(page_names) else "<a href = '%s'>Next</a> " %
                       page_names[i + 1])
            for j in xrange(len(split_table)):
                s = '<b>%d</b>' % (1 + j) if (i == j) else str(1 + j)
                footer += ("<a href = '%s'>%s</a> " % (page_names[j], s))
            footer += '<br><br><br><br>'
        ut.make_file(
            page_paths[i],
            "<html><head>%s<title>%s</title></head><body>%s<br>%s</html>" %
            (table_js(), title, table_html, footer))
    return page_paths
Пример #2
0
def html_from_cell(x, output_dir):
    cell = None
    if type(x) == type(''):
        # text
        return x
    elif type(x) == type(np.array([])):
        return html_from_cell(('img', x), output_dir)
    elif hasattr(x, '__video__') and x.__video__:
        return x.make_html(output_dir)
    elif hasattr(x, '__cycle__') and x.__cycle__:
        return x.make_html(output_dir)
    elif type(x) == type((1, )):
        if x[0] in ('img', 'img_mv'):
            path = path_from_im(x, output_dir)
            opts = dict(ut.split_n(x[2:], 2))
            # for tool-tips
            maybe_title = ('title = "%s"' %
                           opts['title']) if 'title' in opts else ''
            return "<img src = '%s' %s>" % (path, maybe_title)
        elif x[0] == 'animation':
            # make an animated gif
            duration = (0.5 if len(x) < 3 else float(x[2]))
            seq_fname = make_temp_animated_gif(x[1],
                                               duration=duration,
                                               dir=output_dir)
            return html_from_cell(('img_mv', seq_fname), output_dir)
        elif x[0] == 'cycle':
            # clicking: advance column; number keys: change row; shift-click: move by 10 frames; control-click: query user for column;
            im_table = x[1]
            group = None if len(x) < 3 else x[2]

            # format: [0, 0] (default) | col | [row, col]
            if len(x) < 4:
                start = [0, 0]
            elif np.ndim(x[3]) == 0:
                start = [0, x[3]]
            else:
                start = x[3]

            if len(im_table) == 0 or type(im_table[0]) != type([]):
                im_table = [im_table]

            return cycle_html([[path_from_im(im, output_dir) for im in row]
                               for row in im_table], group, start)

        elif x[0] == 'table':
            return '<table border = 1>%s</table>' % ('<tr>'.join(
                html_from_rows(x[1], output_dir)))

            #ut.fail("Invalid tuple in table.")
    elif hasattr(x, '__call__'):
        # call function; make a cell from the result
        return html_from_cell(x(), output_dir)
    # # allow table of tables
    # elif type(x) == type([]):
    #   return '<table border = 1>%s</table>' % ('<tr>'.join(html_from_rows(x, output_dir)))
    else:
        return str(x)
Пример #3
0
def html_from_cell(x, output_dir):
  cell = None
  if type(x) == type(''):
    # text
    return x
  elif type(x) == type(np.array([])):
    return html_from_cell(('img', x), output_dir)
  elif hasattr(x, '__video__') and x.__video__:
    return x.make_html(output_dir)
  elif hasattr(x, '__cycle__') and x.__cycle__:
      return x.make_html(output_dir)  
  elif type(x) == type((1,)):
    if x[0] in ('img', 'img_mv'):
      path = path_from_im(x, output_dir)
      opts = dict(ut.split_n(x[2:], 2))
      # for tool-tips
      maybe_title = ('title = "%s"' % opts['title']) if 'title' in opts else ''
      return "<img src = '%s' %s>" % (path, maybe_title)
    elif x[0] == 'animation':
      # make an animated gif
      duration = (0.5 if len(x) < 3 else float(x[2]))
      seq_fname = make_temp_animated_gif(x[1], duration = duration, dir = output_dir)
      return html_from_cell(('img_mv', seq_fname), output_dir)
    elif x[0] == 'cycle':
      # clicking: advance column; number keys: change row; shift-click: move by 10 frames; control-click: query user for column; 
      im_table = x[1]
      group = None if len(x) < 3 else x[2]

      # format: [0, 0] (default) | col | [row, col]
      if len(x) < 4:
        start = [0, 0]
      elif np.ndim(x[3]) == 0:
        start = [0, x[3]]
      else:
        start = x[3]
      
      if len(im_table) == 0 or type(im_table[0]) != type([]):
        im_table = [im_table]

      return cycle_html([[path_from_im(im, output_dir) for im in row] for row in im_table], group, start)
    
    elif x[0] == 'table':
      return '<table border = 1>%s</table>' % ('<tr>'.join(html_from_rows(x[1], output_dir)))

      #ut.fail("Invalid tuple in table.")
  elif hasattr(x, '__call__'):
    # call function; make a cell from the result
    return html_from_cell(x(), output_dir)
  # # allow table of tables
  # elif type(x) == type([]):
  #   return '<table border = 1>%s</table>' % ('<tr>'.join(html_from_rows(x, output_dir)))
  else:
    return str(x)
Пример #4
0
def paginate_table(table_rows, rows_per_page, title, output_dir):
  if rows_per_page <= 0:
    rows_per_page = int(1e100)
  split_table = list(ut.split_n(table_rows, rows_per_page))
  #html_pages = [ut.make_temp('.html', dir = output_dir) for x in split_table]
  page_names = ['index.html'] + ['page_%d.html' % i for i in xrange(2, 1+len(split_table))]
  page_paths = [os.path.join(output_dir, fname) for fname in page_names]
  for i in xrange(len(split_table)):
    table_html = '<table border = 1><tr>' + '\n<tr>'.join(split_table[i]) + '</table>'
    footer = None
    if len(split_table) == 1:
      footer = ''
    else:
      footer = ''
      footer += ("Back " if i == 0 else "<a href = '%s'>Back</a> " % page_names[i-1])
      footer += ("Next " if i == -1 + len(page_names) else "<a href = '%s'>Next</a> " % page_names[i+1])
      for j in xrange(len(split_table)):
        s = '<b>%d</b>' % (1+j) if (i == j) else str(1+j)
        footer += ("<a href = '%s'>%s</a> " % (page_names[j], s))
      footer += '<br><br><br><br>'
    ut.make_file(page_paths[i], "<html><head>%s<title>%s</title></head><body>%s<br>%s</html>" % (table_js(), title, table_html, footer))
  return page_paths
Пример #5
0
def main():
    pygame.init()
    window_size = (512, 512)
    screen = pygame.display.set_mode(
        window_size, pygame.OPENGL | pygame.DOUBLEBUF | pygame.RESIZABLE)

    #pygame.display.gl_set_attribute(pygame.GL_DEPTH_SIZE, 32)

    glCullFace(GL_BACK)

    glDepthFunc(GL_LEQUAL)
    glEnable(GL_DEPTH_TEST)

    glEnable(GL_BLEND)
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

    glClearColor(0.1, 0.2, 0.3, 1.0)

    shader = make_boring_shader()

    images = util.load_images("textures")
    textures = [texture_from_image(image) for image in images]

    #mesh = Mesh3D(shader, util.cube_vertex_positions, util.cube_texture_coordinates)
    meshes = []
    positions = util.split_n(util.cube_vertex_positions, 6)
    tex_coords = util.split_n(util.cube_texture_coordinates, 6)
    for i in range(6):
        mesh = Mesh3D(shader, textures[i], positions[i], tex_coords[i])
        meshes.append(mesh)

    clock = pygame.time.Clock()

    try:
        os.mkdir("frames")
    except FileExistsError:
        pass

    FPS = 60
    frame = 0
    while True:
        clock.tick(FPS)
        for event in pygame.event.get():
            if event.type == pygame.VIDEORESIZE:
                window_size = event.size
            if event.type == pygame.QUIT:
                return
            if event.type == pygame.KEYUP and event.key == pygame.K_ESCAPE:
                return

        mvp, model, view, projection = get_mvp(window_size)

        display(window_size, shader, meshes, mvp)

        pygame.display.flip()

        # save frame
        pygame.image.save(screen, "frames/%d.jpg" % frame)
        with open("matrices.npy", "ab") as f:
            np.save(f, model)
            np.save(f, view)
            np.save(f, projection)

        frame += 1