kopia lustrzana https://github.com/villares/sketch-a-day
main
rodzic
359e9b2d84
commit
410d7d7858
Plik binarny nie jest wyświetlany.
Plik binarny nie jest wyświetlany.
|
Po Szerokość: | Wysokość: | Rozmiar: 866 KiB |
|
|
@ -1,117 +1,59 @@
|
|||
CT = "Poly data (c) OpenStreetMap contributors \nhttps://www.openstreetmap.org/copyright"
|
||||
"""
|
||||
Based on sketch 37 180206b
|
||||
https://abav.lugaralgum.com/sketch-a-day
|
||||
"""
|
||||
|
||||
import pickle
|
||||
from pathlib import Path
|
||||
confetti = []
|
||||
SIZE = 15
|
||||
TEXTO = """carnahacking\nvem aí""" # ainda não usei este texto...
|
||||
|
||||
import py5
|
||||
import osmnx as ox
|
||||
import shapely
|
||||
|
||||
x_off = 0
|
||||
y_off = 0
|
||||
zoom = 1
|
||||
|
||||
def setup():
|
||||
global main_shp, geodata, graph
|
||||
py5.size(1000, 1000)
|
||||
py5.stroke_join(py5.ROUND)
|
||||
data_path = Path('osmnx.data')
|
||||
ox.settings.log_console = True
|
||||
ox.settings.requests_timeout = 1000
|
||||
|
||||
if data_path.is_file():
|
||||
print(f'loading GDFs from {data_path}')
|
||||
with open(data_path, 'rb') as f:
|
||||
geodata = pickle.load(f)
|
||||
else:
|
||||
print(f'downloading GDFs with OSMnx.=')
|
||||
city_boundary = ox.geocode_to_gdf("São Paulo, Brazil")
|
||||
se = ox.geocode("Praça da Sé, São Paulo, SP, Brasil")
|
||||
parks_and_squares = ox.features_from_place(
|
||||
"São Paulo, Brazil", tags={
|
||||
'leisure': 'park',
|
||||
'landuse': 'park',
|
||||
'amenity': 'square',
|
||||
})
|
||||
rivers = ox.features_from_place(
|
||||
"São Paulo, Brazil", tags={
|
||||
'water': True,
|
||||
})
|
||||
buildings = ox.features_from_point(
|
||||
se, dist=2000, tags={
|
||||
'building': True,
|
||||
})
|
||||
graph = ox.graph_from_place(
|
||||
"São Paulo, Brazil"
|
||||
)
|
||||
|
||||
geodata = {
|
||||
'boundary': city_boundary,
|
||||
'parks': parks_and_squares,
|
||||
'rivers': rivers,
|
||||
'buildngs': buildings,
|
||||
'graph': graph,
|
||||
}
|
||||
gdf_nodes, gdf_edges = ox.graph_to_gdfs(
|
||||
geodata['graph'],
|
||||
nodes=True, edges=True,
|
||||
node_geometry=True,
|
||||
fill_edge_geometry=False
|
||||
)
|
||||
geodata['edges'] = gdf_edges
|
||||
|
||||
with open(data_path, 'wb') as f:
|
||||
pickle.dump(geodata, f)
|
||||
|
||||
x_min, y_min, x_max, y_max = geodata['boundary'].total_bounds
|
||||
map_w, map_h = (x_max - x_min), (y_max - y_min)
|
||||
x_scale = y_scale = py5.height / map_h
|
||||
main_shp = py5.create_shape(py5.GROUP)
|
||||
for gdf, fill_color, stroke_color, in (
|
||||
(geodata['boundary'], 100, 'white'),
|
||||
(geodata['rivers'], 'blue', None),
|
||||
(geodata['parks'], py5.color(0, 100, 0, 128), None),
|
||||
(geodata['buildngs'], 200, 0),
|
||||
(geodata['edges'], None, 255),
|
||||
):
|
||||
translate_and_scale_gdf(gdf, -x_min, -y_min, x_scale, -y_scale)
|
||||
if fill_color is None:
|
||||
py5.no_fill()
|
||||
else:
|
||||
py5.fill(fill_color)
|
||||
if stroke_color is None:
|
||||
py5.no_stroke()
|
||||
else:
|
||||
py5.stroke(stroke_color)
|
||||
py5.stroke_weight(0.001)
|
||||
shps = shapely.GeometryCollection(tuple(gdf.geometry))
|
||||
main_shp.add_child(py5.convert_shape(shps))
|
||||
size(500, 500) # comment out se for usar com fundo
|
||||
no_stroke()
|
||||
font = create_font("GaroaHackerClubeBold.otf", 24);
|
||||
text_font(font)
|
||||
text_align(CENTER, CENTER) # Alinhamento horizontal e vertical
|
||||
text_size(60) # Tamanho do texto
|
||||
for _ in range(1500):
|
||||
confetti.append(([random(width), # X
|
||||
random(height+20)], # Y
|
||||
random(TWO_PI), # screen plane rotation
|
||||
random(TWO_PI), # "Z" rotation
|
||||
color(random(256), random(256), random(256)) # color
|
||||
))
|
||||
|
||||
def draw():
|
||||
py5.background(200)
|
||||
with py5.push_matrix():
|
||||
py5.scale(zoom)
|
||||
|
||||
py5.shape(main_shp, x_off, py5.height + y_off)
|
||||
#background(fundo)
|
||||
background(0) # comment out se for usar o fundo
|
||||
fill(255)
|
||||
text(TEXTO, width/2, height/2);
|
||||
|
||||
py5.fill(255)
|
||||
py5.text(CT, 400, py5.height-30)
|
||||
for pos, rot1, rot2, color_ in confetti:
|
||||
with push_matrix():
|
||||
x, y = pos
|
||||
max_dist = width / 2
|
||||
dis = dist(x, y, mouse_x, mouse_y)
|
||||
ang = atan2(y - mouse_y, x - mouse_x)
|
||||
if (dis < max_dist):
|
||||
dd = remap(dis, 0, max_dist, 1, 0)
|
||||
df = dd ** 0.95 * dis * 2
|
||||
x += cos(ang) * df
|
||||
y += sin(ang) * df
|
||||
translate(x, y)
|
||||
rotate(rot1 + float(frame_count / 7))
|
||||
s = sin(rot2 + float(frame_count / 11))
|
||||
fill(color_)
|
||||
ellipse(0, 0, SIZE, SIZE * s)
|
||||
pos[1] += 1 + random(0, 2) * s # update y (pos[1])
|
||||
if y > height + 20:
|
||||
pos[1] = -20
|
||||
if dist(x, y, mouse_x, mouse_y) < 100:
|
||||
pos[1] += random(-5, 0)
|
||||
pos[0] += random(-5, 5)
|
||||
|
||||
|
||||
# if frame_count < 300 and not frame_count % 3:
|
||||
# save_frame("###.tga")
|
||||
|
||||
def key_pressed():
|
||||
py5.save('map.png')
|
||||
|
||||
def translate_and_scale_gdf(gdf, x, y, x_scale, y_scale):
|
||||
gdf['geometry'] = gdf.geometry.translate(x, y)
|
||||
gdf['geometry'] = gdf.geometry.scale(
|
||||
xfact=x_scale, yfact=y_scale, origin=(0, 0))
|
||||
|
||||
def mouse_dragged():
|
||||
global x_off, y_off
|
||||
x_off += py5.mouse_x - py5.pmouse_x
|
||||
y_off += py5.mouse_y - py5.pmouse_y
|
||||
|
||||
def mouse_wheel(e):
|
||||
global zoom
|
||||
zoom += e.get_count() / 10
|
||||
|
||||
py5.run_sketch(block=False)
|
||||
|
||||
Plik binarny nie jest wyświetlany.
|
Po Szerokość: | Wysokość: | Rozmiar: 1.8 MiB |
|
|
@ -22,6 +22,16 @@ If you appreciate what I have been doing, you may also support my artistic work,
|
|||
|
||||
---
|
||||
|
||||
### sketch_2025_02_28
|
||||
|
||||

|
||||
|
||||
[sketch_2025_02_28](https://github.com/villares/sketch-a-day/tree/main/2025/sketch_2025_02_28) [[py5](https://py5coding.org/)]
|
||||
|
||||
Domingo vai ter oficina de GIFs animados no Garoa... [versão maior da animação](sketch_2025_02_28_maior.gif)
|
||||
|
||||
---
|
||||
|
||||
### sketch_2025_02_27
|
||||
|
||||

|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue