kopia lustrzana https://github.com/villares/sketch-a-day
				
				
				
			
		
			
	
	
		
			84 wiersze
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Plaintext
		
	
	
		
		
			
		
	
	
			84 wiersze
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Plaintext
		
	
	
|   | # Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day | ||
|  | SKETCH_NAME = "s200"  # 20180717 | ||
|  | OUTPUT = ".gif" | ||
|  | 
 | ||
|  | from gif_export_wrapper import * | ||
|  | add_library('gifAnimation') | ||
|  | add_library('peasycam') | ||
|  | 
 | ||
|  | cycles = 5 | ||
|  | hatches = [] | ||
|  | global_rot = 0 | ||
|  | noise_scale = 0.04 | ||
|  | 
 | ||
|  | def setup(): | ||
|  |     print_text_for_readme(SKETCH_NAME, OUTPUT) | ||
|  |     size(500, 500, P3D) | ||
|  |     cam = PeasyCam(this, 100) | ||
|  |     cam.setMinimumDistance(300) | ||
|  |     cam.setMaximumDistance(1000) | ||
|  |     blendMode(MULTIPLY) | ||
|  |     noStroke() | ||
|  | 
 | ||
|  |     hatches.append(Hatch(color(0, 255, 255),  # cian | ||
|  |                          radians(275))) | ||
|  |     hatches.append(Hatch(color(255, 0, 255),  # magenta | ||
|  |                          radians(45))) | ||
|  |     hatches.append(Hatch(color(255, 255, 0),  # yellow | ||
|  |                          radians(00))) | ||
|  | 
 | ||
|  | def draw(): | ||
|  |     global global_rot | ||
|  |     lights() | ||
|  |     background(200) | ||
|  | 
 | ||
|  |     for i, h in enumerate(hatches): | ||
|  |         translate(0, 0, 10) | ||
|  |         h.plot() | ||
|  | 
 | ||
|  |     global_rot += 0.0314 * 2 | ||
|  | 
 | ||
|  |     if not frameCount % 2: | ||
|  |         gif_export(GifMaker, filename=SKETCH_NAME) | ||
|  | 
 | ||
|  |     if global_rot > TWO_PI: | ||
|  |         gif_export(GifMaker, finish=True) | ||
|  |         noLoop() | ||
|  | 
 | ||
|  | 
 | ||
|  | class Hatch(): | ||
|  | 
 | ||
|  |     def __init__(self, c, rot): | ||
|  |         self.n = width / 6 | ||
|  |         self.space = 10 | ||
|  |         l = self.n * self.space | ||
|  |         self.x = width / 2 | ||
|  |         self.y = height / 2 | ||
|  |         self.rot = rot | ||
|  |         self.c = c | ||
|  |         #println((self.x, self.y, s)) | ||
|  | 
 | ||
|  |     def plot(self): | ||
|  |         with pushMatrix(): | ||
|  |             translate(self.x - width / 2, self.y - height / 2) | ||
|  |             rotate(self.rot) | ||
|  |             s, l = self.space, self.n * self.space | ||
|  |             for i in range(1, self.n): | ||
|  |                 for j in range(1, self.n): | ||
|  |                     d = s * cos(global_rot + i / 10. + j / 10.) | ||
|  |                     fill(self.c) | ||
|  |                     with pushMatrix(): | ||
|  |                         translate(s / 2 + s * i - l / 2., | ||
|  |                                   s / 2 + s * j - l / 2.) | ||
|  |                         box(d) | ||
|  | 
 | ||
|  | 
 | ||
|  | 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) | ||
|  |     ) |