kopia lustrzana https://github.com/villares/sketch-a-day
main
rodzic
26c985af48
commit
4c4fa85d1b
Plik binarny nie jest wyświetlany.
|
Po Szerokość: | Wysokość: | Rozmiar: 31 KiB |
Plik binarny nie jest wyświetlany.
|
Po Szerokość: | Wysokość: | Rozmiar: 32 KiB |
Plik binarny nie jest wyświetlany.
|
Po Szerokość: | Wysokość: | Rozmiar: 33 KiB |
Plik binarny nie jest wyświetlany.
|
Po Szerokość: | Wysokość: | Rozmiar: 33 KiB |
|
|
@ -0,0 +1,131 @@
|
|||
# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day
|
||||
SKETCH_NAME = "s268" # 20180923
|
||||
|
||||
import pygame # install Pygame https://www.pygame.org
|
||||
from random import choice
|
||||
from random import randint
|
||||
|
||||
gliphs = [lambda x, y, s: rect(x, y, s, s),
|
||||
lambda x, y, s: ellipse(x, y, s, s),
|
||||
lambda x, y, s: triangle(x - s, y, x - s, y + s, x, y + s),
|
||||
lambda x, y, s: triangle(x + s, y, x + s, y - s, x, y - s),
|
||||
]
|
||||
|
||||
def setup():
|
||||
size(1200, 600)
|
||||
|
||||
|
||||
def draw():
|
||||
background(0)
|
||||
grid(300, 300., 4, 150, ensamble, 5) # ensamble of 5 , on grid also order=5
|
||||
grid(width/4.*3, height/2., 4, 150, ensamble, 5) # ensamble of 5 , on grid also order=5
|
||||
noLoop()
|
||||
|
||||
def ensamble(ex, ey, order):
|
||||
for _ in range(order):
|
||||
order, spacing, side = randint(3, 5), 14, 7
|
||||
x, y = randint(-5, 4) * side, randint(-5, 4) * side
|
||||
grid(ex+x, ey+y, order, spacing, choice(gliphs), side)
|
||||
|
||||
|
||||
def grid(x, y, order, spacing, function, *args):
|
||||
xo, yo = (x - order * spacing / 2, y - order * spacing / 2)
|
||||
for i in range(order):
|
||||
gx = spacing/2 + i * spacing
|
||||
for j in range(order):
|
||||
gy = spacing/2 + j * spacing
|
||||
function(xo + gx, yo + gy, *args)
|
||||
|
||||
|
||||
# Now stuff to make it easier to port from Processing to Pygame
|
||||
|
||||
def triangle(x0, y0, x1, y1, x2, y2):
|
||||
# This draws a triangle using the polygon command
|
||||
pygame.draw.polygon(screen, current_fill,
|
||||
[[x0, y0], [x1, y1], [x2, y2]], 0)
|
||||
if _stroke_weight:
|
||||
pygame.draw.polygon(screen, current_stroke,
|
||||
[[x0, y0], [x1, y1], [x2, y2]], _stroke_weight)
|
||||
|
||||
|
||||
def rect(x, y, w, h):
|
||||
pygame.draw.rect(screen, current_fill, [x, y, w, h], 0)
|
||||
if _stroke_weight:
|
||||
pygame.draw.rect(screen, current_stroke, [x, y, w, h], _stroke_weight)
|
||||
|
||||
def ellipse(x, y, w, h):
|
||||
pygame.draw.ellipse(screen, current_fill, [x, y, w, h], 0)
|
||||
if _stroke_weight:
|
||||
pygame.draw.ellipse(screen, current_stroke, [x, y, w, h], _stroke_weight)
|
||||
|
||||
def background(r, g=None, b=None):
|
||||
if g and b:
|
||||
screen.fill((r, g, b))
|
||||
else:
|
||||
screen.fill((r, r, r))
|
||||
|
||||
def fill(r, g=None, b=None):
|
||||
global current_fill
|
||||
if g and b:
|
||||
current_fill = (r, g, b)
|
||||
else:
|
||||
current_fill = (r, r, r)
|
||||
|
||||
def noStroke():
|
||||
global _stroke_weight
|
||||
_stroke_weight = 0
|
||||
|
||||
def size(w, h):
|
||||
global width, height
|
||||
width, height = w, h
|
||||
|
||||
def noLoop():
|
||||
global _pause
|
||||
_pause = True
|
||||
|
||||
def loop():
|
||||
global _pause
|
||||
_pause = False
|
||||
|
||||
|
||||
def run():
|
||||
global width, height, screen, current_fill, current_stroke, _stroke_weight, _pause
|
||||
# Initialize the game engine
|
||||
pygame.init()
|
||||
current_fill = (255, 255, 255)
|
||||
current_stroke = (0, 0, 0)
|
||||
_stroke_weight = 1
|
||||
width, height = 100, 100
|
||||
_done = False
|
||||
_pause = False
|
||||
|
||||
setup()
|
||||
|
||||
# Set the height and width of the screen
|
||||
screen = pygame.display.set_mode([width, height])
|
||||
pygame.display.set_caption(SKETCH_NAME)
|
||||
clock = pygame.time.Clock()
|
||||
draw()
|
||||
# Loop until the user clicks the close button.
|
||||
while not _done:
|
||||
# This limits the while loop to a max of 10 times per second.
|
||||
# Leave this out and we will use all CPU we can.
|
||||
clock.tick(10)
|
||||
|
||||
for event in pygame.event.get(): # User did something
|
||||
if event.type == pygame.QUIT: # If user clicked close
|
||||
_done = True # Flag that we are _done so we exit this loop
|
||||
if event.type == pygame.KEYDOWN:
|
||||
_pause = not _pause
|
||||
# All drawing code happens after the for loop and but
|
||||
# inside the main while _done==False loop.
|
||||
# Draw on screen
|
||||
if not _pause:
|
||||
draw()
|
||||
# Go ahead and update the screen with what we've drawn.
|
||||
# This MUST happen after all the other drawing commands.
|
||||
pygame.display.flip()
|
||||
# Be IDLE friendly
|
||||
pygame.quit()
|
||||
|
||||
run()
|
||||
Plik binarny nie jest wyświetlany.
|
Po Szerokość: | Wysokość: | Rozmiar: 66 KiB |
|
|
@ -0,0 +1,28 @@
|
|||
size(200, 101)
|
||||
colorMode(HSB)
|
||||
noStroke()
|
||||
|
||||
y = 0
|
||||
for i in range(8):
|
||||
fill(i * 32, 255, 255)
|
||||
rect(i * 20, y, 20, 20)
|
||||
|
||||
y += 20
|
||||
for i in range(5):
|
||||
fill(i * 42.5, 255, 255)
|
||||
rect(i * 20, y, 20, 20)
|
||||
|
||||
y += 20
|
||||
for i in range(5):
|
||||
fill(i * 48, 255, 255)
|
||||
rect(i * 20, y, 20, 20)
|
||||
|
||||
y += 20
|
||||
for i in range(5):
|
||||
fill(i * 51, 255, 255)
|
||||
rect(i * 20, y, 20, 20)
|
||||
|
||||
y += 20
|
||||
for i in range(4):
|
||||
fill(i * 64, 255, 255)
|
||||
rect(i * 20, y, 20, 20)
|
||||
Plik binarny nie jest wyświetlany.
|
|
@ -0,0 +1,82 @@
|
|||
# ASCII video
|
||||
|
||||
"""
|
||||
Aperte 'g' para gravar um PDF na pasta do sketch
|
||||
Press 'g' to record a PDF
|
||||
a, d, w, s to change sizes
|
||||
"""
|
||||
add_library('video')
|
||||
add_library('pdf')
|
||||
recordingPDF = False
|
||||
grid_size = 16 # tamanho da grade
|
||||
font_size = 16 # tamanho dsa letras
|
||||
gliphs = (
|
||||
" .`-_':,;^=+/\"|)\\<>)iv%xclrs{*}I?!][1taeo7zjLu" +
|
||||
"nT#JCwfy325Fp6mqSghVd4EgXPGZbYkOA&8U$@KHDBWNMR0Q"
|
||||
)[::-1]
|
||||
print(gliphs)
|
||||
|
||||
def setup():
|
||||
global fonte
|
||||
global colunas, filas, video
|
||||
size(640, 480)
|
||||
noStroke()
|
||||
smooth()
|
||||
rectMode(CENTER)
|
||||
fonte = createFont("SourceCodePro-Bold",60)
|
||||
textFont(fonte)
|
||||
textAlign(CENTER, CENTER)
|
||||
video = Capture(this, width, height)
|
||||
# Começa a captura
|
||||
video.start()
|
||||
background(0)
|
||||
|
||||
|
||||
def draw():
|
||||
global recordingPDF, filas, colunas
|
||||
colunas = int(width / grid_size)
|
||||
filas = int(height / grid_size)
|
||||
if video.available():
|
||||
background(255)
|
||||
# se foi apertado 'g'
|
||||
if recordingPDF:
|
||||
# fill(0)
|
||||
# rect(0, 0, width, height)
|
||||
beginRecord(PDF, "Imagem.pdf")
|
||||
video.read()
|
||||
video.loadPixels()
|
||||
# Loopando as colunas da grade
|
||||
for i in range(colunas):
|
||||
# Loop das filas
|
||||
for j in range(filas):
|
||||
x = i * grid_size
|
||||
y = j * grid_size
|
||||
pos = y * video.width + x # índice da posição do pixel
|
||||
#cor = video.get(x, y)
|
||||
cor = video.pixels[pos]
|
||||
bri = brightness(cor)
|
||||
dar = int(map(bri, 0, 255, 0, len(gliphs)-1))
|
||||
fill(cor) # gliph color
|
||||
textSize(font_size)
|
||||
text(gliphs[dar], x + grid_size / 2, y + grid_size / 2)
|
||||
# dim fo loop das filas
|
||||
# fim do loop das colunas
|
||||
if (recordingPDF):
|
||||
endRecord()
|
||||
println('saved ascii_image.pdf')
|
||||
recordingPDF = False
|
||||
|
||||
|
||||
def keyPressed(self):
|
||||
global recordingPDF, font_size, grid_size
|
||||
if key == 'g':
|
||||
recordingPDF = True
|
||||
if key == 'w':
|
||||
font_size += 1
|
||||
if key == 's' and font_size > 1:
|
||||
font_size -= 1
|
||||
if key == 'a':
|
||||
grid_size += 1
|
||||
if key == 'd' and grid_size > 1:
|
||||
grid_size -= 1
|
||||
|
||||
Ładowanie…
Reference in New Issue