-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
445 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
""" | ||
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 add_library('gifAnimation') at the start of your sketch | ||
and add gif_export(GifMaker) at the end of draw() | ||
""" | ||
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=32, # quality range 0 - 255 | ||
delay=170, # this is quick | ||
frames=0): # 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) | ||
|
||
gifExporter.addFrame() | ||
|
||
if (frames == 0 and keyPressed or frameCount >= 100000) \ | ||
or (frames != 0 and frameCount >= frames): | ||
gifExporter.finish() | ||
print("gif saved") | ||
exit() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day | ||
SKETCH_NAME = "s087" # 180328 | ||
|
||
add_library('gifAnimation') | ||
from gif_exporter import gif_export | ||
from slider import Slider | ||
from shapes import * | ||
|
||
A = Slider(1, 40, 10, 'q', 'a') | ||
B = Slider(1, 40, 10, 'w', 's') | ||
C = Slider(1, 40, 10, 'e', 'd') | ||
D = Slider(1, 40, 10, 'r', 'f') | ||
|
||
SHAPES = [ellipse, | ||
rect, | ||
exes, | ||
losang] | ||
|
||
COLORS = [color(0), color(0), color(0), | ||
color(255), color(255), | ||
color(200, 0, 100), | ||
] | ||
|
||
def setup(): | ||
size(600, 600, P2D) | ||
colorMode(HSB) | ||
rectMode(CENTER) | ||
|
||
A.position(40, height - 70) | ||
B.position(40, height - 30) | ||
C.position(width - 140, height - 70) | ||
D.position(width - 140, height - 30) | ||
|
||
def draw(): | ||
background(200) | ||
noFill() | ||
|
||
a = int(A.val) # number of elements | ||
b = int(B.val) # size of elements | ||
c = int(C.val) # space between elements | ||
d = int(D.val) # number of grids | ||
|
||
randomSeed(int(d * 100)) # a different random seed | ||
|
||
for i in range(d): | ||
tam = a * c | ||
x = int(random(width - tam) / c) * c | ||
y = int(random(height - tam) / c) * c | ||
stroke(rnd_choice(COLORS)) | ||
noFill() # fill(rnd_choice(COLORS), 100) | ||
strokeWeight(int(random(1, 3))) | ||
random_a = rnd_choice(range(1, a + 1)) | ||
grid(x, y, random_a, b, c, rnd_choice(SHAPES)) | ||
|
||
# uncomment next lines to export GIF | ||
if not frameCount % 30: | ||
gif_export(GifMaker, | ||
frames=2000, | ||
delay=500, | ||
filename=SKETCH_NAME) | ||
|
||
# Draws sliders and checks for mouse dragging or keystrokes | ||
Slider.update_all() | ||
|
||
def grid(x, y, num, size_, space, func): | ||
for i in range(x, x + num * space, space): | ||
for j in range(y, y + num * space, space): | ||
func(i, j, size_, size_) | ||
|
||
def rnd_choice(collection): | ||
i = int(random(len(collection))) | ||
return collection[i] | ||
|
||
# def keyPressed(): | ||
# saveFrame(SKETCH_NAME + '_###.gif') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
def exes(x, y, c, _): | ||
with pushMatrix(): | ||
translate(x, y) | ||
line(-c / 2, -c / 2, c / 2, c / 2) | ||
line(c / 2, -c / 2, -c / 2, c / 2) | ||
|
||
def losang(x, y, c, _): | ||
with pushMatrix(): | ||
translate(x, y) | ||
rotate(radians(45)) | ||
rect(0, 0, c, c) |
Oops, something went wrong.