kopia lustrzana https://github.com/villares/sketch-a-day
				
				
				
			
		
			
	
	
		
			97 wiersze
		
	
	
		
			2.3 KiB
		
	
	
	
		
			Plaintext
		
	
	
		
		
			
		
	
	
			97 wiersze
		
	
	
		
			2.3 KiB
		
	
	
	
		
			Plaintext
		
	
	
|   | # Baseado no L-System apresentado pela Tatasz na | ||
|  | # Noite de Processing | ||
|  | 
 | ||
|  | iterations = 5  | ||
|  | # axiom = "F" | ||
|  | axiom = "HF-G-F-G-F" | ||
|  | sentence = axiom | ||
|  | stroke_len = 100 | ||
|  | rules = ( | ||
|  |          ("F", "F-F++F-F"), | ||
|  |          ("G", "G[HG]HG"), | ||
|  |          ("H", "H[-GH]+GH") | ||
|  |          ,) | ||
|  | a = 72 | ||
|  | 
 | ||
|  | def setup(): | ||
|  |     size(700, 700) | ||
|  |     strokeWeight(1) | ||
|  |     generate(iterations) | ||
|  |      | ||
|  | def draw(): | ||
|  |     global a | ||
|  |     background(220, 220, 200)     | ||
|  |     translate(width / 2, height / 2) | ||
|  |     global a     | ||
|  |     angle = radians(a) | ||
|  |     plot(angle) | ||
|  |     # if a <= 180: | ||
|  |     #     saveFrame("sketch###.png") | ||
|  |     #     print a | ||
|  |     #     a += 2.5 | ||
|  |          | ||
|  | 
 | ||
|  | def generate(n): | ||
|  |     global stroke_len, sentence | ||
|  |     for c in range(n): | ||
|  |         stroke_len *= 0.5 | ||
|  |         nextSentence = "" | ||
|  |         for c in sentence: | ||
|  |             found = False | ||
|  |             for c_a, c_b in rules: | ||
|  |                 if c == c_a: | ||
|  |                     found = True | ||
|  |                     nextSentence += c_b | ||
|  |                     break | ||
|  |             if not found: | ||
|  |                 nextSentence += c | ||
|  |         sentence = nextSentence | ||
|  | 
 | ||
|  | def plot(angle): | ||
|  |     for c in sentence: | ||
|  |         if c == "F": | ||
|  |             stroke(200, 0, 0) | ||
|  |             line(0, 0, 0, -stroke_len) | ||
|  |             translate(0, -stroke_len) | ||
|  |          # ellipse(0, 0, 10, 10) | ||
|  |         elif c == "G": | ||
|  |             stroke(0, 0, 200) | ||
|  |             line(0, 0, 0, -stroke_len) | ||
|  |             translate(0, -stroke_len) | ||
|  |         elif c == "H": | ||
|  |             stroke(0, 200, 0) | ||
|  |             line(0, 0, 0, -stroke_len) | ||
|  |             translate(0, -stroke_len) | ||
|  |         elif c == "+": | ||
|  |             rotate(angle) | ||
|  |         elif c == "-": | ||
|  |             rotate(-angle) | ||
|  |         elif c == "[": | ||
|  |             pushMatrix() | ||
|  |         elif c == "]": | ||
|  |             popMatrix() | ||
|  |    | ||
|  | def keyPressed(): | ||
|  |     global a | ||
|  |     if keyCode == LEFT: | ||
|  |         a -= 5 | ||
|  |     if keyCode == RIGHT: | ||
|  |         a += 5         | ||
|  |     if key == 's': | ||
|  |         saveFrame("####.png") | ||
|  |                        | ||
|  |                                            | ||
|  | def settings(): | ||
|  |     """ print markdown to add at the sketch-a-day page""" | ||
|  |     from os import path | ||
|  |     global SKETCH_NAME, OUTPUT | ||
|  |     SKETCH_NAME = path.basename(sketchPath()) | ||
|  |     OUTPUT = ".png" | ||
|  |     println( | ||
|  |         """ | ||
|  |  | ||
|  | 
 | ||
|  | [{0}](https://github.com/villares/sketch-a-day/tree/master/{2}/{0}) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)] | ||
|  | """.format(SKETCH_NAME, OUTPUT, year()) | ||
|  |     ) |