|
|
@ -71,14 +71,17 @@ def draw_combo(n):
|
|||
stroke(0, 0, 100, 200)
|
||||
# noStroke()
|
||||
fill(200)
|
||||
siz = space #/ 2. # B option
|
||||
siz = space / 2. # B option
|
||||
first_line = bar_combos[n][0]
|
||||
next_line = bar_combos[n][1]
|
||||
jn = 8
|
||||
for j in range(8):
|
||||
jn = 5
|
||||
for j in range(jn):
|
||||
strokeWeight(2)
|
||||
(x0, y0), (x1, y1) = lerp_poly(first_line, next_line, j / (jn - 1.))
|
||||
strokeWeight(1 + j / 4)
|
||||
line(x0 * siz, y0 * siz, x1 * siz, y1 * siz)
|
||||
(x0, y1), (x1, y0) = lerp_poly(first_line, next_line, j / (jn - 1.))
|
||||
line(x0 * siz, y0 * siz, x1 * siz, y1 * siz)
|
||||
|
||||
|
||||
def keyPressed():
|
||||
global W, H
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
|
||||
|
||||
|
||||
def csgTranslate(csg, x, y, z):
|
||||
return csg.transformed(Transform.unity().translate(x, y, z))
|
||||
|
||||
def csgRot(csg, x, y, z):
|
||||
return csg.transformed(Transform.unity().rot(x, y, z))
|
||||
|
||||
def CSGToPShape(mesh, scale):
|
||||
"""
|
||||
Convert a CSG mesh to a Processing PShape
|
||||
"""
|
||||
result = createShape(GROUP) # allocate a PShape group
|
||||
# for each polygon (Note: these can have 3,4 or more vertices)
|
||||
for p in mesh.getPolygons():
|
||||
# make a child PShape
|
||||
polyShape = createShape()
|
||||
# begin setting vertices to it
|
||||
polyShape.beginShape()
|
||||
# for each vertex in the polygon
|
||||
for v in p.vertices:
|
||||
# add each (scaled) polygon vertex
|
||||
polyShape.vertex(v.pos.getX() * scale,
|
||||
v.pos.getY() * scale,
|
||||
v.pos.getZ() * scale)
|
||||
|
||||
# finish this polygon
|
||||
polyShape.endShape()
|
||||
# append the child PShape to the parent
|
||||
result.addChild(polyShape)
|
||||
|
||||
return result
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day
|
||||
|
||||
"""
|
||||
First trial of the JCSG library prepared for Processing by George Profenza https://stackoverflow.com/users/89766/george-profenza
|
||||
"""
|
||||
# You'll need to copy these libs into your Processing libraries folder:
|
||||
add_library('VVecMath')
|
||||
add_library('jcsg')
|
||||
|
||||
from csg_helpers import *
|
||||
|
||||
def setup():
|
||||
global pshape_result
|
||||
size(600, 500, P3D)
|
||||
noStroke()
|
||||
csg_result = calculate_stuff()
|
||||
pshape_result = CSGToPShape(csg_result, 45)
|
||||
|
||||
|
||||
def draw():
|
||||
background(0)
|
||||
lights()
|
||||
translate(width * 0.5, height * 0.5, 0)
|
||||
rotateY(map(mouseX, 0, width, -PI, PI))
|
||||
rotateX(map(mouseY, 0, height, PI, -PI))
|
||||
shape(pshape_result)
|
||||
|
||||
|
||||
def calculate_stuff():
|
||||
global csgResult # the PShape reference which will contain the converted
|
||||
|
||||
# Jsample code:
|
||||
# we use cube and sphere_ as base geometries
|
||||
cube = RoundedCube(2).toCSG()
|
||||
sphere_ = Sphere(1.25).toCSG()
|
||||
|
||||
# perform union, difference and intersection
|
||||
cubePlusSphere = cube.union(sphere_)
|
||||
cubePlusSphere = csgTranslate(cubePlusSphere, 6, 0, 0)
|
||||
|
||||
cubeMinusSphere = cube.difference(sphere_)
|
||||
cubeMinusSphere = csgTranslate(cubeMinusSphere, 9, 0, 0)
|
||||
|
||||
cubeIntersectSphere = cube.intersect(sphere_)
|
||||
cubeIntersectSphere = csgTranslate(cubeIntersectSphere, 12, 0, 0)
|
||||
|
||||
sphere_ = csgTranslate(sphere_, 3, 0, 0)
|
||||
union = cube.union((sphere_,
|
||||
cubePlusSphere,
|
||||
cubeMinusSphere,
|
||||
cubeIntersectSphere))
|
||||
|
||||
# translate merged geometry back by half to pivot around centre
|
||||
return csgTranslate(union, -6, 0, 0)
|
||||
|
||||
|
||||
def keyPressed():
|
||||
saveFrame("###.png")
|
||||
|
||||
|
||||
def settings():
|
||||
from os import path
|
||||
global SKETCH_NAME
|
||||
SKETCH_NAME = path.basename(sketchPath())
|
||||
OUTPUT = ".png"
|
||||
println(
|
||||
"""
|
||||

|
||||
|
||||
[{0}](https://github.com/villares/sketch-a-day/tree/master/{2}/{0}) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
|
||||
""".format(SKETCH_NAME, OUTPUT, year())
|
||||
)
|
||||
|
Po Szerokość: | Wysokość: | Rozmiar: 3.9 KiB |
|
Po Szerokość: | Wysokość: | Rozmiar: 3.0 KiB |
|
Po Szerokość: | Wysokość: | Rozmiar: 4.3 KiB |
|
Po Szerokość: | Wysokość: | Rozmiar: 3.5 KiB |
|
Po Szerokość: | Wysokość: | Rozmiar: 2.5 KiB |
|
Po Szerokość: | Wysokość: | Rozmiar: 2.8 KiB |
|
Po Szerokość: | Wysokość: | Rozmiar: 4.3 KiB |
|
Po Szerokość: | Wysokość: | Rozmiar: 3.1 KiB |
|
Po Szerokość: | Wysokość: | Rozmiar: 4.2 KiB |
|
|
@ -0,0 +1,100 @@
|
|||
# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day
|
||||
|
||||
"""
|
||||
First trial of the JCSG library prepared for Processing by George Profenza https://stackoverflow.com/users/89766/george-profenza
|
||||
"""
|
||||
# You'll need to copy these libs into your Processing libraries folder:
|
||||
add_library('VVecMath')
|
||||
add_library('jcsg')
|
||||
|
||||
from random import choice
|
||||
|
||||
dim = (2, 3, 4, 5, 6)
|
||||
|
||||
|
||||
def setup():
|
||||
global pshape_result
|
||||
size(600, 500, P3D)
|
||||
noStroke()
|
||||
csg_result = calculate_stuff()
|
||||
pshape_result = CSGToPShape(csg_result, 45)
|
||||
|
||||
|
||||
def draw():
|
||||
background(0)
|
||||
lights()
|
||||
translate(width * 0.5, height * 0.5, -height/2)
|
||||
rotateY(map(mouseX, 0, width, -PI, PI))
|
||||
rotateX(map(mouseY, 0, height, PI, -PI))
|
||||
shape(pshape_result)
|
||||
|
||||
|
||||
def calculate_stuff():
|
||||
solids = []
|
||||
for i, s in enumerate(range(5)):
|
||||
w, h, d = choice(dim), choice(dim), choice(dim)
|
||||
cube = Cube(w, h, d).toCSG()
|
||||
if w % 2:
|
||||
hole = Cube(w-1, h, d-1).toCSG()
|
||||
else:
|
||||
hole = Cube(w, h-1, d-1).toCSG()
|
||||
solid = cube.difference(hole)
|
||||
solids.append(csgTranslate(solid, i * 3, 0, 0))
|
||||
|
||||
union = solids[0].union(solids[1:])
|
||||
|
||||
# translate merged geometry back by half to pivot around centre
|
||||
return csgTranslate(union, -6, 0, 0)
|
||||
|
||||
|
||||
def csgTranslate(csg, x, y, z):
|
||||
return csg.transformed(Transform.unity().translate(x, y, z))
|
||||
|
||||
def csgRot(csg, x, y, z):
|
||||
return csg.transformed(Transform.unity().rot(x, y, z))
|
||||
|
||||
def CSGToPShape(mesh, scale):
|
||||
"""
|
||||
Convert a CSG mesh to a Processing PShape
|
||||
"""
|
||||
result = createShape(GROUP) # allocate a PShape group
|
||||
# for each polygon (Note: these can have 3,4 or more vertices)
|
||||
for p in mesh.getPolygons():
|
||||
# make a child PShape
|
||||
polyShape = createShape()
|
||||
# begin setting vertices to it
|
||||
polyShape.beginShape()
|
||||
# for each vertex in the polygon
|
||||
for v in p.vertices:
|
||||
# add each (scaled) polygon vertex
|
||||
polyShape.vertex(v.pos.getX() * scale,
|
||||
v.pos.getY() * scale,
|
||||
v.pos.getZ() * scale)
|
||||
|
||||
# finish this polygon
|
||||
polyShape.endShape()
|
||||
# append the child PShape to the parent
|
||||
result.addChild(polyShape)
|
||||
|
||||
return result
|
||||
|
||||
def keyPressed():
|
||||
if key == "p":
|
||||
saveFrame("###.png")
|
||||
if key == " ":
|
||||
global pshape_result
|
||||
csg_result = calculate_stuff()
|
||||
pshape_result = CSGToPShape(csg_result, 45)
|
||||
|
||||
def settings():
|
||||
from os import path
|
||||
global SKETCH_NAME
|
||||
SKETCH_NAME = path.basename(sketchPath())
|
||||
OUTPUT = ".png"
|
||||
println(
|
||||
"""
|
||||

|
||||
|
||||
[{0}](https://github.com/villares/sketch-a-day/tree/master/{2}/{0}) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
|
||||
""".format(SKETCH_NAME, OUTPUT, year())
|
||||
)
|
||||