@@ -101,8 +101,8 @@ render_spiral(spiral_t spiral) {
101101 };
102102 // initialise output bitmap - image dimensions are twice the size + 1
103103 bitmap_t output = {
104- .width = ((bottom_right .x + 1 ) * 2 ) + 1 ,
105- .height = ((bottom_right .y + 1 ) * 2 ) + 1 ,
104+ .width = ((bottom_right .x + 1 ) * 2 ) + 1 ,
105+ .height = ((bottom_right .y + 1 ) * 2 ) + 1 ,
106106 };
107107 // allocate dynamic memory - 2D array of bools
108108 output .pixels = malloc (output .width * sizeof (bool * ));
@@ -119,17 +119,20 @@ render_spiral(spiral_t spiral) {
119119 // get current direction
120120 vector_t direction = VECTOR_DIRECTIONS [spiral .lines [i ].direction ];
121121 // make as many jumps in this direction as this lines length
122- for (uint64_t j = 0 ; j < spiral .lines [i ].length * 2 ; j ++ ) {
122+ for (uint64_t j = 0 ; j < ( spiral .lines [i ].length * 2 ) + 1 ; j ++ ) {
123123 // get output co-ords
124- int64_t x_pos = current .x + (normalisation_vector .x * 2 ) + 1 ;
125- int64_t y_pos = current .y + (normalisation_vector .y * 2 ) + 1 ;
124+ int64_t x_pos = current .x + (normalisation_vector .x * 2 ) + 1 ;
125+ int64_t y_pos = current .y + (normalisation_vector .y * 2 ) + 1 ;
126126 // skip the second pixel of the first line
127127 if (!((i == 0 ) && (j == 1 ))) {
128128 // flip the y-axis otherwise they appear vertically mirrored
129- output .pixels [x_pos ][output .height - 1 - y_pos ] = true;
129+ output .pixels [x_pos ][output .height - 1 - y_pos ] = true;
130+ }
131+ if (j != (spiral .lines [i ].length * 2 )) {
132+ // if we're not on the last line, advance the marker along
133+ current .x += direction .x ;
134+ current .y += direction .y ;
130135 }
131- current .x += direction .x ;
132- current .y += direction .y ;
133136 }
134137 }
135138 return output ;
0 commit comments