color.c
Go to the documentation of this file.
1 #include "color.h"
2 
3 
14 void NewColor(double r,double g,double b,Tcolor *c)
15 {
16  c->r=r;
17  c->g=g;
18  c->b=b;
19 }
20 
21 void CopyColor(Tcolor *c_dst,Tcolor *c_src)
22 {
23  c_dst->r=c_src->r;
24  c_dst->g=c_src->g;
25  c_dst->b=c_src->b;
26 }
27 
28 boolean NullColor(Tcolor *c)
29 {
30  return((c->r<0)||(c->g<0)||(c->b<0));
31 }
32 
33 void ScaleColor(double s,Tcolor *c)
34 {
35  c->r*=s;
36  c->g*=s;
37  c->b*=s;
38 }
39 
40 void CostColor(double cost,double minCost,Tcolor *c)
41 {
42  if (cost<minCost)
43  {
44  /* Black */
45  c->r=0;
46  c->g=0;
47  c->b=0;
48  }
49  else
50  {
51  /* Gradient for the rest (0=green, 1=red) */
52  c->r=cost;
53  c->g=1.0-cost;
54  c->b=0;
55  }
56 }
57 
58 void SetRed(double r,Tcolor *c)
59 {
60  c->r=r;
61 }
62 
63 void SetGreen(double g,Tcolor *c)
64 {
65  c->g=g;
66 }
67 
68 void SetBlue(double b,Tcolor *c)
69 {
70  c->b=b;
71 }
72 
73 double GetRed(Tcolor *c)
74 {
75  return(c->r);
76 }
77 
78 double GetGreen(Tcolor *c)
79 {
80  return(c->g);
81 }
82 
83 double GetBlue(Tcolor *c)
84 {
85  return(c->b);
86 }
87 
88 void PrintColor(FILE *f,Tcolor *c)
89 {
90  fprintf(f,"%f %f %f",c->r,c->g,c->b);
91 }
92 
94 {
95 }
void SetBlue(double b, Tcolor *c)
Changes the blue component of a color.
Definition: color.c:68
void PrintColor(FILE *f, Tcolor *c)
Prints the color.
Definition: color.c:88
boolean NullColor(Tcolor *c)
Identifies a non-valid color.
Definition: color.c:28
double GetGreen(Tcolor *c)
Gets the green component of a color.
Definition: color.c:78
double b
Definition: color.h:26
void CopyColor(Tcolor *c_dst, Tcolor *c_src)
Copy constructor.
Definition: color.c:21
A color.
Definition: color.h:23
double g
Definition: color.h:25
void SetGreen(double g, Tcolor *c)
Changes the green component of a color.
Definition: color.c:63
void ScaleColor(double s, Tcolor *c)
Scales a color.
Definition: color.c:33
void SetRed(double r, Tcolor *c)
Changes the red component of a color.
Definition: color.c:58
double r
Definition: color.h:24
double GetRed(Tcolor *c)
Gets the red component of a color.
Definition: color.c:73
Definition of the Tcolor type and the associated functions.
void DeleteColor(Tcolor *c)
Destructor.
Definition: color.c:93
void NewColor(double r, double g, double b, Tcolor *c)
Constructor.
Definition: color.c:14
double GetBlue(Tcolor *c)
Gets the blue component of a color.
Definition: color.c:83
void CostColor(double cost, double minCost, Tcolor *c)
Definees a color in function of a cost.
Definition: color.c:40