[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice
Subject:    Re: [KIll.] Linear Gradients with arbitray angles
From:       claus wilke <claus.wilke () gmx ! net>
Date:       1999-12-20 20:12:06
[Download RAW message or body]


> I have a question concerning gradients. What is the best methode to create
> linear gradients with arbitrary angles of the shading? I tried to create
> something based on the Gradiant.cc code in killustrator (which supported only
> linear gradients with the angles 0° and 90°). My code works somehow, but not
> that well (especially bad are values closer to the tan 90° singularity that is
> [45°-]89°).
> 
> If somebody has a nice workable idea, please share it.

If I get your question right, the problem is that you are rasterizing an area,
and for every pixel on that area you have to calculate the right pixel color,
right? So you have to calculate the distance to the line that is orthogonal to
the line spanned by the beginning and the end-point of the gradient.

My proposal would be the following: think in the gradient coordinate system.
Let the beginnig of the gradient be at x0, y0, and let the angle be -alpha.
Then, rotate the pixel at x,y into the gradient coordinate system via
  x' = (x-x0) cos alpha + (y-y0) sin alpha
  y' = - (x-x0) sin alpha + (y-y0) cos alpha

Then calculate a linear gradient according to the value x' or y', depending on
the axis according to which you measure the angle alpha.

I cannot see how there could be any problems with singularities in this
approach, and it should work with arbitrary angles.

I hope this works,
Best,
  Claus


-- 
Claus Wilke
claus.wilke@gmx.net

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic