diff --git a/s199/gif_export_wrapper.py b/s199/gif_export_wrapper.py new file mode 100644 index 00000000..800dad81 --- /dev/null +++ b/s199/gif_export_wrapper.py @@ -0,0 +1,38 @@ +""" +Alexandre B A Villares http://abav.lugaralgum.com - GPL v3 + +A helper for the Processing gifAnimation library (https://github.com/jordanorelli) +ported to Processing 3 by 01010101 (https://github.com/01010101) +Download the library from https://github.com/01010101/GifAnimation/archive/master.zip +This helper was inspired by an example by Art Simon https://github.com/APCSPrinciples/AnimatedGIF/ + +Put at the start of your sketch: + add_library('gifAnimation') + from gif_exporter import gif_export +and at the end of draw(): + gif_export(GifMaker) +""" + +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=128, # quality range 0 - 255 + delay=170, # this is quick + finish=False): # 0 will stop on keyPressed or frameCount >= 100000 + global gifExporter + try: + gifExporter + except NameError: + gifExporter = GifMaker(this, filename + ".gif") + gifExporter.setRepeat(repeat) + gifExporter.setQuality(quality) + gifExporter.setDelay(delay) + gif_export._frame = frameCount + print("gif start") + + gifExporter.addFrame() + if finish: + gifExporter.finish() + print("gif saved") + del(gifExporter) + diff --git a/s199/s199.gif b/s199/s199.gif new file mode 100644 index 00000000..0ef4bd08 Binary files /dev/null and b/s199/s199.gif differ diff --git a/s199/s199.pyde b/s199/s199.pyde new file mode 100644 index 00000000..42a1af97 --- /dev/null +++ b/s199/s199.pyde @@ -0,0 +1,78 @@ +# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day +SKETCH_NAME = "s199" # 20180713 +OUTPUT = ".gif" + +from gif_export_wrapper import * +add_library('gifAnimation') + +cycles = 5 +hatches = [] +global_rot = 0 +noise_scale = 0.04 + +def setup(): + print_text_for_readme(SKETCH_NAME, OUTPUT) + size(500, 500, P2D) + 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 + background(200) + + for i, h in enumerate(hatches): + 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, self.y) + 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): + x = s / 2 + s * i - l / 2. + y = s / 2 + s * j - l / 2. + w = dist(mouseX - width / 2, mouseY - height / 2, x, y) + #wy = sin(global_rot ) + d = s * map(w, 0, width / 2, 0, 1) + fill(self.c) + ellipse(x, y, d, d) + + +def print_text_for_readme(name, output): + println(""" +![{0}]({0}/{0}{2}) + +{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) + )