kopia lustrzana https://github.com/villares/sketch-a-day
				
				
				
			
			
			
			
				main
			
			
		
		
							rodzic
							
								
									76afba26b8
								
							
						
					
					
						commit
						19695baea8
					
				
										
											Plik binarny nie jest wyświetlany.
										
									
								
							| Po Szerokość: | Wysokość: | Rozmiar: 122 KiB | 
										
											Plik binarny nie jest wyświetlany.
										
									
								
							| Po Szerokość: | Wysokość: | Rozmiar: 41 KiB | 
|  | @ -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: 75 KiB | 
										
											Plik binarny nie jest wyświetlany.
										
									
								
							| Po Szerokość: | Wysokość: | Rozmiar: 37 KiB | 
|  | @ -0,0 +1,99 @@ | |||
| # Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day | ||||
| from random import choice | ||||
| from gif_export_wrapper import * | ||||
| add_library('gifAnimation') | ||||
| 
 | ||||
| GRID_SIZE = 50 | ||||
| SKETCH_NAME = "s178" | ||||
| OUTPUT = ".gif" | ||||
| 
 | ||||
| def setup(): | ||||
|     size(700, 700) | ||||
|     colorMode(HSB) | ||||
|     strokeWeight(5) | ||||
|     print_text_for_readme(SKETCH_NAME, OUTPUT) | ||||
|     border = 50 | ||||
|     spacing = (width - border * 2) / GRID_SIZE | ||||
|     Node.spacing = spacing | ||||
|     for x in range(GRID_SIZE): | ||||
|         for y in range(GRID_SIZE): | ||||
|             Node.nodes.append(Node(border + spacing / 2 + x * spacing, | ||||
|                                    border + spacing / 2 + y * spacing)) | ||||
|     for node in Node.nodes: | ||||
|         node.set_nbs() | ||||
| 
 | ||||
|     Node.nodes[0].current = True | ||||
| 
 | ||||
| def draw(): | ||||
| 
 | ||||
|     background(0) | ||||
|     for node in Node.nodes: | ||||
|         node.plot_links() | ||||
|         node.update() | ||||
| 
 | ||||
| class Node(): | ||||
|     nodes = [] | ||||
| 
 | ||||
|     def __init__(self, x, y): | ||||
|         self.x = x | ||||
|         self.y = y | ||||
|         self.visited = False | ||||
|         self.current = False | ||||
|         self.links = [] | ||||
|         self.cor = 0 | ||||
| 
 | ||||
|     def plot_links(self): | ||||
|         for node in self.links: | ||||
|             if mousePressed: | ||||
|                 stroke(color(self.cor % 256, 255, 255)) | ||||
|             else: | ||||
|                 stroke(255) | ||||
|             line(node.x, node.y, self.x, self.y) | ||||
| 
 | ||||
|     def set_nbs(self): | ||||
|         self.nbs, self.unvisited_nbs = [], [] | ||||
|         for node in Node.nodes: | ||||
|             if node != self and dist(node.x, node.y, | ||||
|                                      self.x, self.y) <= Node.spacing * 1.5: | ||||
|                 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 self.unvisited_nbs: | ||||
|                 rnd_choice = choice(self.unvisited_nbs) | ||||
|                 self.links.append(rnd_choice) | ||||
|                 self.current = False | ||||
|                 rnd_choice.current = True | ||||
|                 rnd_choice.visited = True | ||||
|                 rnd_choice.cor = self.cor + 1 | ||||
|             else: | ||||
|                 branch_nodes = [node for node in Node.nodes | ||||
|                                 if node.visited and node.unvisited_nbs] | ||||
|                 if branch_nodes: | ||||
|                     print(len(branch_nodes)) | ||||
|                     rnd_choice = branch_nodes[-1] #choice(branch_nodes) | ||||
|                     self.current = False | ||||
|                     rnd_choice.current = True | ||||
|                 else: | ||||
|                     print("finished") | ||||
|                     noLoop() | ||||
| 
 | ||||
| def keyPressed(): | ||||
|     loop() | ||||
|     saveFrame("####s179.png") | ||||
| 
 | ||||
| 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