Some mixing math
Boudewijn Rempt
boud at valdyas.org
Fri Jun 15 21:19:05 CEST 2007
On Friday 15 June 2007, Emanuele Tamponi wrote:
> http://principe.homelinux.net/email.txt
>
> The text of the email is in the previous link. Sorry but it is detected
> as spam!
Let's see whether I fare better :-)
---------------
Hello,
since the dissertations are poor of mathematical details, I've to
"invent" the equations that describe the behavior of the painterly paintops.
I've had some thoughts these days and I came to this simple set of
equations... I'd like to know if you agree with the model. Suggestions
are more than welcome! :) I know that the model is *really* simple, and
perhaps not realistic, but I don't intend it to be the final one!
Variables:
W_tot = the total amount of water in the brush (liters)
I_tot = the total amount of pigment in the brush (liters)
p(0) = the pressure given by the event
th, ph = the angles of the pen
1) We calculate the "point of maximal pressure", that is, when the
artist presses the brush over the canvas, the point where the maximal
pressure is exercised is not the same of p(0). It depends on the angles,
and on the type of the brush: let's call t_x the coefficient that
describes this brush property, and (x_e, y_e) the coords of the event,
and then we have:
x0 = x_p + t_x * cos(ph)
y0 = y_p + t_x * cos(th)
2) We calculate the "radius of the affected area", that is, depending on
pressure and on a brush property (t_r), the brush will affect a
different circular area, centered on the point of maximal pressure:
R = t_r * p(0) now we have the area where we will operate: x,y in
the circle of radius R, centered in (x0, y0)
3) Now we have to calculate the pressure on each (x, y) point of the
area. It's a Gaussian:
p(x, y) = p(0) * exp(-rho^2) rho^2 = (x - x0)^2 + (y - y0)^2
4) We can consider the friction, that's proportional with the square of
the the pressure. Let's call t_c the coefficient that describes the
properties of the canvas about friction, the total force is:
f(x, y) = p(x, y) + t_c*[p(x,y)]^2 (remember that p is in the
interval [0, 1])
5) The amount of water per pixel is proportional to the total force: we
can assume that in the brush the amount of water is the same in each point:
w(x, y) = [W_tot / (pi*R^2)] * f(x, y)
5b) After we set the amount of dropped water, we've to recalculate
W_tot: in my opinion, is more realistic that W_tot doesn't reduce of
exactly the amount of dropped water, but a bit less: this simulates the
fact that in reality the brush never dries up completely:
W_tot = W_tot - (W_dropped) / t_w
t_w depends on the brush properties.
6) The amount of pigment dropped is calculated in the same way:
i(x, y) = [I_tot / (pi*R^2)] * f(x, y)
I_tot = I_tot - (I_dropped) / t_i
t_i depends on the brush properties.
7) Here we are: now we know how much water, pigment and pressure we have
on each pixel! Now, for each pixel, we've to decide if:
7-1) The color already in the pixel is compatible with the new one
7-2) The colors are not compatible
Compatibility depends on mixability, viscosity, and wetness of the
previous color.
In the first case, we sum the amounts of water and pigment, and we sign
the cell in order to calculate the resulting color when it's the time.
In the second case, we sum the amounts of water and pigment (since
they're in the canvas cell, anyway!) but we overwrite the old color with
the new one.
8) Now we have cells with updated amounts of water and pigment: but
probably they are more than filled of pigment and water, so dripping
will occur! (btw: it's not the case of the mixer canvas, where we will
not have dripping, at least in my opinion).
We do dripping this way:
- Start from the (x0,y0) point
- Consider the 8 neighbors and drop water and pigment on them. I don't
say "drop equally" because we have to consider 2 things: gravity
direction, and movement direction. The cells that are in the direction
of either gravity or movement will receive more pigment and water. Sign
them as "visited".
- Do the mixing in the (x0, y0) point and sign it as "visited & mixed".
- Pass to each neighbor and drop the water and pigment on the neighbor
that are still not "visited". Do the color mix and sign it as "visited
and mixed".
- Do this recursively and stop when we come to the end of the affected area.
(this domino effect simulates the fact that very wet paint has more
paint in the borders).
Sorry for the long post, I hope in your feedback :) !
Thanks,
Emanuele
--
Boudewijn Rempt
http://www.valdyas.org/fading/index.cgi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://mail.kde.org/pipermail/kimageshop/attachments/20070615/ecde9fcd/attachment.pgp
More information about the kimageshop
mailing list