diff --git a/README.md b/README.md index 4b0d6a40..a0cce857 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,15 @@ Hi! I'm [Alexandre Villares](https://abav.lugaralgum.com), let's see if I can ma If you enjoy this, make a small donation [here](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=HCGAKACDMVNV2) or with [Patreon](https://patreon.com/arteprog) + +--- + +![s190](s190/s190b.gif) + +190: [code](https://github.com/villares/sketch-a-day/tree/master/s190) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)] + + + --- ![s189](s189/s189.gif) diff --git a/s190/gif_export_wrapper.py b/s190/gif_export_wrapper.py new file mode 100644 index 00000000..800dad81 --- /dev/null +++ b/s190/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/s190/s190.gif b/s190/s190.gif new file mode 100644 index 00000000..4fb4764a Binary files /dev/null and b/s190/s190.gif differ diff --git a/s190/s190.pyde b/s190/s190.pyde new file mode 100644 index 00000000..7e17be58 --- /dev/null +++ b/s190/s190.pyde @@ -0,0 +1,67 @@ +# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day +SKETCH_NAME = "s190b" # 20180707 +OUTPUT = ".gif" + +from gif_export_wrapper import * +add_library('gifAnimation') + +num_hatches = 10 +hatches = [] +global_rot = 0 + +def setup(): + print_text_for_readme(SKETCH_NAME, OUTPUT) + size(500, 500, P3D) + # smooth(4) + for _ in range(num_hatches): + hatches.append(Hatch()) + +def draw(): + global global_rot + background(200) + stroke(0) + for i, h in enumerate(hatches): + h.plot(do_rotation = (frameCount/50 % num_hatches == i)) + + global_rot += 0.0628 + + if frameCount % 2: + gif_export(GifMaker, filename=SKETCH_NAME) + + if global_rot > PI * num_hatches: + gif_export(GifMaker, finish=True) + noLoop() + + +class Hatch: + + def __init__(self): + self.n = int(random(20, 60)) + self.space = random(5, 15) + self.half = self.n * self.space / 2. + self.x = random(self.half, width - self.half) + self.y = random(self.half, height - self.half) + self.rot = random(TWO_PI) + + def plot(self, do_rotation): + with pushMatrix(): + translate(self.x, self.y) + rotate(self.rot) + if do_rotation: + rotateX(global_rot) + rotateZ(global_rot) + s, l = self.space, self.half + #ellipse(0, 0, 5,5) + + for i in range(self.n): + line(s * i - l, -l, s * i - l, l) + + +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) + ) diff --git a/s190/s190b.gif b/s190/s190b.gif new file mode 100644 index 00000000..46bd0a08 Binary files /dev/null and b/s190/s190b.gif differ