PandA-2024.02
vgatest.c
Go to the documentation of this file.
1 #define sgn(x) ((x<0)?-1:((x>0)?1:0))
2 extern void plot(int color, int x, int y);
3 extern void leds_ctrl(unsigned int id, unsigned int val);
4 extern int delay(int ritardo);
5 #if 1
6 #define RESOLUTION_X 160
7 #define RESOLUTION_Y 120
8 #else
9 #define RESOLUTION_X 320
10 #define RESOLUTION_Y 240
11 #endif
12 
13 void line(int x1, int y1, int x2, int y2, unsigned int color)
14 {
15  int i,dx,dy,sdx,sdy,dxabs,dyabs,x,y,px,py;
16 
17  dx=x2-x1; /* the horizontal distance of the line */
18  dy=y2-y1; /* the vertical distance of the line */
19  dxabs=abs(dx);
20  dyabs=abs(dy);
21  sdx=sgn(dx);
22  sdy=sgn(dy);
23  x=dyabs>>1;
24  y=dxabs>>1;
25  px=x1;
26  py=y1;
27 
28  plot(color,px,py);
29  if (dxabs>=dyabs) /* the line is more horizontal than vertical */
30  {
31  for(i=0; i<dxabs; i++)
32  {
33  y+=dyabs;
34  if (y>=dxabs)
35  {
36  y-=dxabs;
37  py+=sdy;
38  }
39  px+=sdx;
40  plot(color,px,py);
41  }
42  }
43  else /* the line is more vertical than horizontal */
44  {
45  for(i=0; i<dyabs; i++)
46  {
47  x+=dxabs;
48  if (x>=dyabs)
49  {
50  x-=dyabs;
51  px+=sdx;
52  }
53  py+=sdy;
54  plot(color,px,py);
55  }
56  }
57 }
58 
59 void Rect(int left,int top, int right, int bottom, unsigned int color)
60 {
61  line(left,top,right,top,color);
62  line(left,top,left,bottom,color);
63  line(right,top,right,bottom,color);
64  line(left,bottom,right,bottom,color);
65 }
66 void RectFill(int left,int top, int right, int bottom, unsigned int color)
67 {
68  int currentline;
69  for (currentline=top; currentline<=bottom; currentline++) {
70  line(left,currentline,right,currentline,color);
71  }
72 }
73 
74 
75 
76 
77 void Circle(int x0, int y0, int radius, unsigned int color)
78 {
79  int x = radius, y = 0;
80  int radiusError = 1-x;
81 
82  while(x >= y)
83  {
84  plot(color,x + x0, y + y0);
85  plot(color,y + x0, x + y0);
86  plot(color,-x + x0, y + y0);
87  plot(color,-y + x0, x + y0);
88  plot(color,-x + x0, -y + y0);
89  plot(color,-y + x0, -x + y0);
90  plot(color,x + x0, -y + y0);
91  plot(color,y + x0, -x + y0);
92  y++;
93  if(radiusError<0)
94  radiusError+=2*y+1;
95  else
96  {
97  x--;
98  radiusError+=2*(y-x+1);
99  }
100  }
101 }
102 
103 void CircleFill(int x0, int y0, int radius, unsigned int color)
104 {
105  int x = radius, y = 0;
106  int radiusError = 1-x;
107 
108  while(x >= y)
109  {
110  line(x + x0,y + y0,-x + x0, y + y0,color);
111  line(y + x0, x + y0,y + x0, -x + y0,color);
112  line(-y + x0, x + y0,-y + x0, -x + y0,color);
113  line(-x + x0, -y + y0,x + x0, -y + y0,color);
114  y++;
115  if(radiusError<0)
116  radiusError+=2*y+1;
117  else
118  {
119  x--;
120  radiusError+=2*(y-x+1);
121  }
122  }
123 }
124 
125 
126 void plot_test() {
127  int x,y,k;
128 //Uncomment desired test function
129 # if 1
130  // Multiple circle test:
131 #ifdef C_SIMULATION
132  for (x=0; x<1; x++) {
133 #else
134  for (x=0; x<RESOLUTION_X; x++) {
135 #endif
136  for (y=0; y<RESOLUTION_Y; y++) {
137  leds_ctrl(4,x);
138  leds_ctrl(5,y);
139  Circle(x,y,10,7);
140  delay(500000);
141  Circle(x,y,10,0);
142  }
143  }
144 #endif
145 # if 0
146  k=0;
147  //Pattern test:
148  for (x=0; x<RESOLUTION_X; x++) {
149  for (y=0; y<RESOLUTION_Y; y++) {
150  k++;
151  plot((k*x*y)%8,x,y);
152  }
153  }
154 #endif
155 # if 0
156  //Multiple Square test:
157  for (x=0; x<RESOLUTION_X; x++) {
158  for (y=0; y<RESOLUTION_Y; y++) {
159  Rect(x,y,x+10,y+10,4);
160  delay(500000);
161  Rect(x,y,x+10,y+10,0);
162  }
163  }
164 #endif
165 # if 0
166  // Multiple circle test:
167  for (x=0; x<RESOLUTION_X; x++) {
168  for (y=0; y<RESOLUTION_Y; y++) {
169  CircleFill(x,y,10,4);
170  delay(500000);
171  CircleFill(x,y,10,0);
172  }
173  }
174 #endif
175 # if 0
176  //Multiple Square test:
177  for (x=0; x<RESOLUTION_X; x++) {
178  for (y=0; y<RESOLUTION_Y; y++) {
179  RectFill(x,y,x+10,y+10,4);
180  delay(500000);
181  RectFill(x,y,x+10,y+10,0);
182  }
183  }
184 #endif
185 # if 0
186  //Multiple Polygons test:
187  for (x=0; x<RESOLUTION_X; x++) {
188  for (y=0; y<RESOLUTION_Y; y++) {
189  Circle(x,y,10,4);
190  CircleFill(x-4,y-1,1,3);
191  CircleFill(x+4,y-1,1,3);
192  RectFill(x-2,y+4,x+2,y+5,2);
193  delay(500000);
194  Circle(x,y,10,0);
195  CircleFill(x-4,y-1,1,0);
196  CircleFill(x+4,y-1,1,0);
197  RectFill(x-2,y+4,x+2,y+5,0);
198  }
199  }
200 #endif
201  return;
202 }
203 
204 int main() {
205  plot_test();
206  return 0;
207 }
void * top(node_stack *head)
Definition: tree.c:75
int main()
Definition: vgatest.c:204
void Rect(int left, int top, int right, int bottom, unsigned int color)
Definition: vgatest.c:59
void plot(int color, int x, int y)
Definition: plot.c:1
void line(int x1, int y1, int x2, int y2, unsigned int color)
Definition: vgatest.c:13
#define abs(x)
Definition: main.c:3
void CircleFill(int x0, int y0, int radius, unsigned int color)
Definition: vgatest.c:103
void plot_test()
Definition: vgatest.c:126
static const uint32_t k[]
Definition: sha-256.c:22
void Circle(int x0, int y0, int radius, unsigned int color)
Definition: vgatest.c:77
void leds_ctrl(unsigned int id, unsigned int val)
Definition: leds_ctrl.c:1
int delay(int ritardo)
Definition: delay.c:1
#define sgn(x)
Definition: vgatest.c:1
x
Return the smallest n such that 2^n >= _x.
#define RESOLUTION_Y
Definition: vgatest.c:7
#define RESOLUTION_X
Definition: vgatest.c:6
void RectFill(int left, int top, int right, int bottom, unsigned int color)
Definition: vgatest.c:66

Generated on Mon Feb 12 2024 13:02:50 for PandA-2024.02 by doxygen 1.8.13