main
Alexandre B A Villares 2018-03-30 11:19:39 -03:00
rodzic fca9282f10
commit 3516964404
6 zmienionych plików z 222 dodań i 2 usunięć

Wyświetl plik

@ -6,13 +6,22 @@ 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)
----
![s089](s089/s089.gif)
089: [code](https://github.com/villares/sketch-a-day/tree/master/s089) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
X stroke now is translucent and grid elements have random colour inside grids.
----
![s088](s088/s088.gif)
088: [code](https://github.com/villares/sketch-a-day/tree/master/s087) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
088: [code](https://github.com/villares/sketch-a-day/tree/master/s088) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
FIlled rects, ellipses and losangles (without sktroke) and Xs
Filled rects, ellipses and losangles (without sktroke) and Xs
----

Wyświetl plik

@ -0,0 +1,36 @@
"""
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=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()

BIN
s089/s089.gif 100644

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 1.6 MiB

66
s089/s089.pyde 100644
Wyświetl plik

@ -0,0 +1,66 @@
# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day
SKETCH_NAME = "s089" # 180330
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, 100, 50, 'w', 's')
C = Slider(1, 40, 10, 'e', 'd')
D = Slider(1, 40, 10, 'r', 'f')
SHAPES = [circle,
square,
exes,
losang]
def setup():
size(600, 600, P2D)
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)
a = int(A.val) # number of elements
b = C.val * B.val / 100 # size of el ements (B.val % of spacing!)
c = int(C.val) # spacing between elements
d = int(D.val) # number of grids
randomSeed(100) # a different random seed
for i in range(d):
tam = a * c
x = int(random(c, width - tam) / c) * c
y = int(random(c, height - tam) / c) * c
#random_a = rnd_choice(range(1, a + 1))
grid(x, y, # random starting point
a, # number of elements
b, # size of elements, a B.val percentage of C.val
c, # spacing of grid elements
rnd_choice(SHAPES)) # random shape drawing function
# 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):
stroke(rnd_choice(COLORS), 200)
fill(rnd_choice(COLORS), 100)
func(i, j, size_)
def rnd_choice(collection):
i = int(random(len(collection)))
return collection[i]

36
s089/shapes.py 100644
Wyświetl plik

@ -0,0 +1,36 @@
COLORS = [color(0), color(0), color(0),
color(255), color(255),
color(200, 0, 100),
]
def circle(x, y, s):
pushStyle()
noStroke()
ellipse(x, y, s, s)
popStyle()
def square(x, y, s):
pushStyle()
rectMode(CENTER)
noStroke()
rect(x, y, s, s)
popStyle()
def exes(x, y, s):
pushStyle()
strokeWeight(3)
with pushMatrix():
translate(x, y)
line(-s / 2, -s / 2, s / 2, s / 2)
line(s / 2, -s / 2, -s / 2, s / 2)
popStyle()
def losang(x, y, s):
pushStyle()
noStroke()
with pushMatrix():
translate(x, y)
rotate(radians(45))
rect(0, 0, s, s)
popStyle()

73
s089/slider.py 100644
Wyświetl plik

@ -0,0 +1,73 @@
"""
Slider code based on Peter Farell's htts://twitter.com/hackingmath
https://github.com/hackingmath/python-sliders http://farrellpolymath.com/
"""
class Slider:
SLIDERS = []
def __init__(self, low, high, default, more_key, less_key):
'''slider has range from low to high
and is set to default'''
self.low = low
self.high = high
self.val = default
self.clicked = False
self.more = more_key
self.less = less_key
Slider.SLIDERS.append(self)
def position(self, x, y):
'''slider's position on screen'''
self.x = x
self.y = y
# the position of the rect you slide:
self.rectx = self.x + map(self.val, self.low, self.high, 0, 120)
self.recty = self.y - 10
def update(self):
'''updates the slider'''
pushStyle()
rectMode(CENTER)
# black translucid rect behind slider
fill(0, 100)
noStroke()
rect(self.x + 60, self.y, 130, 20)
# gray line behind slider
strokeWeight(4)
stroke(200)
line(self.x, self.y, self.x + 120, self.y)
# press mouse to move slider
if (self.x < mouseX < self.x + 120 and
self.y < mouseY < self.y + 20):
fill(250)
textSize(10)
text(str(self.val), self.rectx, self.recty + 35)
if mousePressed:
self.rectx = mouseX
# key usage
if keyPressed:
if key == self.more:
self.rectx += 1
if key == self.less:
self.rectx -= 1
# constrain rectangle
self.rectx = constrain(self.rectx, self.x, self.x + 120)
# draw rectangle
strokeWeight(1)
fill(255)
rect(self.rectx, self.recty + 10, 10, 20)
self.val = map(self.rectx, self.x, self.x + 120, self.low, self.high)
popStyle()
def value(self):
''' backwards compatible method... '''
self.update()
return self.val
@classmethod
def update_all(cls):
for slider in Slider.SLIDERS:
slider.update()