Coloring program using alpha less than 1.0
Monkey Forums/Monkey Beginners/Coloring program using alpha less than 1.0
| ||
I'm working on a simple coloring game. Coloring using an alpha of 1.0 using NoOdle's DrawThickLine function works perfectly, but if I want to use alpha of less than 1.0 I run into problems with the polygons (and end ellipses) overlapping. I want to have a single stroke of the finger/mouse (until finger or mouse is up) paint a uniform color. I have had several ideas for achieving this (such as tesselating polygons, one large polygon, writing to an array with alpha of 1 and then changing to alpha less than 1), but nothing I can get working. Any ideas would be very much appreciated! |
| ||
I think the best approach is probably to make all the individual polygon segments into one super-polygon, and draw that. You can fake the end-ellipses with a set of polygon points too. (Not sure what you get when super-polygon overlaps itself (user is scribbling) but it might solve part of the problem. You could always detect scribbling and do it another way.) |
| ||
Thanks Gerry, I have played around with large polygons, but it gets horribly complex very quickly. I think I have figured out a better way - in pseudocode: Clear the screen. SetColor to black and SetAlpha to 1.0. Use NoOdle's DrawThickLine function, with the end ellipses set to True, to draw the required lines (they will be black with Alpha = 1.0). ReadPixels into a screen-sized integer array (I prefer a 1-dimensional array), Array1 Set up another screen-sized Boolean array, Array2 (values are either True or False) Use a For Next loop to read Array1 and if the value is equivalent to black, set the equivalent value in Array2 to equal True, if not False. Clear screen again and DrawImage your main image. SetColor and SetAlpha to required values. Use a nested For Next loop to read Array2 (x = 1 to width y = 1 to height) and for each value that is True, DrawPoint(x,y) Keep adding to Array2 until the brush stroke is ended i.e. MouseDown() = False. On the last time around draw each point and set its value in the Boolean array back to False ready for the next brush stroke. ReadPixels into another screen-sized array and WritePixels into your main image. This saves each brushstroke to the image you are coloring Using a Boolean array to store the points that have been painted for each stroke of the brush is much quicker and uses fewer resources than using an array with the full color data for each pixel. So far this seems to work OK. |
| ||
Well, if ReadPixels and WritePixels are fast enough, that should be fine. (I understand some changes have been made recently so they are faster.) Making a big polygon from a series of pen positions isn't really that mathematically complicated, though. |
| ||
Writing to a texture allows for even more: eg "stamps" (have done that in a simple blitzmax-painter for the youngest of a friend). The only problem is speed and memory consumption. bye Ron |
| ||
Gerry Quinn, Reading pixels was getting a bit slow, so I modified the code to make the DrawThickLine function generate the points inside the brush stroke, instead of drawing them, then I put them straight into the Boolean array. The math scared me off, but maybe I should look at making a large polygon again. I just figured out how to generate the points within a rectangle, so I should be able to get my head around big polygons :-) It depends if this method is too slow. Ron, Thanks for the tip. I haven't looked at textures yet, but I will. |