Proyecto Final: Programar para un contexto visual
przez lidervisualgroup @lidervisualgroup
- 66
- 3
- 1
s = 1
save_document = False
def setup():
size(600, 600)
def draw():
global save_document
if save_document:
begin_record(PDF, f"output{s}.pdf")
random_seed(s)
background(0, 0, 30)
fill(0, 0, 50)
no_stroke()
square(300, 300, 525)
stroke(255, 32)
for n in range(2, 60, 2):
line(600 - n ** 2, 0, 1200 - n ** 2, 600)
line(1200 - n ** 2, 0, 600 - n ** 2, 600)
for _ in range(2):
r1 = random_int(0, 100)
r2 = random_int(50, 150)
colores = [color(0, 200, 0 + r2),
color(0, 128, 255 - r1),
color(0, 150 - r2, 50),
color(0, 0, 200 - r1),
]
cuadricula(75, 75, 5, 5, 500, colores)
if save_document:
end_record()
save_document = False
def cuadricula(off_x, off_y, colum, filas, wt, col):
no_stroke()
z = wt / colum
for j in range(filas):
y = off_y + j * z + z/2
for i in range(colum):
x = off_x + i * z + z/2
m = random_int(1, 12)
for _ in range(3):
fill(255, 32)
dr = random_int(0, 2) * z/2
stroke(random_choice(col), 64)
square(x - dr/2, y - dr/2, z/2)
no_stroke()
if m == 1 and z > 50:
fill(200, 0, 64)
h(x, y)
elif 2 <= m < 3 and z > 50:
fill(random_choice(col))
ra = random(z/10, z/2)
rb = random(1, z/6)
np = random_int(4, 6)
star(x, y, ra, rb, np)
elif 3 <= m < 5 and z > 50:
fill(random_choice(col))
star(x, y, 10, 20, 4)
elif m == 5:
fill(random_choice(col))
circle(x, y, random_int(1, 2) * z/4)
elif m == 6:
eye(x, y, z)
if random_int(1, 2) == 2 and z > 50:
cuadricula(x - z/2, y - z/2, random_int(1, 2), random_int(1, 2), z/2, col)
def eye(x, y, w):
no_stroke()
fill(200, 0, 0)
ellipse(x, y, w/3, w/3)
fill(0)
ellipse(x, y, w/10, w/10)
def h(x, y):
rect_mode(CENTER)
no_stroke()
w = 50
rect(x, y, w/2, w/6)
rect(x - 10, y, w/4, w)
rect(x + 10, y + 12, w/5, w/2)
ellipse(x, y - 2, w/2, w/4)
ellipse(x - 7, y, w/5, w)
ellipse(x + 12, y + 11, w/5, w - 22)
def star(cx, cy, ra, rb, n, start_ang=0):
step = TWO_PI / n
begin_shape()
for i in range(n):
ang = start_ang + step * i
ax = cx + cos(ang) * ra
ay = cy + sin(ang) * ra
vertex(ax, ay)
bx = cx + cos(ang + step / 2.0) * rb
by = cy + sin(ang + step / 2.0) * rb
vertex(bx, by)
end_shape(CLOSE)
def mouse_pressed():
global s
s += 1
print(f"Semilla aleatoria: {s}")
def key_pressed():
global save_document
if key == "s":
save_frame(f"output{s}.png")
print("Imagen guardada en PNG")
elif key == "p":
save_document = True
print("Guardando PDF")





1 komentarz
a_b_a_villares
Prowadzący PlusBardzo szczęśliwy!
Zobacz oryginał
Ukryj oryginał
Zaloguj się lub dołącz bezpłatnie, aby móc komentować