kopia lustrzana https://github.com/villares/sketch-a-day
main
rodzic
1bb8261f22
commit
3858b8c4ee
|
|
@ -0,0 +1,44 @@
|
|||
"""
|
||||
Alexandre B A Villares http://abav.lugaralgum.com - GPL v3
|
||||
|
||||
A helper for the Processing gifAnimation library https://github.com/extrapixel/gif-animation/tree/3.0
|
||||
Download from https://github.com/villares/processing-play/blob/master/export_GIF/unzip_and_move_to_libraries_GifAnimation.zip
|
||||
This helper was inspired by an example by Art Simon https://github.com/APCSPrinciples/AnimatedGIF/
|
||||
|
||||
v2019_09_23
|
||||
|
||||
# add at the start of your sketch:
|
||||
add_library('gifAnimation')
|
||||
from gif_animation_helper import gif_export
|
||||
# add at the end of draw():
|
||||
gif_export(GifMaker, "filename")
|
||||
"""
|
||||
|
||||
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=100, # quality range 0 - 255
|
||||
delay=100, # this is quick
|
||||
frames=0, # 0 will stop on keyPressed or frameCount >= 100000
|
||||
finish=False): # force stop
|
||||
global gifExporter
|
||||
try:
|
||||
gifExporter
|
||||
except NameError:
|
||||
gifExporter = GifMaker(this, filename + ".gif")
|
||||
gifExporter.setRepeat(repeat)
|
||||
gifExporter.setQuality(quality)
|
||||
gifExporter.setDelay(delay)
|
||||
print("gif recording started")
|
||||
|
||||
|
||||
gifExporter.addFrame()
|
||||
|
||||
if (frames == 0 and keyPressed and key == "e" or
|
||||
frames != 0 and frameCount >= frames):
|
||||
finish = True
|
||||
|
||||
if finish:
|
||||
gifExporter.finish()
|
||||
print("gif saved, exit")
|
||||
exit()
|
||||
Plik binarny nie jest wyświetlany.
|
Po Szerokość: | Wysokość: | Rozmiar: 534 KiB |
|
|
@ -0,0 +1,74 @@
|
|||
# inspired by https://twitter.com/beesandbombs/status/1247567578802855938?s=20
|
||||
add_library('GifAnimation')
|
||||
from gif_animation_helper import gif_export
|
||||
|
||||
s_size = 60
|
||||
sketch_name = 'sketch_2020_04_14a'
|
||||
|
||||
def setup():
|
||||
size(400, 400)
|
||||
colorMode(HSB)
|
||||
blendMode(ADD) # DIFFERENCE
|
||||
rectMode(CENTER)
|
||||
textSize(120)
|
||||
textAlign(CENTER, CENTER)
|
||||
init()
|
||||
|
||||
def init():
|
||||
from itertools import product
|
||||
from random import shuffle
|
||||
global origin, target, current
|
||||
origin = []
|
||||
target = []
|
||||
grid0 = ((-1, -1), (-1, 0), (0, 0), (0, -1))
|
||||
grid = list(product(range(-3, 3), repeat=2))
|
||||
# shuffle(grid)
|
||||
|
||||
for i, p in enumerate(grid):
|
||||
h_size = s_size / 2
|
||||
off_x, off_y = h_size + p[0] * s_size, h_size + p[1] * s_size
|
||||
element = i % 4
|
||||
target.append((width / 2 + grid0[element][0] * 60 + 30,
|
||||
height / 2 + grid0[element][1] * 60 + 30,
|
||||
0,
|
||||
s_size * 2))
|
||||
origin.append((width / 2. + off_x,
|
||||
height / 2. + off_y,
|
||||
random(-HALF_PI, HALF_PI),
|
||||
random(s_size / 2, s_size * 2)))
|
||||
current = origin[:]
|
||||
|
||||
def draw():
|
||||
background(0)
|
||||
noFill()
|
||||
strokeWeight(5)
|
||||
# t = .5 - cos(radians(frameCount % 360)) / 2. # map(mouseX, 0, width, 0, 1)
|
||||
for i, current_i in enumerate(current):
|
||||
fill((i * 16) % 256, 255, 255)
|
||||
x, y, r, s = current_i
|
||||
current[i] = lerp_sequence(current_i, target[i], .15)
|
||||
pushMatrix()
|
||||
translate(x, y)
|
||||
rotate(r)
|
||||
square(0, 0, s_size / 2)
|
||||
popMatrix()
|
||||
print current[0][0]
|
||||
print target[0][0]
|
||||
if abs(current[0][0] - target[0][0]) < 0.1:
|
||||
target[:] = origin
|
||||
|
||||
if frameCount < 360:
|
||||
# if frameCount % 2:
|
||||
gif_export(GifMaker, sketch_name)
|
||||
else:
|
||||
gif_export(GifMaker, sketch_name, finish=True)
|
||||
|
||||
|
||||
def lerp_sequence(a, b, t):
|
||||
c = []
|
||||
for c_a, c_b in zip(a, b):
|
||||
c.append(lerp(c_a, c_b, t))
|
||||
return c
|
||||
|
||||
def keyPressed():
|
||||
gif_export(GifMaker, sketch_name, finish=True)
|
||||
|
|
@ -18,6 +18,12 @@ You may also support my artistic work, open educational resources and research u
|
|||
|
||||
---
|
||||
|
||||

|
||||
|
||||
[sketch_2020_04_14a](https://github.com/villares/sketch-a-day/tree/master/2020/sketch_2020_04_14a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
|
||||
|
||||
---
|
||||
|
||||
 
|
||||
|
||||
[sketch_2020_04_13a](https://github.com/villares/sketch-a-day/tree/master/2020/sketch_2020_04_13a)<br>
|
||||
|
|
@ -56,7 +62,7 @@ https://abav.lugaralgum.com/sketch-a-day/2020/sketch_2020_04_11a/pyp5js/ [pyp5j]
|
|||
|
||||

|
||||
|
||||
[sketch_2020_04_08a](https://github.com/villares/sketch-a-day/tree/master/2020/sketch_2020_04_07a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
|
||||
[sketch_2020_04_08a](https://github.com/villares/sketch-a-day/tree/master/2020/sketch_2020_04_08a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
|
||||
|
||||
---
|
||||
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue