Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Adding vector shapes within a mesh

edited July 2014 in Questions Posts: 277

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?



  • IgnatzIgnatz Mod
    Posts: 5,396

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

  • Posts: 277

    ok, that's what I thought... I'll try experimenting with it! Thanks!

  • Posts: 2,043

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

  • Posts: 277

    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?

  • Posts: 2,043

    @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
  • Posts: 277

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

  • Posts: 2,043

    @Rodolphe, no problem.

Sign In or Register to comment.