def main(args):

  from render.render import Render
  from dddUtils.ioOBJ import load_2d as load

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

  data = load(args.fn)

  size = args.size
  one = 1.0/size
  vertices = data['vertices']
  lines = data['lines']

  render = Render(size, BACK, FRONT)

  render.ctx.set_source_rgba(*FRONT)
  render.ctx.set_line_width(args.width*one)

  out = ''.join(args.fn.split('.')[:-1])+'.png'

  show_closed(render, vertices[lines[0],:], out, fill=args.closed)
  #for vv in vertices:
    #render.circle(vv[0], vv[1], one, fill=True)

  render.write_to_png(out)


  return
def main(args):

    from render.render import Render
    from dddUtils.ioOBJ import load_2d as load

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

    data = load(args.fn)

    size = args.size
    one = 1.0 / size
    vertices = data['vertices']
    lines = data['lines']

    render = Render(size, BACK, FRONT)

    render.ctx.set_source_rgba(*FRONT)
    render.ctx.set_line_width(args.width * one)

    out = ''.join(args.fn.split('.')[:-1]) + '.png'

    show_closed(render, vertices[lines[0], :], out, fill=args.closed)
    #for vv in vertices:
    #render.circle(vv[0], vv[1], one, fill=True)

    render.write_to_png(out)

    return
def main(args):

  from render.render import Render
  from dddUtils.ioOBJ import load
  from numpy import array

  data = load(args.fn)

  size = args.size
  one = 1.0/size
  vertices = data['vertices'][:,:2]

  back = [1,1,1,1]
  front = [0,0,0,args.alpha]

  rad = args.rad*one

  vertices -= get_mid(vertices)
  vertices *= args.scale
  vertices += array([[0.5,0.5]])

  render = Render(size, back, front)

  render.ctx.set_source_rgba(*front)
  render.ctx.set_line_width(one)

  out = ''.join(args.fn.split('.')[:-1])+'.png'

  for vv in vertices:
    render.circle(vv[0], vv[1], rad, fill=True)

  render.write_to_png(out)

  return
Beispiel #4
0
    def __init__(self):
        self.tick = 0
        pygame.init()

        screen = pygame.display.set_mode((self.width, self.height),
                                         pg_vars.DOUBLEBUF)

        pygame.display.set_caption('orange:phobia')

        self.renderer = Render(screen)
        register_all_skills()

        self.skill_ui = None
    def __init__(self, game, x, y, max_radius=None):
        super().__init__(game, BoundBox(Vector2(x, y), Vector2(x, y)))

        self.radius = 0
        self.radius_speed = 0

        if max_radius is None:
            max_radius = math.hypot(game.width / 2, game.height / 2)

        self.max_radius = max_radius
        self.fade_tick = 30

        self.screen = pygame.Surface((game.width, game.height))
        self.screen.set_colorkey((240, 240, 240))
        self.renderer = Render(self.screen)
Beispiel #6
0
def main(args):

  from dddUtils.ioOBJ import load_2d as load
  from render.render import Render

  fn = args.fn
  dot_size = args.dotSize

  data = load(fn)
  vertices = data['vertices']

  render = Render(SIZE, BACK, FRONT)
  draw(render, vertices, dot_size)

  out = fn + '.png'
  render.write_to_png(out)
def main(args):

  from dddUtils.ddd import get_mid_2d as get_mid
  from render.render import Render
  from dddUtils.ioOBJ import load
  from modules.show import show_closed

  from numpy import array

  data = load(args.fn)
  size = args.size

  if args.fill:
    fill = True
  else:
    fill = False

  one = 1.0/size
  vertices = data['vertices']

  print(vertices)

  if args.scale:

    vertices -= get_mid(vertices)
    vertices *= args.scale
    vertices += array([[0.5,0.5]])

  render = Render(size, BACK, FRONT)

  render.ctx.set_source_rgba(*FRONT)
  render.ctx.set_line_width(args.width*one)

  out = ''.join(args.fn.split('.')[:-1])+'.png'

  show_closed(render, vertices, out, fill=fill)

  #render.ctx.set_source_rgba(*[1,0,0,1])
  #for vv in vertices:
    #render.circle(vv[0], vv[1], one*4, fill=False)

  render.write_to_png(out)

  return
def main(args):

    from render.render import Render
    from dddUtils.ioOBJ import load
    from numpy import array

    data = load(args.fn)

    size = args.size
    one = 1.0 / size
    vertices = data['vertices'][:, :2]

    back = [1, 1, 1, 1]
    front = [0, 0, 0, args.alpha]

    rad = args.rad * one

    vertices -= get_mid(vertices)
    vertices *= args.scale
    vertices += array([[0.5, 0.5]])

    render = Render(size, back, front)

    render.ctx.set_source_rgba(*front)
    render.ctx.set_line_width(one)

    out = ''.join(args.fn.split('.')[:-1]) + '.png'

    for vv in vertices:
        render.circle(vv[0], vv[1], rad, fill=True)

    render.write_to_png(out)

    return
class EntityPulseExplosion(Entity):
    color = (3, 169, 244)

    def __init__(self, game, x, y, max_radius=None):
        super().__init__(game, BoundBox(Vector2(x, y), Vector2(x, y)))

        self.radius = 0
        self.radius_speed = 0

        if max_radius is None:
            max_radius = math.hypot(game.width / 2, game.height / 2)

        self.max_radius = max_radius
        self.fade_tick = 30

        self.screen = pygame.Surface((game.width, game.height))
        self.screen.set_colorkey((240, 240, 240))
        self.renderer = Render(self.screen)

    def update(self, events):
        super().update(events)

        if self.radius < self.max_radius:
            self.radius_speed += 1
            self.radius += self.radius_speed

        else:
            self.fade_tick -= 1

            if self.fade_tick < 0:
                self.set_dead()

    def render(self, render):
        self.renderer.fill((240, 240, 240))
        self.screen.set_alpha(self.fade_tick / 30 * 255)

        self.renderer.circle(self, self.radius, self.color)

        render.screen.blit(self.screen, (0, 0))
Beispiel #10
0
def main():

  from time import time
  from itertools import count

  from render.render import Render
  from modules.helpers import print_stats
  from modules.show import show
  from modules.show import show_closed

  from differentialLine import DifferentialLine


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

  render = Render(SIZE, BACK, FRONT)

  render.ctx.set_source_rgba(*FRONT)
  render.ctx.set_line_width(LINEWIDTH)

  angles = sorted(random(NINIT)*TWOPI)

  DF.init_circle_segment(MID,MID,RAD, angles)

  t_start = time()


  for i in count():

    DF.optimize_position(STP)
    spawn_curl(DF,NEARL)

    if i % STAT_ITT == 0:

      print_stats(i,time()-t_start,DF)

    if i % EXPORT_ITT == 0:

      fn = './res/oryx_bb_{:010d}.png'.format(i)
      num = DF.np_get_edges_coordinates(np_edges)
      show(render,np_edges[:num,:],fn)

      fn = './res/oryx_bb_closed_{:010d}.png'.format(i)
      num = DF.np_get_sorted_vert_coordinates(np_verts)
      show_closed(render,np_verts[:num,:],fn)
Beispiel #11
0
def main():

    from time import time
    from itertools import count

    from render.render import Render
    from modules.helpers import print_stats
    from modules.show import show
    from modules.show import show_closed

    from differentialLine import DifferentialLine

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

    render = Render(SIZE, BACK, FRONT)

    render.ctx.set_source_rgba(*FRONT)
    render.ctx.set_line_width(LINEWIDTH)

    angles = sorted(random(NINIT))

    DF.init_circle_segment(MID, MID, RAD, angles)

    for i in count():

        t_start = time()

        steps(DF, STEPS_ITT)

        t_stop = time()

        print_stats(i * STEPS_ITT, t_stop - t_start, DF)

        fn = './res/oryx_bb_{:010d}.png'.format(i * STEPS_ITT)
        edges_coordinates = DF.get_edges_coordinates()
        show(render, edges_coordinates, fn)

        fn = './res/oryx_bb_closed_{:010d}.png'.format(i * STEPS_ITT)
        sorted_vert_coordinates = DF.get_sorted_vert_coordinates()
        show_closed(render, sorted_vert_coordinates, fn)
def main():

    from time import time
    from itertools import count

    from differentialLine import DifferentialLine

    from render.render import Render
    from modules.helpers import print_stats

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

    np_coords = zeros(shape=(NMAX, 4), dtype='float')
    np_vert_coords = zeros(shape=(NMAX, 2), dtype='float')

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

    render = Render(SIZE, BACK, FRONT)

    render.ctx.set_source_rgba(*FRONT)
    render.ctx.set_line_width(LINEWIDTH)

    ## arc

    angles = sorted(random(INIT_NUM) * pi * 1.5)
    xys = []
    for a in angles:
        x = 0.5 + cos(a) * 0.2
        y = 0.5 + sin(a) * 0.2
        xys.append((x, y))

    DF.init_line_segment(xys, lock_edges=1)

    ## vertical line

    #yy = sorted(MID + 0.2*(1-2*random(INIT_NUM)))
    #xx = 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(MID + 0.2*(1-2*random(INIT_NUM)))
    # xx = sorted(MID + 0.2*(1-2*random(INIT_NUM)))
    # xys = []
    # for x,y in zip(xx,yy):
    # xys.append((x,y))

    # DF.init_line_segment(xys, lock_edges=1)

    for i in count():

        t_start = time()

        DF.optimize_position(STP)
        spawn_curl(DF, NEARL, 0.016)

        if i % 100 == 0:
            fn = './res/sider_arc_ac_{:04d}.png'.format(i)
        else:
            fn = None

        render.set_front(FRONT)
        num = DF.np_get_edges_coordinates(np_coords)
        sandstroke(render, np_coords[:num, :], 20, fn)

        if random() < 0.05:
            sandstroke(render, np_coords[:num, :], 30, None)

        vert_num = DF.np_get_vert_coordinates(np_vert_coords)
        dots(render, np_vert_coords[:vert_num, :], None)

        t_stop = time()

        print_stats(i, t_stop - t_start, DF)
def main():

  from differentialMesh import DifferentialMesh
  from render.render import Render
  from time import time
  from modules.helpers import print_stats

  from numpy.random import randint, random

  from numpy import unique


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

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

  render = Render(SIZE, BACK, FRONT)
  render.set_line_width(LINEWIDTH)


  tsum = 0

  for i in xrange(10000):

    t1 = time()
    for _ in xrange(STEPS_ITT):

      DM.optimize_position(
        ATTRACT_SCALE,
        REJECT_SCALE,
        TRIANGLE_SCALE,
        ALPHA,
        DIMINISH,
        -1
      )

      henum = DM.get_henum()

      edges = unique(randint(henum,size=(henum)))
      en = len(edges)
      rnd = 1-2*random(size=en*2)
      make_island = random(size=en)>0.85

      for i,(he,isl) in enumerate(zip(edges,make_island)):

        if DM.is_surface_edge(he)>0:

          the = pi*rnd[2*i]
          rad = rnd[2*i+1]*0.5
          dx = cos(the)*rad*H
          dy = sin(the)*rad*H

          if not isl:

            DM.new_triangle_from_surface_edge(
              he,
              H,
              dx*rad*H,
              dy*rad*H,
              minimum_length=MINIMUM_LENGTH,
              maximum_length=MAXIMUM_LENGTH,
              merge_ragged_edge=1
            )

          else:

            DM.throw_seed_triangle(
              he,
              H,
              dx*rad*H,
              dy*rad*H,
              NEARL*0.5,
              the
            )

      DM.optimize_edges(
        SPLIT_LIMIT,
        FLIP_LIMIT
      )

      tsum += time() - t1

    print_stats(render.num_img, tsum, DM)
    show(render, DM)
    tsum = 0
Beispiel #14
0
def main():

    from differentialMesh import DifferentialMesh
    from render.render import Render
    from time import time
    from modules.helpers import print_stats

    from numpy.random import randint, random

    from numpy import unique

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

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

    render = Render(SIZE, BACK, FRONT)
    render.set_line_width(LINEWIDTH)

    tsum = 0

    for i in xrange(10000):

        t1 = time()
        for _ in xrange(STEPS_ITT):

            DM.optimize_position(ATTRACT_STP, REJECT_STP, TRIANGLE_STP, ALPHA,
                                 DIMINISH, -1)

            henum = DM.get_henum()

            edges = unique(randint(henum, size=(henum)))
            en = len(edges)
            rnd = 1 - 2 * random(size=en * 2)
            make_island = random(size=en) > 0.85

            for i, (he, isl) in enumerate(zip(edges, make_island)):

                if DM.is_surface_edge(he) > 0:

                    the = pi * rnd[2 * i]
                    rad = rnd[2 * i + 1] * 0.5
                    dx = cos(the) * rad * H
                    dy = sin(the) * rad * H

                    if not isl:

                        DM.new_triangle_from_surface_edge(
                            he,
                            H,
                            dx * rad * H,
                            dy * rad * H,
                            minimum_length=MINIMUM_LENGTH,
                            maximum_length=MAXIMUM_LENGTH,
                            merge_ragged_edge=1)

                    else:

                        DM.throw_seed_triangle(he, H, dx * rad * H,
                                               dy * rad * H, NEARL * 0.5, the)

            DM.optimize_edges(SPLIT_LIMIT, FLIP_LIMIT)

            tsum += time() - t1

        print_stats(render.num_img, tsum, DM)
        show(render, DM)
        tsum = 0
Beispiel #15
0
def main():

  from differentialMesh import DifferentialMesh
  from render.render import Render
  from time import time
  from modules.helpers import print_stats
  from numpy import array

  # from modules.utils import get_exporter
  # exporter = get_exporter(NMAX)

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

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

  render = Render(SIZE, BACK, FRONT)
  render.set_line_width(LINEWIDTH)


  # st = named_sub_timers()

  tsum = 0


  for i in xrange(10000000):

    t1 = time()
    for _ in xrange(STEPS_ITT):

      # st.start()
      DM.optimize_position(
        ATTRACT_STP,
        REJECT_STP,
        TRIANGLE_STP,
        ALPHA,
        DIMINISH,
        -1
      )
      # st.t('opt')

      henum = DM.get_henum()
      # st.t('rnd')

      surface_edges = array(
        [DM.is_surface_edge(e)>0
        for e in range(henum)],
        'bool').nonzero()[0]

      # st.t('surf')

      rnd = random(size=len(surface_edges)*2)
      the = (1.-2*rnd[::2])*pi
      rad = rnd[1::2]*0.5*H
      dx = cos(the)*rad
      dy = sin(the)*rad
      # st.t('rnd2')

      DM.new_triangles_from_surface_edges(
        surface_edges,
        len(surface_edges),
        H,
        dx,
        dy,
        MINIMUM_LENGTH,
        MAXIMUM_LENGTH,
        1
      )
      # st.t('tri')

      # st.start()
      DM.optimize_edges(
        SPLIT_LIMIT,
        FLIP_LIMIT
      )
      # st.t('opte')

      tsum += time() - t1

    print_stats(i*STEPS_ITT, tsum, DM)

    ## export png
    show(render, DM)

    ## export obj
    # exporter(
      # DM, 
      # {
        # 'procs': PROCS,
        # 'nearl': NEARL,
        # 'farl': FARL,
        # 'prefix': PREFIX,
        # 'reject_stp': 0,
        # 'attract_stp': 0,
        # 'triangle_stp': 0,
        # 'size': SIZE
      # }, 
      # i*STEPS_ITT
    # )
    tsum = 0
def main():

  from time import time
  from itertools import count

  from differentialLine import DifferentialLine

  from render.render import Render
  from modules.helpers import print_stats

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


  np_coords = zeros(shape=(NMAX,4), dtype='float')
  np_vert_coords = zeros(shape=(NMAX,2), dtype='float')


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

  render = Render(SIZE, BACK, FRONT)

  render.ctx.set_source_rgba(*FRONT)
  render.ctx.set_line_width(LINEWIDTH)

  ## arc

  angles = sorted(random(INIT_NUM)*pi*1.5)
  xys = []
  for a in angles:
    x = 0.5 + cos(a)*0.2
    y = 0.5 + sin(a)*0.2
    xys.append((x,y))

  DF.init_line_segment(xys, lock_edges=1)

  ## vertical line

  #yy = sorted(MID + 0.2*(1-2*random(INIT_NUM)))
  #xx = 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(MID + 0.2*(1-2*random(INIT_NUM)))
  # xx = sorted(MID + 0.2*(1-2*random(INIT_NUM)))
  # xys = []
  # for x,y in zip(xx,yy):
    # xys.append((x,y))

  # DF.init_line_segment(xys, lock_edges=1)


  for i in count():

    t_start = time()

    DF.optimize_position(STP)
    spawn_curl(DF,NEARL,0.016)

    if i%100==0:
      fn = './res/sider_arc_ac_{:04d}.png'.format(i)
    else:
      fn = None

    render.set_front(FRONT)
    num = DF.np_get_edges_coordinates(np_coords)
    sandstroke(render,np_coords[:num,:],20,fn)


    if random()<0.05:
      sandstroke(render,np_coords[:num,:],30,None)

    vert_num = DF.np_get_vert_coordinates(np_vert_coords)
    dots(render,np_vert_coords[:vert_num,:],None)


    t_stop = time()

    print_stats(i,t_stop-t_start,DF)
    def __init__(self, game):
        super().__init__(game, game.width / 2, game.height / 2, game.width,
                         game.height)
        self.elements = []
        self.update_while_tween = False
        self.in_tween = False

        margin_top = 50
        margin_left = 100

        carousel_width = SkillView.width * 3 + SkillGroupElement.gap * 2

        group_elements = []

        for skill_group in SkillManager.get_instance().groups.values():
            group = SkillGroupElement(game, margin_left + 50, 0, skill_group,
                                      self)
            group_elements.append(group)

        self.carousel = Carousel(game, margin_left + 50, margin_top + 300,
                                 carousel_width, SkillView.height,
                                 group_elements)

        self.skill_name = Tween(
            Label(self.game,
                  margin_left + carousel_width + 300,
                  margin_top,
                  350,
                  80,
                  "<>",
                  80,
                  color=(52, 152, 219)).set_fade_tick(30, "pause"),
            {'opacity': 255}, [])

        self.font = Render.load_font()

        empty_surface = Surface((500, self.game.height - margin_top - 150))
        empty_surface.set_colorkey((240, 240, 240))
        empty_surface.fill((240, 240, 240))
        empty_surface.set_alpha(0)

        self.empty_surface = empty_surface

        self.skill_desc = Tween(
            Image(self.game, margin_left + carousel_width + 300,
                  margin_top + 150, empty_surface), {'opacity': 255}, [])

        self.skill_price = Tween(
            Label(self.game,
                  margin_left + carousel_width + 300,
                  margin_top + 150 + 150,
                  350,
                  80,
                  "필요 SP   1",
                  32,
                  color=(52, 152, 219)).set_fade_tick(30, "pause"),
            {'opacity': 255}, [])

        self.current_sp = Tween(
            Label(self.game,
                  margin_left + carousel_width + 300,
                  margin_top + 150 + 150 + 40,
                  350,
                  80,
                  "현재 SP   0",
                  32,
                  color=(52, 152, 219)).set_fade_tick(30, "pause"),
            {'opacity': 255}, [])

        self.skill_score = Tween(
            Label(self.game,
                  margin_left + carousel_width + 300 + 500 - 250,
                  margin_top + 150 + 150,
                  350,
                  80,
                  "필요 점수   0",
                  32,
                  color=(52, 152, 219)).set_fade_tick(30, "pause"),
            {'opacity': 255}, [])

        self.current_score = Tween(
            Label(self.game,
                  margin_left + carousel_width + 300 + 500 - 250,
                  margin_top + 150 + 150 + 40,
                  350,
                  80,
                  "현재 점수   0",
                  32,
                  color=(52, 152, 219)).set_fade_tick(30, "pause"),
            {'opacity': 255}, [])

        self.buy_button_image = Surface((500, 100))
        Render(self.buy_button_image)\
            .fill((52, 152, 219))\
            .write_text(250, 50, "Enter 키로 구매", color=(240, 240, 240), size=50)

        self.disabled_button_image = Surface((500, 100))
        Render(self.disabled_button_image)\
            .fill((220, 220, 220))\
            .write_text(250, 50, "구매할 수 없음", color=(180, 180, 180), size=50)

        self.already_bought_button_image = Surface((500, 100))
        Render(self.already_bought_button_image)\
            .fill((220, 220, 220))\
            .write_text(250, 50, "이미 구매함", color=(180, 180, 180), size=50)

        self.buy_button = Tween(
            Image(self.game, margin_left + carousel_width + 300,
                  margin_top + 150 + 150 + 40 + 100, self.buy_button_image),
            {'opacity': 255}, [])

        self.skill_ui = [
            self.skill_name, self.skill_desc, self.skill_price,
            self.current_sp, self.skill_score, self.current_score,
            self.buy_button
        ]

        self.update_skill()

        self.elements.extend(
            (self.carousel,
             Label(self.game, margin_left, margin_top, 250, 50, "SkillTree",
                   50).set_fade_tick(30, "pause")))

        self.elements.extend(self.skill_ui)
Beispiel #18
0
from render.jsonloader import JsonLoader as JsonLoader
from render.render import Render as Render
if __name__ == '__main__':
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('--directory',
                        type=str,
                        default='/Users/sameriksson/temp/screensgen/')
    parser.add_argument('--save', type=bool, default=True)
    args = parser.parse_args()
    rend = Render(args.directory)
    rend.render(args.save)
        def callback():
            for skill_elem in self.skill_ui:
                skill_elem.set_value('opacity', 255, 10)

            if self.current_activated_skill is not None:
                skill_name = "<%s>" % self.current_activated_skill.name
                skill_desc = self.current_activated_skill.description
                if player.point < 1:
                    self.current_sp.element.set_color((255, 87, 34))
                else:
                    self.current_sp.element.set_color((52, 152, 219))

                self.current_sp.element.set_text("현재 SP   %d" % player.point)

                if player.score < self.current_activated_skill.require_score:
                    self.current_score.element.set_color((255, 87, 34))
                else:
                    self.current_score.element.set_color((52, 152, 219))

                self.current_score.element.set_text("현재 점수   %d" %
                                                    player.score)

                self.skill_price.element.set_text('필요 SP   1')
                self.skill_score.element.set_text(
                    '필요 점수   %d' % self.current_activated_skill.require_score)

                if self.current_activated_skill.activated:
                    self.buy_button.element.image = self.already_bought_button_image

                elif self.current_activated_skill.can_activate(player):
                    self.buy_button.element.image = self.buy_button_image

                else:
                    self.buy_button.element.image = self.disabled_button_image

            else:
                skill_name = ''
                skill_desc = ''
                self.skill_price.element.set_text('')
                self.skill_score.element.set_text('')
                self.current_sp.element.set_text('')
                self.current_score.element.set_text('')

                self.buy_button.element.image = self.empty_surface

            self.skill_name.element.set_text(skill_name)
            self.skill_desc.element.image = Render.get_paragraph_text(
                skill_desc,
                self.font,
                self.skill_desc.element.image.get_width(),
                self.skill_desc.element.image.get_height(),
                color=(52, 152, 219))

            if self.update_while_tween:

                @delay(.1)
                def new_update():
                    self.in_tween = False
                    self.update_while_tween = False
                    self.update_skill()

                new_update()

            else:
                self.in_tween = False
Beispiel #20
0
def main():

    from differentialMesh import DifferentialMesh
    from render.render import Render
    from time import time
    from modules.helpers import print_stats
    from numpy import array

    # from modules.utils import get_exporter
    # exporter = get_exporter(NMAX)

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

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

    render = Render(SIZE, BACK, FRONT)
    render.set_line_width(LINEWIDTH)

    # st = named_sub_timers()

    tsum = 0

    for i in xrange(10000000):

        t1 = time()
        for _ in xrange(STEPS_ITT):

            # st.start()
            DM.optimize_position(ATTRACT_STP, REJECT_STP, TRIANGLE_STP, ALPHA,
                                 DIMINISH, -1)
            # st.t('opt')

            henum = DM.get_henum()
            # st.t('rnd')

            surface_edges = array(
                [DM.is_surface_edge(e) > 0 for e in range(henum)],
                'bool').nonzero()[0]

            # st.t('surf')

            rnd = random(size=len(surface_edges) * 2)
            the = (1. - 2 * rnd[::2]) * pi
            rad = rnd[1::2] * 0.5 * H
            dx = cos(the) * rad
            dy = sin(the) * rad
            # st.t('rnd2')

            DM.new_triangles_from_surface_edges(surface_edges,
                                                len(surface_edges), H, dx, dy,
                                                MINIMUM_LENGTH, MAXIMUM_LENGTH,
                                                1)
            # st.t('tri')

            # st.start()
            DM.optimize_edges(SPLIT_LIMIT, FLIP_LIMIT)
            # st.t('opte')

            tsum += time() - t1

        print_stats(i * STEPS_ITT, tsum, DM)

        ## export png
        show(render, DM)

        ## export obj
        # exporter(
        # DM,
        # {
        # 'procs': PROCS,
        # 'nearl': NEARL,
        # 'farl': FARL,
        # 'prefix': PREFIX,
        # 'reject_stp': 0,
        # 'attract_stp': 0,
        # 'triangle_stp': 0,
        # 'size': SIZE
        # },
        # i*STEPS_ITT
        # )
        tsum = 0
 def prepare_surface(self):
     self.surface = pygame.Surface((self.width, self.height))
     self.surface_renderer = Render(self.surface)
Beispiel #22
0
class RenderTest(unittest.TestCase):
    def setUp(self):
        self.render = Render()

    def test_options(self):
        chrome_options = [
            '--headless', '--window-size=1280x1024', '--hide-scrollbars',
            '--no-sandbox'
        ]
        self.assertListEqual(self.render.chrome_options.arguments,
                             chrome_options)
        firefox_options = ['-headless', '--width 1280']
        self.assertListEqual(self.render.firefox_options.arguments,
                             firefox_options)

        self.assertFalse(self.render.is_open)
        self.assertIsNone(self.render.browser)

    @patch.object(webdriver, 'Firefox', MagicMock(options=None))
    def test_open_with_firefox(self):
        self.render.open_browser('firefox')

        self.assertTrue(self.render.is_open)
        self.assertEqual(self.render.browser, 'firefox')
        assert webdriver.Firefox.called

    @patch.object(webdriver, 'Chrome', MagicMock(options=None))
    def test_open_with_chrome(self):
        self.render.open_browser('chrome')

        self.assertTrue(self.render.is_open)
        self.assertEqual(self.render.browser, 'chrome')
        assert webdriver.Chrome.called

    @patch.object(webdriver, 'Chrome', MagicMock(options=None,
                                                 quit=MagicMock()))
    def test_close_browser(self):
        self.render.open_browser('chrome')
        self.render.close_browser()

        self.assertFalse(self.render.is_open)
        self.assertEqual(self.render.browser, 'chrome')
        assert self.render.driver.quit.called

    def test_set_max_height(self):
        self.render.open_browser('chrome')
        self.render.driver.get(BASE64_HTML_MAX_HEIGHT)
        height = self.render.get_max_height()
        self.assertEqual(height, 2000)

    def test_render_selector(self):
        self.render.open_browser('chrome')
        image = self.render.render(BASE64_HTML_SELECTOR, '1280', '#test-me',
                                   '')
        # with open(os.path.join(dir_path, 'images', 'rendered-selector.png'), 'wb') as write_file:
        #     write_file.write(image)
        with open(os.path.join(dir_path, 'selector.png'), 'rb') as file:
            png_data = file.read()
        self.assertEqual(png_data, image)

    def test_render_hide_selector(self):
        self.render.open_browser('chrome')
        image = self.render.render(BASE64_HTML_SELECTOR, '1280', '',
                                   '#do-not-test-me')
        # with open(os.path.join(dir_path, 'images', 'rendered-hide-selector.png'), 'wb') as write_file:
        #     write_file.write(image)
        with open(os.path.join(dir_path, 'hide-selector.png'), 'rb') as file:
            png_data = file.read()
        self.assertEqual(png_data, image)
Beispiel #23
0
 def setUp(self):
     self.render = Render()
Beispiel #24
0
IMPROVISER_HOST = "https://api.improviser.education"
ENDPOINT_RIFFS = IMPROVISER_HOST + "/v1/riffs"
RENDER_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                           'rendered')

API_USER = os.getenv('API_USER')
API_PASS = os.getenv('API_PASS')
AWS_ACCESS_KEY_ID = os.getenv('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = os.getenv('AWS_SECRET_ACCESS_KEY')
AWS_BUCKET_NAME = "improviser.education"
KEYS = [
    'c', 'cis', 'd', 'dis', 'ees', 'e', 'f', 'fis', 'g', 'gis', 'aes', 'a',
    'ais', 'bes', 'b'
]

renderer = Render(renderPath=RENDER_PATH)
logger = structlog.get_logger(__name__)

if not LOCAL_RUN:
    if not API_USER or not API_PASS or not AWS_ACCESS_KEY_ID or not AWS_SECRET_ACCESS_KEY:
        sys.exit('Please set needed environment vars.')


def render(riff):
    rendered_riff_ids = []
    for key in KEYS:
        renderer.name = "riff_%s_%s" % (riff["id"], key)
        notes = riff["notes"]
        chords = riff["chord_info"] if riff["chord_info"] else ""
        renderer.addNotes(notes)
        renderer.addChords(chords)
Beispiel #25
0
class Game(object):
    entities = {}
    players = []
    mobs = []
    death_note = []
    life_note = []
    last_entity_id = 0
    key_maps = dict.fromkeys(Keys.list_keys(), False)
    width = 1280
    height = 720
    background = (240, 240, 240)
    passed_patterns = 0
    patterns = []
    avail_patterns_easy = [PatternThorn, PatternRain, PatternFakey]
    avail_patterns_normal = [PatternCircular, PatternDrop, PatternLaser]
    avail_patterns_hard = [PatternTurret, PatternTriangle]
    pre_ui = []
    ui = []

    def __init__(self):
        self.tick = 0
        pygame.init()

        screen = pygame.display.set_mode((self.width, self.height),
                                         pg_vars.DOUBLEBUF)

        pygame.display.set_caption('orange:phobia')

        self.renderer = Render(screen)
        register_all_skills()

        self.skill_ui = None

    def handle_event(self, event):
        for elem in self.ui:
            if elem.ui_event:
                elem.update_event(event)

        if event.type is pg_vars.QUIT:
            pygame.quit()
            sys.exit()

        elif event.type is pg_vars.KEYDOWN:
            if event.key in self.key_maps:
                self.key_maps[event.key] = True

            elif event.key == Keys.KEY_SKILL_UI_TOGGLE:
                # self.toggle_skill_window()
                pass

        elif event.type is pg_vars.KEYUP:
            if event.key in self.key_maps:
                self.key_maps[event.key] = False

    def update(self, events):
        self.tick += 1

        for event in events:
            self.handle_event(event)

        for e in self.entities.values():
            e.update(events)

        for pattern in self.patterns:
            pattern.update()

        for death in self.death_note:
            if death in self.entities:
                death_entity = self.entities[death]

                del self.entities[death]

                if death_entity in self.mobs:
                    self.mobs.remove(death_entity)

        for life in self.life_note:
            life.entity_id = self.last_entity_id
            self.last_entity_id += 1
            self.entities[life.entity_id] = life

        self.life_note = []
        self.death_note = []

    def render(self):
        self.render_background()

        for element in self.pre_ui:
            element.render(self.renderer)

        for entity in self.entities.values():
            entity.render(self.renderer)

        for element in self.ui:
            element.render(self.renderer)

        self.renderer.update()

    def render_background(self):
        self.renderer.fill(self.background)

    def toggle_skill_window(self):
        if self.skill_ui is None:
            return

        if self.skill_ui.is_hidden:
            self.skill_ui.show()

        else:
            self.skill_ui.hide()

    def new_pattern(self, end=True):
        if len(self.players) < 1:
            return

        if end:
            self.players[0].score += 100
            self.passed_patterns += 1

        @delay(1)
        def start_pattern():
            if len(self.players) < 1:
                return

            if self.passed_patterns < 4:
                if random.randint(0, 10) >= 4:
                    chosen_pattern = random.choice(self.avail_patterns_easy)

                else:
                    chosen_pattern = random.choice(self.avail_patterns_normal)

            elif self.passed_patterns < 7:
                if random.randint(0, 10) >= 4:
                    chosen_pattern = random.choice(self.avail_patterns_normal)

                else:
                    chosen_pattern = random.choice(self.avail_patterns_easy)

            else:
                if random.randint(0, 10) >= 4:
                    chosen_pattern = random.choice(self.avail_patterns_hard)

                elif random.randint(0, 10) >= 8:
                    chosen_pattern = random.choice(self.avail_patterns_easy)

                else:
                    chosen_pattern = random.choice(self.avail_patterns_normal)

            chosen_pattern(self, self.players[0]).activate()

        start_pattern()