kopia lustrzana https://github.com/villares/sketch-a-day
				
				
				
			Update sketch_2020_03_05a.pyde
							rodzic
							
								
									ffe4e69fd9
								
							
						
					
					
						commit
						a2192a1da0
					
				|  | @ -1,15 +1,14 @@ | ||||||
| # add_library('GifAnimation') | add_library('GifAnimation') | ||||||
| # from gif_animation_helper import gif_export | from gif_animation_helper import gif_export | ||||||
| 
 | 
 | ||||||
| from arcs import * | from arcs import * | ||||||
| 
 | 
 | ||||||
| many_arrows = [] | many_arrows = [] | ||||||
| num_arrows, num_transitions = 3, 4 | num_arrows, num_transitions = 5, 3 | ||||||
| i, t = 0, 0 | i, t = 0, 0 | ||||||
| 
 | 
 | ||||||
| def setup(): | def setup(): | ||||||
|     size(400, 400) |     size(400, 400) | ||||||
|     # colorMode(HSB) |  | ||||||
|     strokeJoin(ROUND) |     strokeJoin(ROUND) | ||||||
|     frameRate(30) |     frameRate(30) | ||||||
|     smooth(8) |     smooth(8) | ||||||
|  | @ -27,7 +26,8 @@ def create_arrows(): | ||||||
| 
 | 
 | ||||||
| def draw(): | def draw(): | ||||||
|     global t, i |     global t, i | ||||||
|     background(200) |     colorMode(RGB) | ||||||
|  |     background(235, 230, 235) | ||||||
|     if t <= width: |     if t <= width: | ||||||
|         tt = map(t, 0, width, 0, 1) |         tt = map(t, 0, width, 0, 1) | ||||||
|     else: |     else: | ||||||
|  | @ -37,34 +37,29 @@ def draw(): | ||||||
|     for a, b in zip(ini_arrows, fin_arrows): |     for a, b in zip(ini_arrows, fin_arrows): | ||||||
|         mid_arrow = lerp_arrow(a, b, tt) |         mid_arrow = lerp_arrow(a, b, tt) | ||||||
|         rad, start, sweep, thick, h = mid_arrow |         rad, start, sweep, thick, h = mid_arrow | ||||||
|         noFill() |         strokeWeight(2) | ||||||
|         strokeWeight(4) |         for m in range(10): | ||||||
|         if thick > 0: |             ta = tt * m | ||||||
|             start = TWO_PI * tt |             if thick > 0: | ||||||
|         else: |                 start = TWO_PI * ta  | ||||||
|             start = TWO_PI * -tt |             else: | ||||||
|  |                 start = TWO_PI * -ta             | ||||||
|  |             mid_arrow[1] = start | ||||||
|              |              | ||||||
|         while start > TWO_PI: |             noFill() | ||||||
|             start -= TWO_PI |             colorMode(HSB) | ||||||
|         while start < -TWO_PI: |             stroke(h, 200, 200) | ||||||
|             start += TWO_PI |             arc_arrow(width / 2, height / 2, rad * ta / 5., start, sweep, thick) | ||||||
|              |  | ||||||
|         mid_arrow[1] = start |  | ||||||
|         if mouse_on_arrow(mid_arrow): |  | ||||||
|             stroke(255, 150) |  | ||||||
|         else: |  | ||||||
|             stroke(0, 150) |  | ||||||
|         noFill() |  | ||||||
|         arc_arrow(width / 2, height / 2, rad, start, sweep, thick) |  | ||||||
| 
 | 
 | ||||||
|     if t < width: |     if t < width: | ||||||
|         t = lerp(t, width + 1, .01) |         t = lerp(t, width + 1, .02) | ||||||
|     else: |     else: | ||||||
|         t = 0 |         t = 0 | ||||||
|         i = (i + 1) % num_transitions |         i = (i + 1) % num_transitions | ||||||
|     #     if i == 0: |         if i == 0: | ||||||
|     #         gif_export(GifMaker, finish=True) |             gif_export(GifMaker, finish=True) | ||||||
|     # gif_export(GifMaker, filename="sketch") |     if frameCount % 2: | ||||||
|  |         gif_export(GifMaker, filename="sketch") | ||||||
| 
 | 
 | ||||||
| def lerp_arrow(a, b, t): | def lerp_arrow(a, b, t): | ||||||
|     result = [] |     result = [] | ||||||
|  | @ -81,24 +76,6 @@ def random_arrow(): | ||||||
|             random(256)  # hue |             random(256)  # hue | ||||||
|             ] |             ] | ||||||
| 
 | 
 | ||||||
| def mouse_on_arrow(a, precision=10): |  | ||||||
|     mx, my = width / 2, height / 2 |  | ||||||
|     rad, start, sweep, thick, _ = a |  | ||||||
|     # start += thick * radians(frameCount % 361) / 10. |  | ||||||
|     same_rad = abs(abs(rad) - dist(mouseX, mouseY, mx, my)) < precision |  | ||||||
|     mouse_ang = atan2(mouseY - my, mouseX - mx) |  | ||||||
|     line(mouseX, mouseY, mx, my) |  | ||||||
|     textSize(14) |  | ||||||
|     fill(255, 0, 0) |  | ||||||
|     text(str(int(degrees(mouse_ang))), mouseX, mouseY) |  | ||||||
|     in_sweep = start < mouse_ang < degrees(start + sweep) |  | ||||||
|     x, y = point_on_arc(mx, my, abs(rad), start) |  | ||||||
|     text(str(int(degrees(start))), x, y) |  | ||||||
|     x, y = point_on_arc(mx, my, abs(rad), start + sweep) |  | ||||||
|     text(str(int(degrees(start+sweep))), x, y) |  | ||||||
|     # return same_rad and in_sweep |  | ||||||
|     return in_sweep |  | ||||||
| 
 |  | ||||||
| 
 | 
 | ||||||
| def keyPressed(): | def keyPressed(): | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Ładowanie…
	
		Reference in New Issue
	
	 Alexandre B A Villares
						Alexandre B A Villares