# Texture on hexagon

**URL:** <https://discourse.processing.org/t/texture-on-hexagon/28534>\
**Category:** Coding Questions\
**Created:** [March 14, 2021, 2:57pm UTC](https://discourse.processing.org/t/texture-on-hexagon/28534 "2021-03-14T14:57:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Theodor](https://avatars.discourse-cdn.com/v4/letter/t/b5a626/32.png) [@Theodor](https://discourse.processing.org/u/Theodor)\
**Post date:** [March 14, 2021, 2:57pm UTC](https://discourse.processing.org/t/texture-on-hexagon/28534/1 "2021-03-14T14:57:26Z")

</div>

Hallo I am new in this forum and just started with processing. I would like to paint my 3d hexagon with an image (texture). How can I place a texture on a hexagon? The jpg it self is a rectangular format and I would like to show only the painted hexagon area of the jpg on the surface of the 3D shape. (maybe this is not the best way to channge the layout, surface of the 3d shape but comes into my mind watching the processing tutorials. I would like to change later on the picture based on user interface)  
Thank you for any help.  
The “3D hexagon”:  
beginShape();  
for(int i=0;i\<6;i++){  
float angle = i \* 2 \* PI / 6;  
vertex(0 + 300_cos(angle),0 + 300_sin(angle), -80);  
} endShape(CLOSE);  
for(int i=0;i\<6;i++){  
beginShape();  
float angle = i \* 2 \* PI / 6;  
vertex(0 + 300_cos(angle),0 + 300_sin(angle), -80);  
vertex(0 + 300_cos(angle),0 + 300_sin(angle), 80);  
angle = (i+1) \* 2 \* PI / 6;  
vertex(0 + 300_cos(angle),0 + 300_sin(angle), 80);  
vertex(0 + 300_cos(angle),0 + 300_sin(angle), -80);  
endShape(CLOSE);  
}  
beginShape();  
for(int i=0;i\<6;i++){  
float angle = i \* 2 \* PI / 6;  
vertex(0 + 300_cos(angle),0 + 300_sin(angle), 80);  
} endShape(CLOSE);–\>

---

<div class="post-metadata">

**Author:** ![ReyzArtz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/reyzartz/32/11750_2.png) [@ReyzArtz](https://discourse.processing.org/u/ReyzArtz)\
**Post date:** [March 15, 2021, 5:16am UTC](https://discourse.processing.org/t/texture-on-hexagon/28534/2 "2021-03-15T05:16:22Z")

</div>

Hey Theodar u can try to use `textureMode()` in processing to map an image around the surface check out this [reference](https://processing.org/reference/textureMode_.html)` if u want to know more

---

<div class="post-metadata">

**Author:** ![matheplica](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/matheplica/32/21035_2.png) [@matheplica](https://discourse.processing.org/u/matheplica)\
**Post date:** [March 15, 2021, 8:29am UTC](https://discourse.processing.org/t/texture-on-hexagon/28534/3 "2021-03-15T08:29:24Z")

</div>

I did something similar in the past.  
I don’t think texture works on hexagon shape.  
You have maybe to split your hexagon in 6 triangles, cut your texture. And apply it with something like :  
`textureMode(NORMAL); texture(img); vertex(10, 20, 0, 0.5);`

---

<div class="post-metadata">

**Author:** ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)\
**Post date:** [March 15, 2021, 11:39am UTC](https://discourse.processing.org/t/texture-on-hexagon/28534/4 "2021-03-15T11:39:59Z")

</div>

just to note that `vertex` can take up to 5 arguments, and the last 2 are for the uv coordinates on the texture:  
[https://processing.org/reference/vertex\_.html](https://processing.org/reference/vertex_.html)

Since there’s no complete code I’m lazy to try it on my own (and please use `</>` button to format the code), but as @matheplica says I’m not sure if the tessellation works in this case (maybe it does). If the mapped image is distorted, you can start the `beginShape` in `TRIANGLE_FAN` mode starting with the center and this would generate nice triangles I suppose:  
[https://processing.org/reference/beginShape\_.html](https://processing.org/reference/beginShape_.html)
