#### Richard Horne

##### Member

Hi guys,

So I have a simple path roughly in the shape of a circle and I want to repeat a texture around the entire length of the path. I'm using primitives because ultimately the path I'm going to apply this to is massive and this is the most efficient way so far to achieve this.

Using a simple for loop I've managed to create a primitive made up of lots of alternating triangles but I need the repeating pattern to properly rotate and form around the the path. If you see the image below it will make a lot more sense.

The issue occurs at 3 o'clock and at 9 o'clock where the primitive sort of twists back on itself.

If I extend down vertically then the effect is even more dramatic and you basically just see a thin slither.

Below is the code I've come up with so far but I'm struggling to get the triangles to angle right. I'm sure length_dirx and y is along the right lines but so far I'm drawing a blank.

So I have a simple path roughly in the shape of a circle and I want to repeat a texture around the entire length of the path. I'm using primitives because ultimately the path I'm going to apply this to is massive and this is the most efficient way so far to achieve this.

Using a simple for loop I've managed to create a primitive made up of lots of alternating triangles but I need the repeating pattern to properly rotate and form around the the path. If you see the image below it will make a lot more sense.

The issue occurs at 3 o'clock and at 9 o'clock where the primitive sort of twists back on itself.

If I extend down vertically then the effect is even more dramatic and you basically just see a thin slither.

Below is the code I've come up with so far but I'm struggling to get the triangles to angle right. I'm sure length_dirx and y is along the right lines but so far I'm drawing a blank.

Code:

```
//Create event
even_check = -1;
triangle_size = 10;
xpos = 0;
ypos = 0;
```

Code:

```
//Draw event
//Set up our primitive, enable texture repeat and define the texture we will use
texture_set_repeat(true);
var tex = sprite_get_texture(sprite3,0);
draw_primitive_begin_texture(pr_trianglestrip,tex);
//Loop through from 0 to 1 (1-100% of the path) in small increments
for (i= 0; i<= 1; i+= 0.001)
{
//We alternate even_check between -1 and 0 to swap the orientation of the
//triangles we are drawing each iteration
//
// /\/\/\/\/\/\/\/\/
//
//We get the xpos and ypos from just slightly in front of our current x and y pos
//so we can determine a close-enough approximation of the current angle
xpos_next = path_get_x(path1, i+0.001);
ypos_next = path_get_y(path1, i+0.001);
//Get the current angle
current_angle = point_direction(xpos, ypos, xpos_next, ypos_next);
if (even_check == -1)
{
//To draw an upward pointing triangle we increment xpos by triangle size
//And decrement ypos by the triangle size
xpos = path_get_x(path1, i) + triangle_size;
ypos = path_get_y(path1, i) - triangle_size;
xpos = xpos + lengthdir_x(triangle_size,current_angle);
ypos = ypos + lengthdir_y(triangle_size,current_angle);
draw_vertex_texture(xpos, ypos,0,0);
even_check = 0;
}
else
{
//To draw a downward pointing triangle we increment xpos and ypos by triangle size
xpos = path_get_x(path1, i) + triangle_size;
ypos = path_get_y(path1, i) + triangle_size;
xpos = xpos + lengthdir_x(triangle_size,current_angle);
ypos = ypos + lengthdir_y(triangle_size,current_angle);
draw_vertex_texture(xpos, ypos,0,1);
even_check = -1;
}
}
draw_primitive_end();
```

Last edited: