kopia lustrzana https://github.com/villares/sketch-a-day
day 44
rodzic
e5967e9d00
commit
7d2d169c9c
|
@ -8,6 +8,13 @@ If you enjoy this, make a small donation [here](https://www.paypal.com/cgi-bin/w
|
|||
|
||||
----
|
||||
|
||||

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

|
||||
|
||||
043: [code](https://github.com/villares/sketch-a-day/tree/master/s043) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
mode=Python
|
||||
mode.id=jycessing.mode.PythonMode
|
|
@ -0,0 +1,75 @@
|
|||
"""
|
||||
sketch 44 180213b - Alexandre B A Villares
|
||||
https://abav.lugaralgum.com/sketch-a-day
|
||||
"""
|
||||
|
||||
LIST = []
|
||||
|
||||
def setup():
|
||||
size(512, 512)
|
||||
rectMode(CENTER)
|
||||
colorMode(HSB)
|
||||
strokeWeight(2)
|
||||
# x, y, size
|
||||
LIST.append(Cell(size=width * .66))
|
||||
|
||||
def draw():
|
||||
translate(width / 2, height / 2)
|
||||
background(255)
|
||||
for cell in LIST:
|
||||
cell.update()
|
||||
|
||||
def keyPressed():
|
||||
if key == " ":
|
||||
LIST[:] = [Cell(size=width * .66)]
|
||||
|
||||
class Cell():
|
||||
|
||||
def __init__(self, x=0, y=0, size=1):
|
||||
self.LIST = []
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.size = size
|
||||
self.color = color(random(0, 128), 200, 200, 100)
|
||||
|
||||
def update(self):
|
||||
self.draw()
|
||||
if not self.LIST: # para listas vazias (células sem sub-células)
|
||||
if mousePressed and self.on_mouse():
|
||||
self.divide()
|
||||
else: # senão update as sub-células!
|
||||
for cell in self.LIST:
|
||||
cell.update()
|
||||
stroke(0)
|
||||
line(self.x, self.y, cell.x, cell.y)
|
||||
|
||||
def draw(self):
|
||||
noStroke()
|
||||
fill(self.color)
|
||||
if keyPressed:
|
||||
ellipse(self.x, self.y, self.size, self.size)
|
||||
else:
|
||||
rect(self.x, self.y, self.size, self.size)
|
||||
|
||||
def divide(self):
|
||||
x, y, new_size = self.x, self.y, self.size *.50
|
||||
o = self.size * 0.50
|
||||
if new_size > 5:
|
||||
self.LIST.append(Cell(x + o, y + o, new_size))
|
||||
self.LIST.append(Cell(x + o, y - o, new_size))
|
||||
self.LIST.append(Cell(x - o, y + o, new_size))
|
||||
self.LIST.append(Cell(x - o, y - o, new_size))
|
||||
self.LIST.append(Cell(x, y - o, new_size))
|
||||
self.LIST.append(Cell(x, y + o, new_size))
|
||||
self.LIST.append(Cell(x - o, y, new_size))
|
||||
self.LIST.append(Cell(x + o, y, new_size))
|
||||
self.size = new_size
|
||||
|
||||
|
||||
def on_mouse(self):
|
||||
x, y = self.x + width / 2, self.y + height / 2
|
||||
r = self.size / 2
|
||||
if (x - r < mouseX < x + r and
|
||||
y - r < mouseY < y + r):
|
||||
return True
|
||||
|
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 4.8 MiB |
|
@ -0,0 +1,93 @@
|
|||
"""
|
||||
sketch 44 180213a - Alexandre B A Villares
|
||||
https://abav.lugaralgum.com/sketch-a-day
|
||||
"""
|
||||
|
||||
LIST = []
|
||||
SRINK = .50
|
||||
OFFSET = .50
|
||||
SIZE = 256 # base size
|
||||
SAVE_FRAME = False
|
||||
RECT_MODE = True
|
||||
|
||||
def setup():
|
||||
size(512, 512)
|
||||
rectMode(CENTER)
|
||||
colorMode(HSB)
|
||||
strokeWeight(2)
|
||||
# x, y, size
|
||||
LIST.append(Cell())
|
||||
|
||||
def draw():
|
||||
translate(width / 2, height / 2)
|
||||
background(255)
|
||||
for cell in LIST:
|
||||
cell.update()
|
||||
save_frame() # saves frame if SAVE_FRAME is set True
|
||||
|
||||
def keyPressed():
|
||||
global SAVE_FRAME, RECT_MODE
|
||||
if key == " ":
|
||||
LIST[:] = [Cell()]
|
||||
if key == "r":
|
||||
RECT_MODE = not RECT_MODE
|
||||
SAVE_FRAME = True
|
||||
|
||||
|
||||
class Cell():
|
||||
|
||||
def __init__(self, x=0, y=0, gen=0):
|
||||
self.LIST = []
|
||||
self.x, self.y = x, y
|
||||
self.gen = gen
|
||||
self.color = color(random(0, 200), 200, 200, 255)
|
||||
|
||||
def s(self): # size
|
||||
return SIZE * (SRINK ** self.gen)
|
||||
|
||||
def update(self):
|
||||
self.draw()
|
||||
if not self.LIST: # para listas vazias (células sem sub-células)
|
||||
if mousePressed and self.on_mouse():
|
||||
self.divide()
|
||||
else: # senão update as sub-células!
|
||||
for cell in self.LIST:
|
||||
cell.update()
|
||||
stroke(0)
|
||||
line(self.x, self.y, cell.x, cell.y)
|
||||
|
||||
def draw(self):
|
||||
noStroke()
|
||||
fill(self.color)
|
||||
if not RECT_MODE:
|
||||
ellipse(self.x, self.y, self.s(), self.s())
|
||||
else:
|
||||
rect(self.x, self.y, self.s(), self.s())
|
||||
fill(0)
|
||||
#text(str(self.gen), self.x, self.y)
|
||||
|
||||
def divide(self):
|
||||
global SAVE_FRAME
|
||||
SAVE_FRAME = True
|
||||
x, y = self.x, self.y
|
||||
o = self.s() * OFFSET
|
||||
new_gen = self.gen + 1
|
||||
if new_gen < 7:
|
||||
self.LIST.append(Cell(x + o, y + o, gen=new_gen))
|
||||
self.LIST.append(Cell(x + o, y - o, gen=new_gen))
|
||||
self.LIST.append(Cell(x - o, y + o, gen=new_gen))
|
||||
self.LIST.append(Cell(x - o, y - o, gen=new_gen))
|
||||
#self.gen = new_gen
|
||||
|
||||
def on_mouse(self):
|
||||
x, y = self.x + width / 2, self.y + height / 2
|
||||
r = self.s() / 2
|
||||
if (x - r < mouseX < x + r and
|
||||
y - r < mouseY < y + r):
|
||||
return True
|
||||
|
||||
def save_frame():
|
||||
global SAVE_FRAME
|
||||
if SAVE_FRAME:
|
||||
SAVE_FRAME = False
|
||||
saveFrame("######.tga")
|
Ładowanie…
Reference in New Issue