3D Pyramid with Textures #786
vsquared
started this conversation in
Show and tell
Replies: 1 comment
|
Such a nice example @vsquared! I converted it to "module mode" so I could tweak it using the py5 Live Coding feature # py5 module mode sketch
# The images can be on a 'data' folder beside the sketch source file or image files directly beside sketch.
import py5
def pyramid(s):
py5.texture_mode(py5.NORMAL)
with py5.begin_shape(py5.TRIANGLES):
py5.texture(imgSuits)
py5.vertices(( # (x, y, z, u, v)
# Front
(-s, -s, -s, -0.05, 1.0),
(s, -s, -s, 0.30, 1.0),
(0, 0, s, 0.125, 0.0),
# Right
(-s, s, -s, 0.20, 1.0),
(-s, -s, -s, 0.55, 1.0),
(0, 0, s, 0.375, 0.0),
# Back
(s, s, -s, 0.45, 1.0),
(-s, s, -s, 0.8, 1.0),
(0, 0, s, 0.625, 0.0),
# Left
(s, -s, -s, 0.70, 1.0),
(s, s, -s, 1.05, 1.0),
(0, 0, s, 0.885, 0.0)
))
# Square Base
with py5.begin_shape(py5.QUADS):
py5.texture(imgJoker)
py5.vertices((
(-s, -s, -s, 1, 0),
(s, -s, -s, 0, 0),
(s, s, -s, 0, 1),
(-s, s, -s, 1, 1)
))
def setup():
global imgSuits
global imgJoker
py5.size(800, 800, py5.P3D)
py5.stroke_weight(4.0)
imgSuits = py5.load_image("suits.png")
imgJoker = py5.load_image("joker.png")
def draw():
py5.background(0)
py5.translate(py5.width / 2, py5.height / 2)
py5.rotate_x(py5.remap(
py5.mouse_y,
0, py5.height,
py5.TWO_PI, -py5.TWO_PI
))
py5.rotate_y(py5.remap(
py5.mouse_x,
0, py5.width,
-py5.TWO_PI, py5.TWO_PI
))
pyramid(150)
py5.run_sketch()
|
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I recently published this on github: https://github.com/vsquared/Pyramid_3D and was impressed how easily I could port it to py5.
Source code:
Images:


suits.png
joker.png
All reactions