diff --git a/README.md b/README.md index 4ed73f2..b3260bb 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ encountering each character. (The `actions` line must occur exactly once in the config.) If you want a longer example, the default "config.txt" contains instructions -for drawing a pair of connected dragon curves. A simpler, single, dragon-curve +for drawing a multi-colored Sierpinski pyramid. A simpler, single, dragon-curve example can be obtained by replacing the contents of "config.txt" with the following lines: ``` diff --git a/config.txt b/config.txt index 73fd201..b04a355 100644 --- a/config.txt +++ b/config.txt @@ -1,40 +1,105 @@ -# Draw two connected dragon curves. -# P = set the initial color to purple. -# F = draw a dragon curve -# R = rotate and change color -init PFRF +init CP -F F+G -G F-G +# The () around the pyramids make it easier for me to keep track of the +# positions when moving between the 5 pyramids. + +# Replace one square pyramid with 5 pyramids, always ending at the bottom left +# corner facing right. +P ((CPN1PN-N2PN-N3P)UND4P) +N NN actions -P -# Set color to purple. +# C, 1, 2, 3, and 4 all just set colors. You can remove them from the +# replacement string to simplify it if you want. +C set_color_r 0.7 -set_color_g 0.2 +set_color_g 0.3 set_color_b 1.0 -B -set_turtle_B +1 +set_color_r 1.0 +set_color_g 0.2 +set_color_b 0.2 -F -move_forward 1.0 +2 +set_color_r 0.2 +set_color_g 1.0 +set_color_b 0.2 -G -move_forward 1.0 +3 +set_color_r 0.2 +set_color_g 0.2 +set_color_b 1.0 + +4 +set_color_r 1.0 +set_color_g 1.0 +set_color_b 1.0 - -rotate -90.0 +rotate 90 -R -pitch 90.0 -# Set color to a bright-ish green. -set_color_r 0.2 -set_color_g 0.9 -set_color_b 0.2 +( +push_position 0.0 + +) +pop_position 0.0 + +N +move_forward_nodraw 1.0 + +# Face "upwards" to move to the upper pyramid. +U +rotate 45 +pitch 45 + +# Undo the "upwards rotation in preparation for drawing the upper pyramid. +D +pitch -45 +rotate -45 + + +# P = draw a single square pyramid. Starts at the bottom left corner facing +# right, and ending at the bottom right corner, facing right. +P + +# Keep track of our start position, we'll return here at the end. +push_position 0 + +# Bottom left -> bottom right, up edge from bottom right +move_forward 1 +push_position 0 +rotate 135 +pitch 45 +move_forward 1 +pop_position 0 + +# Bottom right -> up right, up edge from up right +rotate 90 +move_forward 1 +push_position 0 +rotate 135 +pitch 45 +move_forward 1 +pop_position 0 + +# up right -> up left, up edge from up left +rotate 90 +move_forward 1 +push_position 0 +rotate 135 +pitch 45 +move_forward 1 +pop_position 0 + +# up left -> bottom left, up edge from bottom left +rotate 90 +move_forward 1 +rotate 135 +pitch 45 +move_forward 1 -+ -# Comments can go anywhere, so long as the '#' is at the start of the line. -rotate 90.0 +# Return to bottom left, facing right. +pop_position 0 diff --git a/l_system_3d.c b/l_system_3d.c index 083737b..dad46d8 100644 --- a/l_system_3d.c +++ b/l_system_3d.c @@ -267,9 +267,9 @@ static void UpdateCamera(ApplicationState *s) { glm_vec3_zero(up); up[1] = 1.0; tmp = glfwGetTime() / 4.0; - position[0] = sin(tmp) * 4.0; - position[1] = 3.0; - position[2] = cos(tmp) * 4.0; + position[0] = sin(tmp) * 5.0; + position[1] = 2.0; + position[2] = cos(tmp) * 5.0; glm_lookat(position, target, up, s->shared_uniforms.view); glm_vec4(position, 0, s->shared_uniforms.camera_position); } diff --git a/sample_screenshot.png b/sample_screenshot.png index fc142cf..61dd4b3 100644 Binary files a/sample_screenshot.png and b/sample_screenshot.png differ diff --git a/turtle_3d.c b/turtle_3d.c index bca14cd..0e51410 100644 --- a/turtle_3d.c +++ b/turtle_3d.c @@ -123,7 +123,7 @@ int SetTransformInfo(Turtle3D *t, mat4 model, mat3 normal, vec3 loc_offset) { max_axis = Max3(dx, dy, dz); glm_mat4_identity(model); if (max_axis > 0) { - glm_scale_uni(model, 2.0 / max_axis); + glm_scale_uni(model, MESH_CUBE_SIZE / max_axis); } ModelToNormalMatrix(model, normal); // TODO (eventually): If I get less stupid, combine the loc_offset diff --git a/turtle_3d.h b/turtle_3d.h index 21edddd..a91da75 100644 --- a/turtle_3d.h +++ b/turtle_3d.h @@ -4,6 +4,10 @@ #include #include "l_system_mesh.h" +// The length per edge of the centered cube that the turtle's resulting mesh +// is scaled to fit into. +#define MESH_CUBE_SIZE (4.0) + // Holds the turtle's position and orientation information. typedef struct { // The turtle's current location.