kopia lustrzana https://github.com/villares/sketch-a-day
Day 3!
rodzic
f5ed37779f
commit
1fa9ef446f
|
|
@ -1,2 +1,3 @@
|
|||
|
||||
.DS_Store
|
||||
*.png
|
||||
|
|
|
|||
|
|
@ -8,3 +8,4 @@ Hi! I'm [Alexandre Villares](https://abav.lugaralgum.com), let's see if I can ma
|
|||
|
||||
002: [s180102](/s180102) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)] Many Stars 3D - [YouTube](https://www.youtube.com/watch?v=QmsthW60iBY)
|
||||
|
||||
003: [s180103](/s180103) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)] Tetrahedrons
|
||||
|
|
|
|||
|
|
@ -0,0 +1,65 @@
|
|||
""" Tetrahedrons """
|
||||
|
||||
T_LIST, ROT_X, ROT_Y = [], 0, 0
|
||||
Z_MIN, Z_MAX = -800, 0
|
||||
|
||||
def setup():
|
||||
size(800, 800, P3D)
|
||||
for _ in range(100):
|
||||
x, y, z = random(0, width), random(0, height), random(Z_MIN, Z_MAX)
|
||||
T_LIST.append(Tetrahedron(x, y, z, 75)) # 75 is the size
|
||||
|
||||
def draw():
|
||||
global ROT_X, ROT_Y
|
||||
ROT_X += 0.005
|
||||
ROT_Y += 0.01
|
||||
background(0)
|
||||
strokeWeight(7)
|
||||
for tetra in T_LIST:
|
||||
# Draws only edges, or only faces if mousePressed
|
||||
tetra.plot(ROT_X, ROT_Y, mousePressed)
|
||||
|
||||
# if frameCount < 100: saveFrame("t-##.png") # uncomment to save frames
|
||||
|
||||
class Tetrahedron():
|
||||
|
||||
""" Tetrahedron """
|
||||
|
||||
def __init__(self, x, y, z, radius):
|
||||
self.x, self.y, self.z = x, y, z
|
||||
self.radius = radius
|
||||
self.points = [PVector()] * 4
|
||||
# calculate geometry
|
||||
a = radius * 2 / 3.
|
||||
self.points[0] = PVector(+a, +a, +a) # vertex 1
|
||||
self.points[1] = PVector(-a, -a, +a) # vertex 2
|
||||
self.points[2] = PVector(-a, +a, -a) # vertex 3
|
||||
self.points[3] = PVector(+a, -a, -a) # vertex 4
|
||||
|
||||
# draws tetrahedron
|
||||
def plot(self, rx=0, ry=0, showFaces=False):
|
||||
c = color(map(self.x, 0, width, 255, 0),
|
||||
map(self.y, 0, height, 255, 0),
|
||||
map(self.z, Z_MIN, Z_MAX, 0, 255), 100)
|
||||
if showFaces:
|
||||
noStroke()
|
||||
fill(c)
|
||||
else:
|
||||
noFill()
|
||||
stroke(c)
|
||||
with pushMatrix():
|
||||
translate(self.x, self.y, self.z)
|
||||
rotateX(ry)
|
||||
rotateY(rx)
|
||||
beginShape(TRIANGLE_STRIP)
|
||||
p = self.points
|
||||
vertex(p[0].x, p[0].y, p[0].z) # vertex 1
|
||||
vertex(p[1].x, p[1].y, p[1].z) # vertex 2
|
||||
vertex(p[2].x, p[2].y, p[2].z) # vertex 3
|
||||
vertex(p[3].x, p[3].y, p[3].z) # vertex 4
|
||||
vertex(p[0].x, p[0].y, p[0].z) # vertex 1
|
||||
vertex(p[1].x, p[1].y, p[1].z) # vertex 2
|
||||
vertex(p[3].x, p[3].y, p[3].z) # vertex 4
|
||||
vertex(p[2].x, p[2].y, p[2].z) # vertex 3
|
||||
vertex(p[1].x, p[1].y, p[1].z) # vertex 2
|
||||
endShape(CLOSE)
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
""" Tetrahedrons + PeasyCam"""
|
||||
|
||||
add_library('peasycam')
|
||||
|
||||
T_LIST, ROT_X, ROT_Y = [], 0, 0
|
||||
Z_MIN, Z_MAX = -800, 0
|
||||
|
||||
def setup():
|
||||
cam = PeasyCam(this, 100)
|
||||
hint(DISABLE_DEPTH_TEST)
|
||||
size(800, 800, P3D)
|
||||
for _ in range(100):
|
||||
x, y, z = random(0, width), random(0, height), random(Z_MIN, Z_MAX)
|
||||
T_LIST.append(Tetrahedron(x, y, z, 75)) # 75 is the size
|
||||
|
||||
def draw():
|
||||
global ROT_X, ROT_Y
|
||||
ROT_X += 0.005
|
||||
ROT_Y += 0.01
|
||||
background(0)
|
||||
strokeWeight(7)
|
||||
for tetra in T_LIST:
|
||||
# Draws only edges, or only faces if a key is pressed
|
||||
tetra.plot(ROT_X, ROT_Y, keyPressed)
|
||||
|
||||
class Tetrahedron():
|
||||
|
||||
""" Tetrahedron """
|
||||
|
||||
def __init__(self, x, y, z, radius):
|
||||
self.x, self.y, self.z = x, y, z
|
||||
self.radius = radius
|
||||
self.points = [PVector()] * 4
|
||||
# calculate geometry
|
||||
a = radius * 2 / 3.
|
||||
self.points[0] = PVector(+a, +a, +a) # vertex 1
|
||||
self.points[1] = PVector(-a, -a, +a) # vertex 2
|
||||
self.points[2] = PVector(-a, +a, -a) # vertex 3
|
||||
self.points[3] = PVector(+a, -a, -a) # vertex 4
|
||||
|
||||
# draws tetrahedron
|
||||
def plot(self, rx=0, ry=0, showFaces=False):
|
||||
c = color(map(self.x, 0, width, 255, 0),
|
||||
map(self.y, 0, height, 255, 0),
|
||||
map(self.z, Z_MIN, Z_MAX, 0, 255), 100)
|
||||
if showFaces:
|
||||
noStroke()
|
||||
fill(c)
|
||||
else:
|
||||
noFill()
|
||||
stroke(c)
|
||||
with pushMatrix():
|
||||
translate(self.x, self.y, self.z)
|
||||
rotateX(ry)
|
||||
rotateY(rx)
|
||||
beginShape(TRIANGLE_STRIP)
|
||||
p = self.points
|
||||
vertex(p[0].x, p[0].y, p[0].z) # vertex 1
|
||||
vertex(p[1].x, p[1].y, p[1].z) # vertex 2
|
||||
vertex(p[2].x, p[2].y, p[2].z) # vertex 3
|
||||
vertex(p[3].x, p[3].y, p[3].z) # vertex 4
|
||||
vertex(p[0].x, p[0].y, p[0].z) # vertex 1
|
||||
vertex(p[1].x, p[1].y, p[1].z) # vertex 2
|
||||
vertex(p[3].x, p[3].y, p[3].z) # vertex 4
|
||||
vertex(p[2].x, p[2].y, p[2].z) # vertex 3
|
||||
vertex(p[1].x, p[1].y, p[1].z) # vertex 2
|
||||
endShape(CLOSE)
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
mode=Python
|
||||
mode.id=jycessing.mode.PythonMode
|
||||
Ładowanie…
Reference in New Issue