continous paint/airbrush effect?

mattl's picture

Hi, I need to build a basic paint tool for a touchscreen, I'm wondering if anyone has any idea on how to program a smooth continous paint or airbrush effect, as a normal paint program like photoshop or sketchbook would do. Its simple enough using accumulator or other technique to paint to the screen, but with fast movements rather than getting a continuous brush stroke, you get staggered swatches.. I need it to be continuous.. I can draw lines between using GL line plugin, but its not the effect Im after.. Any ideas? Thx!

franz's picture
Re: continous paint/airbrush effect?

openGL polygons ? check out MouseRibbon.qtz to generate polys, then apply a brush texture.

psonice's picture
Re: continous paint/airbrush effect?

I've written a paint tool using QC before, it was fairly tough. Here's (roughly) how I did it:

  • Yes, use an accumulator. This is the easiest way to accumulate strokes, and it's easy to let strokes interact with each other.

  • The hard part is drawing the lines. Drawing a circle each frame doesn't work for the reason you suggested. My solution was to use core image, and feed it the start and end point of the line. Inside the filter I'd calculate distance from the line, and determine wether it's in or out of the brush that way. Maybe the polygon technique could work here, but I can see a lot of issues unless you want square brush strokes.

  • Once you've got your line, you add it to the canvas with the accumulator.

  • If you're using a soft brush, you can calculate the transparency based on distance in the filter (linear looks crap unfortunately so it's not straightforward) or you can blue the brush image before sending it to the accumulator.

  • With a soft brush or transparency, you have a problem. A brush stroke is made of many short lines. The ends of the lines overlap each other, and because they're transparent, the overlap is visible. I.e. you get a smooth stroke, but with lumps in it.

  • My fix for the lumps: store the previous line image, and subtract it from the current one. This removes the overlap.

There's a ton you can do with this - I had a whole bunch of brush shapes and sizes, full transparency + softness control, even blur/sharpen/colourise/erase brushes. But it gets pretty.. complicated ;)

Good luck!

Abhi's picture
Re: continous paint/airbrush effect?

Hello psonice

Ive posted a job here - http://kineme.net/forum/Jobs/IRSpraycanbasedGraffitiSketchPaintcomp

Let me know if you would be interested