Possible to recolor points in heightmap this way?

edited November 2013 in How To...

I have a fractal terrain generator I wrote and it stores the values in a 2D int array. It displays the wire frame mesh of this on screen and it looks cool but is there a way to recolor these points without changing the way they are already drawn? sort of like using the pixels array to change color based on position but where it colors them by their position in 3d space. or do i have to change the stroke color before i put the points down. is there any way to make it so when drawing a line it colors it differently in different spot dependent on the position of the point on the line? And finally any ideas on a way to change color on a wire frame height-map based on depth. Sorry if this is confusing ill try to explain if you don't understand what i'm asking.


  • edited November 2013

    how are you drawing the lines?

    if you are using line() then you can only set the colour of the whole line.

    if you are using beginShape(LINES); then i think you can change the colour of each vertex so the line can start blue and end up green, or whatever.

    um, i should test this... (edit: no it doesn't)

  • I am just using lines for the time being. I know you can make gradients with 2d shapes by setting the color at each vertex but I dont know much about this. The harder part would be changing the color based on its position in 3d space.

  • If you are creating line segments joining every two vertices using stroke should work.

    For having more control you could use PShape for creating the grid and apply a texture, so you can draw directly to the texture's pixels. Using a height map you can assign each texture pixel a color as you iterate over the height map pixels,thus making it dependant on position and height.

  • Can you perhaps show me how to do this?

  • In this tutorial by Amnon Owed you can find examples on how to create a rectangular grid with a PShape and how to apply textures. He also uses shaders, but you can leave that for later on

Sign In or Register to comment.