| 
									
										
										
										
											2018-07-05 01:57:28 +00:00
										 |  |  | # Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day | 
					
						
							| 
									
										
										
										
											2018-07-05 01:59:04 +00:00
										 |  |  | SKETCH_NAME = "s187"  # 20180704 | 
					
						
							| 
									
										
										
										
											2018-07-05 01:57:28 +00:00
										 |  |  | OUTPUT = ".png" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-05 01:59:04 +00:00
										 |  |  | from gif_export_wrapper import * | 
					
						
							| 
									
										
										
										
											2018-07-05 01:57:28 +00:00
										 |  |  | add_library('gifAnimation') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | num_hatches = 30 | 
					
						
							|  |  |  | hatches = [] | 
					
						
							|  |  |  | global_rot = 0 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def setup(): | 
					
						
							|  |  |  |     print_text_for_readme(SKETCH_NAME, OUTPUT) | 
					
						
							| 
									
										
										
										
											2018-07-05 01:59:04 +00:00
										 |  |  |     size(500, 500) | 
					
						
							|  |  |  |     # smooth(4) | 
					
						
							| 
									
										
										
										
											2018-07-05 01:57:28 +00:00
										 |  |  |     for _ in range(num_hatches): | 
					
						
							|  |  |  |         hatches.append(Hatch()) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def draw(): | 
					
						
							|  |  |  |     global global_rot | 
					
						
							|  |  |  |     background(100) | 
					
						
							|  |  |  |     stroke(0) | 
					
						
							|  |  |  |     for i, h in enumerate(hatches): | 
					
						
							| 
									
										
										
										
											2018-07-05 01:59:04 +00:00
										 |  |  |         stroke(map(i, 0, len(hatches) - 1, 0, 255)) | 
					
						
							| 
									
										
										
										
											2018-07-05 01:57:28 +00:00
										 |  |  |         h.plot() | 
					
						
							| 
									
										
										
										
											2018-07-05 01:59:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     global_rot += 0.05 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     gif_export(GifMaker, filename=SKETCH_NAME) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if global_rot > PI: | 
					
						
							|  |  |  |         gif_export(GifMaker, finish=True) | 
					
						
							|  |  |  |         noLoop() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-05 01:57:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | class Hatch: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def __init__(self): | 
					
						
							|  |  |  |         self.n = int(random(10, 40)) | 
					
						
							|  |  |  |         self.space = random(5, 15) | 
					
						
							|  |  |  |         self.half = self.n * self.space / 2. | 
					
						
							|  |  |  |         self.x = random(width) | 
					
						
							|  |  |  |         self.y = random(height) | 
					
						
							|  |  |  |         self.rot = random(TWO_PI) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def plot(self): | 
					
						
							|  |  |  |         with pushMatrix(): | 
					
						
							|  |  |  |             translate(self.x, self.y) | 
					
						
							|  |  |  |             rotate(self.rot + global_rot) | 
					
						
							|  |  |  |             s, l = self.space, self.half | 
					
						
							|  |  |  |             #ellipse(0, 0, 5,5) | 
					
						
							| 
									
										
										
										
											2018-07-05 01:59:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-05 01:57:28 +00:00
										 |  |  |             for i in range(self.n): | 
					
						
							|  |  |  |                 line(s * i - l, -l, s * i - l, l) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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) | 
					
						
							|  |  |  |     ) |