kopia lustrzana https://github.com/villares/sketch-a-day
				
				
				
			
			
			
			
				main
			
			
		
		
							rodzic
							
								
									c4bd0bc087
								
							
						
					
					
						commit
						1bab39cd30
					
				|  | @ -0,0 +1,47 @@ | |||
| """ | ||||
| Alexandre B A Villares http://abav.lugaralgum.com - GPL v3  | ||||
| 
 | ||||
| A helper for the Processing gifAnimation library (https://github.com/jordanorelli) | ||||
| ported to Processing 3 by 01010101 (https://github.com/01010101) | ||||
| Download the library from https://github.com/01010101/GifAnimation/archive/master.zip | ||||
| This helper was inspired by an example by Art Simon https://github.com/APCSPrinciples/AnimatedGIF/ | ||||
| 
 | ||||
| Put  at the start of your sketch: | ||||
|    add_library('gifAnimation') | ||||
|    from gif_exporter import gif_export | ||||
| and at the end of draw(): | ||||
|     gif_export(GifMaker) | ||||
| """ | ||||
| 
 | ||||
| def gif_export(GifMaker,             # gets a reference to the library | ||||
|                filename="exported",  # .gif will be added | ||||
|                repeat=0,             # 0 makes it an "endless" animation | ||||
|                quality=128,          # quality range 0 - 255 | ||||
|                delay=170,            # this is quick | ||||
|                frames=0, | ||||
|                finish=False):            # 0 will stop on keyPressed or frameCount >= 100000 | ||||
|     global gifExporter | ||||
|     try: | ||||
|         gifExporter | ||||
|     except NameError: | ||||
|         gifExporter = GifMaker(this, filename + ".gif") | ||||
|         gifExporter.setRepeat(repeat) | ||||
|         gifExporter.setQuality(quality) | ||||
|         gifExporter.setDelay(delay) | ||||
|         gif_export._frame = frameCount | ||||
|         print("gif start") | ||||
| 
 | ||||
|     gifExporter.addFrame() | ||||
|     if finish: | ||||
|         gifExporter.finish() | ||||
|         noLoop() | ||||
|     if (frames == 0 and keyPressed or frameCount - gif_export._frame >= 100000) \ | ||||
|             or (frames != 0 and frameCount - gif_export._frame >= frames): | ||||
|         gifExporter.finish() | ||||
|         #background(255) | ||||
|         print("gif saved") | ||||
|         del(gifExporter) | ||||
|         noLoop() | ||||
|         return False | ||||
|     else: | ||||
|         return True | ||||
										
											Plik binarny nie jest wyświetlany.
										
									
								
							| Po Szerokość: | Wysokość: | Rozmiar: 1.1 MiB | 
|  | @ -0,0 +1,177 @@ | |||
| # Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day | ||||
| # s204 20180721 | ||||
| 
 | ||||
| from gif_export_wrapper import * | ||||
| add_library('gifAnimation') | ||||
| add_library('peasycam') | ||||
| 
 | ||||
| GRID_SIZE = 11 | ||||
| SKETCH_NAME = "s205" | ||||
| OUTPUT = ".png" | ||||
| color_mode = True | ||||
| starting_node = 0 | ||||
| end_cycle = False | ||||
| 
 | ||||
| def setup(): | ||||
|     lights() | ||||
|     size(700, 700, P3D) | ||||
|     cam = PeasyCam(this, 100) | ||||
|     cam.setMinimumDistance(1000) | ||||
|     cam.setMaximumDistance(1000) | ||||
|     colorMode(HSB) | ||||
|     strokeWeight(2) | ||||
|     print_text_for_readme(SKETCH_NAME, OUTPUT) | ||||
|     Node.border = 50 | ||||
|     Node.spacing = (width - Node.border * 2) / GRID_SIZE | ||||
|     for x in range(GRID_SIZE): | ||||
|         for y in range(GRID_SIZE): | ||||
|             for z in range(GRID_SIZE): | ||||
|                 Node.nodes.append(Node(x, y, z)) | ||||
|     for node in Node.nodes: | ||||
|         node.set_nbs() | ||||
| 
 | ||||
|     clear_grid() | ||||
| 
 | ||||
| 
 | ||||
| def draw(): | ||||
|     # lights() | ||||
|     background(0) | ||||
|     for node in Node.nodes: | ||||
|         node.plot_links() | ||||
|         node.update() | ||||
| 
 | ||||
|     # gif_export(GifMaker) | ||||
| 
 | ||||
|     if end_cycle == True: | ||||
|         gif_export(GifMaker) | ||||
|         gif_export(GifMaker) | ||||
|         clear_grid() | ||||
|         global end_cycle | ||||
|         end_cycle = False | ||||
| 
 | ||||
| def clear_grid(): | ||||
|     global starting_node | ||||
|     starting_node += 1 | ||||
| 
 | ||||
|     if starting_node < len(Node.nodes): | ||||
|         for node in Node.nodes: | ||||
|             node.visited = False | ||||
|             node.current = False | ||||
|             node.links = [] | ||||
|             node.cor = None | ||||
|         Node.nodes[starting_node].current = True | ||||
|     else: | ||||
|         gif_export(GifMaker, finish=True) | ||||
|         noLoop() | ||||
| 
 | ||||
| 
 | ||||
| class Node(): | ||||
|     nodes = [] | ||||
| 
 | ||||
|     def __init__(self, x, y, z): | ||||
|         self.ix = x | ||||
|         self.iy = y | ||||
|         self.iz = z | ||||
|         self.x = Node.border + Node.spacing / 2 + x * Node.spacing - width / 2 | ||||
|         self.y = Node.border + Node.spacing / 2 + y * Node.spacing - width / 2 | ||||
|         self.z = Node.border + Node.spacing / 2 + z * Node.spacing - width / 2 | ||||
|         self.visited = False | ||||
|         self.current = False | ||||
|         self.links = [] | ||||
|         self.cor = None | ||||
| 
 | ||||
|     def plot_links(self): | ||||
|         if self.cor is not None: | ||||
|             c = color(self.cor % 256, 255, 255) | ||||
|         else: | ||||
|             c = color(255) | ||||
| 
 | ||||
|         if color_mode: | ||||
|             stroke(0) | ||||
|             fill(c) | ||||
|         else: | ||||
|             stroke(c) | ||||
|             fill(0) | ||||
|         with pushMatrix(): | ||||
|             translate(self.x, self.y, self.z) | ||||
|             box(Node.spacing / 2) | ||||
|         # fill(128) | ||||
|         for node in self.nbs: | ||||
|             if node not in self.links: | ||||
|                 mid_x = (self.x + node.x) / 2 | ||||
|                 mid_y = (self.y + node.y) / 2 | ||||
|                 mid_z = (self.z + node.z) / 2 | ||||
|                 with pushMatrix(): | ||||
|                     translate(mid_x, mid_y, mid_z) | ||||
|                     box(Node.spacing / 2) | ||||
| 
 | ||||
|     def set_nbs(self): | ||||
|         self.nbs, self.unvisited_nbs = [], [] | ||||
|         for node in Node.nodes: | ||||
|             if node != self and dist(node.x, node.y, node.z, | ||||
|                                      self.x, self.y, self.z) <= Node.spacing * 1.1: | ||||
|             # if (self.ix == node.ix - 1 or | ||||
|             #         self.ix == node.ix + 1 or | ||||
|             #         self.iy == node.iy - 1 or | ||||
|             #         self.iy == node.iy + 1): | ||||
|                 self.nbs.append(node) | ||||
|                 self.unvisited_nbs.append(node) | ||||
| 
 | ||||
|     def set_unvisited_nbs(self): | ||||
|         self.unvisited_nbs = [node for node in self.nbs | ||||
|                               if not node.visited] | ||||
| 
 | ||||
|     def update(self): | ||||
|         self.set_unvisited_nbs() | ||||
|         if self.current: | ||||
|             self.visited = True | ||||
|             if not self.cor: | ||||
|                 self.cor = 0 | ||||
|             if self.unvisited_nbs: | ||||
|                 for unvisited_nb in self.unvisited_nbs[::-2]: | ||||
|                     self.links.append(unvisited_nb) | ||||
|                     unvisited_nb.links.append(self) | ||||
|                     self.current = False | ||||
|                     unvisited_nb.visited = True | ||||
|                     unvisited_nb.current = True | ||||
|                     unvisited_nb.cor = self.cor + 10 | ||||
|             else: | ||||
|                 branch_nodes = [node for node in Node.nodes | ||||
|                                 if node.visited and node.unvisited_nbs] | ||||
|                 if branch_nodes: | ||||
|                     print(len(branch_nodes)) | ||||
|                     next = branch_nodes[-1] | ||||
|                     self.current = False | ||||
|                     next.current = True | ||||
|                 else: | ||||
|                     print("finished") | ||||
|                     global end_cycle | ||||
|                     end_cycle = True | ||||
|                     noLoop() | ||||
| 
 | ||||
| def keyPressed(): | ||||
|     global color_mode | ||||
|     if key == 'c': | ||||
|         color_mode = not color_mode | ||||
|     if key in ['p', 'P']: | ||||
|         saveFrame("####" + SKETCH_NAME + OUTPUT) | ||||
|     loop() | ||||
|     # if key == 's': | ||||
|     #     gif_export(GifMaker, finish=True) | ||||
|     # if key == 'g': | ||||
|     #     gif_export(GifMaker) | ||||
|     # if key == 'r': | ||||
|     #     clear_grid() | ||||
|     # if key in ['=', '+']: | ||||
|     #     global starting_node | ||||
|     #     starting_node += 1 | ||||
| 
 | ||||
| 
 | ||||
| def print_text_for_readme(name, output): | ||||
|     println(""" | ||||
|  | ||||
| 
 | ||||
| {1}: [code](https://github.com/villares/sketch-a-day/tree/master/{0}) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)] | ||||
| 
 | ||||
| """.format(name, name[1:], output) | ||||
|     ) | ||||
		Ładowanie…
	
		Reference in New Issue
	
	 Alexandre B A Villares
						Alexandre B A Villares