How to use render_steps method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

run.py

Source:run.py Github

copy

Full Screen

1#!/usr/bin/python2import Final3import MustMeet4class Run(object):5 # Abstracts6 def make_ants(self, location1, location2):7 raise NotImplemented8 def make_grid(self, board_size):9 raise NotImplemented10 # End Abstracts11 def __init__(self, board_size, ant_locations, number_of_active_ants,12 render_steps = [], draw_slide_title=False, pyx_output_filename=''):13 # create board, place walls and ants14 self.grid = self.make_grid(board_size=board_size)15 self.board_size = board_size16 self._draw_slide_title = draw_slide_title17 grid = self.grid18 ants = self.ants = self.make_ants(ant_locations)19 self.update_ant_locations(ant_locations)20 # initialize pyx variables21 self.pyx_output_filename = pyx_output_filename22 self.render_steps = set(render_steps)23 self.number_of_active_ants = number_of_active_ants24 def update_ant_locations(self, ant_locations):25 ants = self.ants26 grid = self.grid27 for i, (ant, location) in enumerate(zip(ants, ant_locations)):28 ant.set_location(tuple(location))29 grid.place_ant_on_grid(ant, tuple(location))30 #print "ant %s radius:" % (i + 1)31 #ant.print_radius()32 def single_step(self):33 num_of_pheromones = 034 done = False35 for ant in self.ants:36 if self.number_of_active_ants == 1 and ant.get_ID() != self.number_of_active_ants:37 continue38 if ant is None: continue39 is_coa = self.__class__ is COARun40 N = self.board_size41 if is_coa and ant.get_location()[0]>=N[1]+1:42 #import pdb; pdb.set_trace()43 done = True44 num_of_pheromones = -145 if ant.get_state() != self.FOUND_BASE and self.grid.step(ant) == 1:46 done = True47 num_of_pheromones = ant.get_num_of_pheromones()48 return done, num_of_pheromones49 def run(self, steps, renderer=None, post_step = lambda: None):50 grid, ants = self.grid, self.ants51 #grid.display()52 FOUND_BASE = self.FOUND_BASE53 done = False54 for i in range(steps):55 if i in self.render_steps:56 if renderer:57 renderer.render(grid, title=str(i))58 grid.display(step_num = i)59 done = self.single_step()60 if done:61 break62 grid.display()63 print "step",i64 else:65 print "NO MEETING!"66 i = steps67 grid.display()68 post_step()69 return done70class ObstacleRun(Run):71 def __init__(self, pyx_output_filename, board_size, number_of_active_ants,72 ant_locations=[], obstacles = [], render_steps=[], draw_slide_title=False):73 obstacles_is_a_map = len(obstacles) > 0 and obstacles[0][0] in ' *'74 if obstacles_is_a_map: # special case, we got a board rep75 ant_locations_d = {}76 for l_num, l in enumerate(obstacles):77 for ant_i, c in enumerate('12'):78 if l.find(c) != -1:79 ant_locations_d[ant_i] = l_num + 1, l.find(c) + 180 if len(ant_locations_d) > 0:81 ant_locations = [ant_locations_d[k] for k in sorted(ant_locations_d.keys())]82 board_size = (len(obstacles[0]), len(obstacles))83 Run.__init__(self, pyx_output_filename=pyx_output_filename, board_size=board_size,84 ant_locations=ant_locations, render_steps=render_steps, draw_slide_title=draw_slide_title,85 number_of_active_ants=number_of_active_ants)86 grid = self.grid87 if obstacles_is_a_map:88 self.set_map(obstacles)89 else:90 for x, y, lenx, leny in obstacles:91 grid.create_obstacle(x, y, lenx, leny)92 def set_map(self, grid):93 self.grid.ants = self.ants94 for l_num, l in enumerate(grid):95 for x, c in enumerate(l):96 if self.grid.get((l_num, x)).get_back_arrow() == Final.START:97 continue98 if c == '*':99 self.grid.get((l_num, x)).set_obstacle()100class GOARun(ObstacleRun):101 FOUND_BASE = Final.FOUND_BASE102 def __init__(self, board_size, number_of_active_ants, ant_locations=[],103 obstacles = [], render_steps=[], draw_slide_title=False, pyx_output_filename=''):104 super(GOARun, self).__init__(board_size=board_size,105 number_of_active_ants=number_of_active_ants,106 ant_locations=ant_locations, obstacles=obstacles,107 render_steps=render_steps, draw_slide_title=draw_slide_title,108 pyx_output_filename=pyx_output_filename)109 def make_ants(self, ant_locations):110 return Final.make_ants(tuple(map(tuple,ant_locations)))111 def make_grid(self, board_size):112 return Final.make_grid(list(board_size))113class COARun(ObstacleRun):114 FOUND_BASE = MustMeet.FOUND_BASE115 def __init__(self, board_size, number_of_active_ants, ant_locations=[],116 obstacles = [], render_steps=[], draw_slide_title=False, pyx_output_filename=''):117 super(COARun, self).__init__(board_size=board_size, number_of_active_ants=number_of_active_ants,118 ant_locations=ant_locations, obstacles=obstacles, render_steps=render_steps,119 draw_slide_title=draw_slide_title, pyx_output_filename=pyx_output_filename)120 def make_ants(self, ant_locations):121 return MustMeet.make_ants(tuple(map(tuple,ant_locations)))122 def make_grid(self, board_size):123 return MustMeet.make_grid(list(board_size))124# Main125if False:126 the_map = [[0]*n for i in xrange(10)]127 homes=[(2,2), (3,7)],128 board_size = (len(the_map), len(the_map[0]))129 goa=GOARun('', board_size=board_size, ant_locations=homes)130 goa.set_map(the_map)...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

1#!/usr/bin/python32# -*- coding: utf-8 -*-3def get_wrap(dl, colors, limit, prob, render_steps=10, export_steps=10):4 from fn import Fn5 from time import time6 # from iutils.ioOBJ import export_2d as export7 t0 = time()8 fn = Fn(prefix='./res/')9 def wrap(render):10 dl.step()11 dl.spawn_curl(limit=limit, prob=prob)12 # dl.spawn_normal(limit=limit, prob=prob)13 if dl.itt % render_steps == 0:14 print('itt', dl.itt, 'num', dl.num, 'time', time()-t0)15 num = dl.num16 render.clear_canvas()17 render.set_line_width(2*dl.one)18 xy = dl.xy[:num,:]19 links = dl.links[:num,:]20 # line = dl.get_line()21 render.ctx.set_source_rgba(*colors['front'])22 ## dots23 # for x,y in xy:24 # render.circle(x, y, dl.one, fill=True)25 ## edges26 for i in range(num):27 b = links[i,1]28 render.line(xy[i,0], xy[i,1], xy[b,0], xy[b,1])29 ## connected edges30 # remapped = xy[line,:]31 # render.ctx.move_to(remapped[0,0], remapped[0,1])32 # for x in remapped[:,:]:33 # render.ctx.line_to(x[0], x[1])34 # render.ctx.fill()35 if dl.itt % export_steps == 0:36 name = fn.name()37 render.write_to_png(name+'.png')38 # export('differential-line-cuda', name+'.2obj', xy, lines=[line])39 return True40 return wrap41def main():42 from modules.differentialLine import DifferentialLine43 from iutils.render import Animate44 colors = {45 'back': [1,1,1,1],46 'front': [0,0,0,0.6],47 'cyan': [0,0.6,0.6,0.6],48 'light': [0,0,0,0.2],49 }50 threads = 51251 render_steps = 1052 export_steps = 1453 size = 51254 one = 1.0/size55 init_num = 2056 init_rad = 0.00157 stp = one*0.458 spring_stp = 1.059 reject_stp = 13.060 near_rad = one*361 far_rad = 30.*one62 spawn_limit = near_rad63 spawn_prob = 0.164 DL = DifferentialLine(65 size,66 stp,67 spring_stp,68 reject_stp,69 near_rad,70 far_rad,71 threads = threads72 )73 DL.init_circle(init_num, init_rad)74 wrap = get_wrap(75 DL,76 colors,77 spawn_limit,78 spawn_prob,79 export_steps=export_steps,80 render_steps=render_steps81 )82 render = Animate(size, colors['back'], colors['front'], wrap)83 render.start()84if __name__ == '__main__':...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Lemoncheesecake automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful