Skip to content

Commit

Permalink
Replace example with Sierpinski pyramid
Browse files Browse the repository at this point in the history
 - Changed the included config.txt to show a multi-colored Sierpinski
   pyramid.

 - Increased the model's scale, and changed the camera some.
  • Loading branch information
Nathan O authored and Nathan O committed Feb 17, 2022
1 parent 83947bf commit 585c1cd
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
```
Expand Down
117 changes: 91 additions & 26 deletions config.txt
Original file line number Diff line number Diff line change
@@ -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

6 changes: 3 additions & 3 deletions l_system_3d.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Binary file modified sample_screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion turtle_3d.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions turtle_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include <stdint.h>
#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.
Expand Down

0 comments on commit 585c1cd

Please sign in to comment.