Adding vector shapes within a mesh

Adding an image texture to a mesh is straight forward in Codea. But what if I wanted to add a procedural shape to a mesh? I’m thinking about, for instance, adding a small blue triangle of random size inside a bigger, red, square, and that small triangle would behave like an image texture would, namely rotate as the square rotates.

Is there any efficient way to achieve this? Or is it just silly?

@Rodolphe - simplest is two meshes…otherwise if you have one mesh, you need to keep altering the vertex positions of the triangle

ok, that’s what I thought… I’ll try experimenting with it! Thanks!

Maybe I am misreading the question, but if they rotate together couldn’t you just put them in one image and rotate that image?

I would have to generate an image out of a random-sized triangle, somehow put it in an image, and then use that image as a texture?

@Rodolphe, something like this?

function setup()
    local m = mesh()
    m.vertices = { vec2(0,0), vec2(30, 0), vec2(15, 30) }
    img = image(200, 100) setContext(img)
    fill(255, 0, 0) noStroke()
    rect(0, 0, 200, 100)
    pushMatrix() translate(100 - 15, 50 - 15)
    m:draw() popMatrix() setContext()
    angle = 0

function draw()
    translate(WIDTH / 2, HEIGHT / 2)
    angle = angle + 1

Ooooooh, setContext(), of course… Never used it before. Thanks a lot for this @JakAttak!!!

@Rodolphe, no problem.