kopia lustrzana https://github.com/villares/sketch-a-day
main
rodzic
88d1aea176
commit
97c602c361
|
|
@ -7,6 +7,12 @@ Hi! I'm [Alexandre Villares](https://abav.lugaralgum.com), let's see if I can ma
|
|||
If you enjoy this, be a [patreon](https://patreon.com/arteprog) or make a donation [here](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=HCGAKACDMVNV2)
|
||||
|
||||
|
||||
---
|
||||
|
||||

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

|
||||
|
|
|
|||
|
|
@ -0,0 +1,44 @@
|
|||
from random import choice
|
||||
|
||||
class Node():
|
||||
nodes = []
|
||||
|
||||
def __init__(self, x, y):
|
||||
self.x = Node.border + Node.spacing / 2 + x * Node.spacing - width / 2
|
||||
self.y = Node.border + Node.spacing / 2 + y * Node.spacing - height / 2
|
||||
self.size_ = 1
|
||||
self.rot0 = choice((0, HALF_PI)) #, PI, PI + HALF_PI))
|
||||
self.rot1 = choice((HALF_PI , PI)) #, PI + HALF_PI))
|
||||
|
||||
def plot(self, ang):
|
||||
""" draws node """
|
||||
with pushMatrix():
|
||||
translate(self.x, self.y)
|
||||
d = abs(self.rot0 + ang - self.rot1)
|
||||
if d >= 0.30:
|
||||
rotate(self.rot0 + ang)
|
||||
else:
|
||||
self.rot0 = self.rot1 - ang
|
||||
rotate(self.rot1)
|
||||
|
||||
noFill() #stroke(0)
|
||||
stroke(0, 0, 200, 50)
|
||||
siz = Node.spacing * self.size_
|
||||
rect(0, 0, siz, siz)
|
||||
# line(-siz/2, -siz/2, siz/2, siz/2)
|
||||
stroke(0, 100, 100)
|
||||
arc(-siz/2, -siz/2, siz, siz, 0, HALF_PI)
|
||||
arc(siz/2, siz/2, siz, siz,PI, PI+HALF_PI)
|
||||
|
||||
@classmethod
|
||||
def init_grid(cls, grid_size, border):
|
||||
cls.border = border
|
||||
cls.spacing = (width - cls.border * 2) / grid_size
|
||||
cls.nodes = []
|
||||
for x in range(grid_size):
|
||||
for y in range(grid_size):
|
||||
new_node = cls(x, y)
|
||||
cls.nodes.append(new_node)
|
||||
|
||||
|
||||
|
||||
Plik binarny nie jest wyświetlany.
|
Po Szerokość: | Wysokość: | Rozmiar: 3.8 MiB |
|
|
@ -0,0 +1,68 @@
|
|||
# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day
|
||||
SKETCH_NAME = "s286" # 20181011
|
||||
OUTPUT = ".gif"
|
||||
|
||||
GRID_SIZE = 10
|
||||
BORDER = 50
|
||||
|
||||
from random import seed
|
||||
from random import choice
|
||||
from node import Node
|
||||
|
||||
def setup():
|
||||
size(500, 500)
|
||||
strokeWeight(2)
|
||||
rectMode(CENTER)
|
||||
frameRate(10)
|
||||
random_seed(101)
|
||||
Node.init_grid(GRID_SIZE, BORDER)
|
||||
|
||||
def draw():
|
||||
translate(width/2, height/2)
|
||||
background(200)
|
||||
ang = frameCount/31.
|
||||
|
||||
for node in Node.nodes:
|
||||
node.plot(ang)
|
||||
|
||||
if ang < TWO_PI:
|
||||
saveFrame("###.png")
|
||||
else:
|
||||
noLoop()
|
||||
|
||||
|
||||
def init_grid(grid_size):
|
||||
Node.border = 50
|
||||
Node.spacing = (width - Node.border * 2) / grid_size
|
||||
Node.nodes = []
|
||||
for x in range(grid_size):
|
||||
for y in range(grid_size):
|
||||
new_node = Node(x, y)
|
||||
Node.nodes.append(new_node)
|
||||
|
||||
|
||||
def keyPressed():
|
||||
if key == "n":
|
||||
init_grid(GRID_SIZE)
|
||||
if key == "s": saveFrame("###.png")
|
||||
|
||||
|
||||
def random_seed(s=None):
|
||||
global rnd_seed
|
||||
if s:
|
||||
rnd_seed = s
|
||||
seed(rnd_seed)
|
||||
randomSeed(rnd_seed)
|
||||
else:
|
||||
seed(rnd_seed)
|
||||
randomSeed(rnd_seed)
|
||||
|
||||
# print text to add to the project's README.md
|
||||
def settings():
|
||||
println(
|
||||
"""
|
||||

|
||||
|
||||
{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(SKETCH_NAME, SKETCH_NAME[1:], OUTPUT)
|
||||
)
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
from random import choice
|
||||
|
||||
class Node():
|
||||
nodes = []
|
||||
|
||||
def __init__(self, x, y):
|
||||
self.x = Node.border + Node.spacing / 2 + x * Node.spacing - width / 2
|
||||
self.y = Node.border + Node.spacing / 2 + y * Node.spacing - height / 2
|
||||
self.size_ = 1
|
||||
self.rot0 = choice((0, HALF_PI)) #, PI, PI + HALF_PI))
|
||||
self.rot1 = choice((HALF_PI , PI)) #, PI + HALF_PI))
|
||||
self.rot2 = self.rot0
|
||||
|
||||
def plot(self, ang):
|
||||
""" draws node """
|
||||
with pushMatrix():
|
||||
translate(self.x, self.y)
|
||||
if abs(self.rot0 - self.rot1) >= 0.03:
|
||||
if ang > 0: self.rot0 += 0.03
|
||||
else:
|
||||
self.rot0 = self.rot1
|
||||
|
||||
rotate(self.rot0)
|
||||
noFill() #stroke(0)
|
||||
stroke(0, 0, 200, 50)
|
||||
siz = Node.spacing * self.size_
|
||||
rect(0, 0, siz, siz)
|
||||
# line(-siz/2, -siz/2, siz/2, siz/2)
|
||||
stroke(0, 100, 100)
|
||||
arc(-siz/2, -siz/2, siz, siz, 0, HALF_PI)
|
||||
arc(siz/2, siz/2, siz, siz,PI, PI+HALF_PI)
|
||||
|
||||
@classmethod
|
||||
def init_grid(cls, grid_size, border):
|
||||
cls.border = border
|
||||
cls.spacing = (width - cls.border * 2) / grid_size
|
||||
cls.nodes = []
|
||||
for x in range(grid_size):
|
||||
for y in range(grid_size):
|
||||
new_node = cls(x, y)
|
||||
cls.nodes.append(new_node)
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day
|
||||
SKETCH_NAME = "s286" # 20181011
|
||||
OUTPUT = ".gif"
|
||||
GRID_SIZE = 10
|
||||
BORDER = 50
|
||||
trans = False
|
||||
ang = -HALF_PI
|
||||
|
||||
from random import seed
|
||||
from random import choice
|
||||
from node import Node
|
||||
|
||||
def setup():
|
||||
size(500, 500)
|
||||
strokeWeight(2)
|
||||
rectMode(CENTER)
|
||||
frameRate(10)
|
||||
random_seed(101)
|
||||
Node.init_grid(GRID_SIZE, BORDER)
|
||||
|
||||
def draw():
|
||||
translate(width/2, height/2)
|
||||
background(200)
|
||||
|
||||
for node in Node.nodes:
|
||||
node.plot(ang)
|
||||
|
||||
global ang
|
||||
if ang < TWO_PI * 2:
|
||||
#saveFrame("###.png")
|
||||
ang += 0.03
|
||||
if abs(ang - TWO_PI) <= 0.03:
|
||||
Node.send_back()
|
||||
|
||||
|
||||
def keyPressed():
|
||||
if key == "n":
|
||||
Node.init_grid(GRID_SIZE, BORDER)
|
||||
if key == "s": saveFrame("###.png")
|
||||
|
||||
|
||||
def random_seed(s=None):
|
||||
global rnd_seed
|
||||
if s:
|
||||
rnd_seed = s
|
||||
seed(rnd_seed)
|
||||
randomSeed(rnd_seed)
|
||||
else:
|
||||
seed(rnd_seed)
|
||||
randomSeed(rnd_seed)
|
||||
|
||||
# print text to add to the project's README.md
|
||||
def settings():
|
||||
println(
|
||||
"""
|
||||

|
||||
|
||||
{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(SKETCH_NAME, SKETCH_NAME[1:], OUTPUT)
|
||||
)
|
||||
Ładowanie…
Reference in New Issue