kopia lustrzana https://github.com/villares/sketch-a-day
main
rodzic
66554f5254
commit
ff2ae08d0c
|
|
@ -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=170, # 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: 5.1 MiB |
|
|
@ -0,0 +1,67 @@
|
|||
def setup():
|
||||
size(1220, 400)
|
||||
frameRate(10)
|
||||
|
||||
def draw():
|
||||
from random import seed
|
||||
seed(1)
|
||||
background(0)
|
||||
for function in (grid, shuffled_grid, shoebot_shuffled):
|
||||
g = make_a_grid(function, frameCount % 100)
|
||||
plot_a_grid(g)
|
||||
translate(410, 0)
|
||||
|
||||
def plot_a_grid(a_grid):
|
||||
noStroke()
|
||||
for x, y, s, c in a_grid:
|
||||
fill(c)
|
||||
ellipse(x, y, s, s)
|
||||
|
||||
def shuffled_grid(cols, rows, colSize=1, rowSize=1):
|
||||
from random import shuffle
|
||||
sg = list(grid(cols, rows, colSize, rowSize))
|
||||
shuffle(sg)
|
||||
return sg
|
||||
|
||||
def grid(cols, rows, colSize=1, rowSize=1):
|
||||
"""
|
||||
Returns an iterator that contains coordinate tuples.
|
||||
As seen in Shoebot & Nodebox (minus 'shuffled mode')
|
||||
A common way to use is:
|
||||
# for x, y in grid(10, 10, 12, 12):
|
||||
# rect(x, y, 10, 10)
|
||||
"""
|
||||
rowRange = range(int(rows))
|
||||
colRange = range(int(cols))
|
||||
for y in rowRange:
|
||||
for x in colRange:
|
||||
yield (x * colSize, y * rowSize)
|
||||
|
||||
def shoebot_shuffled(cols, rows, colSize=1, rowSize=1):
|
||||
from random import shuffle
|
||||
rowRange = list(range(int(rows)))
|
||||
colRange = list(range(int(cols)))
|
||||
shuffle(rowRange)
|
||||
shuffle(colRange)
|
||||
for y in rowRange:
|
||||
for x in colRange:
|
||||
yield (x * colSize, y * rowSize)
|
||||
|
||||
def make_a_grid(grid_function, offset=50):
|
||||
colorMode(HSB)
|
||||
i = offset
|
||||
a_grid = []
|
||||
offset_x, offset_y = 20, 20
|
||||
for x, y in grid_function(10, 10, 40, 40):
|
||||
c = color(i * 2.5 % 256, 255, 200)
|
||||
s = 5 + abs(35 - (.7 * (i % 100)))
|
||||
a_grid.append((x + offset_x, y + offset_y, s, c))
|
||||
i += 1
|
||||
return a_grid
|
||||
|
||||
def save_image():
|
||||
from os import path
|
||||
sketch = sketchPath()
|
||||
filename = path.basename(sketch) + '.png'
|
||||
saveFrame(filename)
|
||||
print(filename + ' saved')
|
||||
|
|
@ -16,6 +16,13 @@ You may also support my artistic work, open educational resources and research u
|
|||
|
||||
## 2020
|
||||
|
||||
|
||||
---
|
||||
|
||||

|
||||
|
||||
[sketch_2020_03_21a](https://github.com/villares/sketch-a-day/tree/master/2020/sketch_2020_03_21a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
|
||||
|
||||
---
|
||||
|
||||

|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue