Page 1 of 1

Fill polygon gradient color

Posted: Mon Jun 22, 2015 8:17 pm
by Eugene Lutsenko
In Topic:
http://bb.donnay-software.com/donnay/vi ... 8&start=20
Jimmy gave the example of filling a triangle gradintnym color based on the colors at the vertices.

Code: Select all

GraGradient(oPS, {0,aTmp[2]}, {{aTmp[1],0}, aTmp      }, aColors1 ,GRA_GRADIENT_TRIANGLE)
*GraGradient(oPS, {0,      0}, {{aTmp[1],0}, aTmp      }, aColors1 ,GRA_GRADIENT_TRIANGLE)
*GraGradient(oPS, {0,aTmp[2]}, {{0      ,0},{aTmp[1],0}}, aColors1 ,GRA_GRADIENT_TRIANGLE)
Is it possible to generalize this example:
- Given the coordinates and color 2 points - to build a line with a gradient color;
- Given the coordinates and color 3 points - to build a triangle with a gradient color;
- Given the coordinates and color of 4 points - to build a rectangle with a gradient color;
- Given the coordinates and color 5 points - to construct a pentagon with a gradient color;
..................
- Given the coordinates and color of N points - to build a n-gon with gradient color.

It is clear that any polygon can be divided into triangles and the triangle problem is solved. But the fact is that there are many ways to partition the polygon into triangles (the problem of triangulation). In addition it should be done. And maybe one team all provide.

Re: Fill polygon gradient color

Posted: Tue Jun 23, 2015 5:52 am
by Auge_Ohr
hi,

look into Sample TRIGRAD.PRG. you "just" have to build a Vertex

Code: Select all

STATIC FUNCTION Psycho(o)
...
   cRet := o:TriVertEx(1,       0,      0)   // 1st Gradient
   cRet += o:TriVertEx(2, aDim[1],      0)   // 2nd
   cRet += o:TriVertEx(3, aDim[1],aDim[2])   // 3th
   cRet += o:TriVertEx(4,       0,aDim[2])   // 4th

   // if you need  more add here

RETURN (cRet)

Re: Fill polygon gradient color

Posted: Tue Jun 23, 2015 1:03 pm
by Eugene Lutsenko
Hi, Jimmy!

What do you "just" for me very, very not easy. I do not understand what a vertex. Could you lead a fully three small working program that you can compile and execute:
1. Fill the line segment to the coordinates and gradient colors start and end points of the segment.
2. Fill the triangle with a gradient of color coordinates and vertex points of the triangle.
3. Fill the quadrangle with a gradient of color coordinates and vertex points of the quadrangle.
4. ......
5. ......
Please.

Re: Fill polygon gradient color

Posted: Tue Jun 23, 2015 4:12 pm
by Auge_Ohr
Eugene Lutsenko wrote:1. Fill the line segment to the coordinates and gradient colors start and end points of the segment.

Code: Select all

GraGradient(oPS, {X1,Y1}, {{X2,Y2}}, aColors ,GRA_GRADIENT_HORIZONTAL or GRA_GRADIENT_VERTICAL)
Eugene Lutsenko wrote:2. Fill the triangle with a gradient of color coordinates and vertex points of the triangle.

Code: Select all

GraGradient(oPS, {X1,Y1}, {{X2,Y2}, {X3,Y3}}, aColors ,GRA_GRADIENT_TRIANGLE)
Eugene Lutsenko wrote:3. Fill the quadrangle with a gradient of color coordinates and vertex points of the quadrangle.
4. ......
5. ......
as you say
It is clear that any polygon can be divided into triangles and the triangle problem is solved. But the fact is that there are many ways to partition the polygon into triangles (the problem of triangulation).
you have the Source of GraGradient() in c:\ALASKA\XPPW32\Source\SYS\GraSys.prg which return

Code: Select all

oPS:drawGradientFill()
in c:\ALASKA\XPPW32\Source\SYS\xbparts.prg you find

Code: Select all

METHOD XbpPresSpace:DrawGradientFill( aStart, aVertices, aColors, nMode )
...
#ifdef __WIN32__
  // this is API Way
#endif
   // Use simulation on platforms not
   // supporting the GradientFill API
so have a look how Alaska use GRA Function to simulate GraGradient() / GradientFill.

Re: Fill polygon gradient color

Posted: Wed Jun 24, 2015 7:29 am
by Eugene Lutsenko
What is the structure of the array: aColors for different number of points?

For four points will be so?

GraGradient (oPS, {X1, Y1}, {{X2, Y2}, {{X3, Y3}, {X4, Y4}}}, aColors, GRA_GRADIENT_quadrangle)

Action example of a function GraGradient () I have not found, including documentation.

Until I got to do to make it work.

Re: Fill polygon gradient color

Posted: Wed Jun 24, 2015 7:50 am
by Auge_Ohr
Eugene Lutsenko wrote:What is the structure of the array: aColors for different number of points?
Help File say :
{<xColor1>,<xColor2>} for 2 Color
{<xColor1>,<xColor2>,<xColor3>} for Triangle
Eugene Lutsenko wrote:For four points will be so?
GraGradient (oPS, {X1, Y1}, {{X2, Y2}, {{X3, Y3}, {X4, Y4}}}, aColors, GRA_GRADIENT_quadrangle)
the are only 3 Constante
GRA_GRADIENT_HORIZONTAL
GRA_GRADIENT_VERTICAL
and
GRA_GRADIENT_TRIANGLE
so it will NOT work with more than 3 Coordinate.
Eugene Lutsenko wrote:Action example of a function GraGradient () I have not found, including documentation.
Until I got to do to make it work.
as i say : you have the Source ...

Re: Fill polygon gradient color

Posted: Sat Jun 27, 2015 10:09 am
by Eugene Lutsenko
Everybody did it!
http://lc.kubagro.ru/1.pdf (see pages 22, 23, 24)
Thank you for your help!