PandA-2024.02
vgatest.c
Go to the documentation of this file.
1 #include "leds_ctrl.h"
2 #include "sw_ctrl.h"
3 #include "btn_ctrl.h"
4 #include "plot.h"
5 #include "delay.h"
6 
7 #define sgn(x) ((x<0)?-1:((x>0)?1:0))
8 #define RESOLUTION_X 640
9 #define RESOLUTION_Y 480
10 
11 void line(int x1, int y1, int x2, int y2, unsigned int color)
12 {
13  int i,dx,dy,sdx,sdy,dxabs,dyabs,x,y,px,py;
14 
15  dx=x2-x1; /* the horizontal distance of the line */
16  dy=y2-y1; /* the vertical distance of the line */
17  dxabs=abs(dx);
18  dyabs=abs(dy);
19  sdx=sgn(dx);
20  sdy=sgn(dy);
21  x=dyabs>>1;
22  y=dxabs>>1;
23  px=x1;
24  py=y1;
25 
26  plot(color,px,py);
27  if (dxabs>=dyabs) /* the line is more horizontal than vertical */
28  {
29  for(i=0; i<dxabs; i++)
30  {
31  y+=dyabs;
32  if (y>=dxabs)
33  {
34  y-=dxabs;
35  py+=sdy;
36  }
37  px+=sdx;
38  plot(color,px,py);
39  }
40  }
41  else /* the line is more vertical than horizontal */
42  {
43  for(i=0; i<dyabs; i++)
44  {
45  x+=dxabs;
46  if (x>=dyabs)
47  {
48  x-=dyabs;
49  px+=sdx;
50  }
51  py+=sdy;
52  plot(color,px,py);
53  }
54  }
55 }
56 
57 void Rect(int left,int top, int right, int bottom, unsigned int color)
58 {
59  line(left,top,right,top,color);
60  line(left,top,left,bottom,color);
61  line(right,top,right,bottom,color);
62  line(left,bottom,right,bottom,color);
63 }
64 void RectFill(int left,int top, int right, int bottom, unsigned int color)
65 {
66  int currentline;
67  for (currentline=top; currentline<=bottom; currentline++) {
68  line(left,currentline,right,currentline,color);
69  }
70 }
71 
72 
73 
74 
75 void Circle(int x0, int y0, int radius, unsigned int color)
76 {
77  int x = radius, y = 0;
78  int radiusError = 1-x;
79 
80  while(x >= y)
81  {
82  plot(color,x + x0, y + y0);
83  plot(color,y + x0, x + y0);
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  y++;
91  if(radiusError<0)
92  radiusError+=2*y+1;
93  else
94  {
95  x--;
96  radiusError+=2*(y-x+1);
97  }
98  }
99 }
100 
101 void CircleFill(int x0, int y0, int radius, unsigned int color)
102 {
103  int x = radius, y = 0;
104  int radiusError = 1-x;
105 
106  while(x >= y)
107  {
108  line(x + x0,y + y0,-x + x0, y + y0,color);
109  line(y + x0, x + y0,y + x0, -x + y0,color);
110  line(-y + x0, x + y0,-y + x0, -x + y0,color);
111  line(-x + x0, -y + y0,x + x0, -y + y0,color);
112  y++;
113  if(radiusError<0)
114  radiusError+=2*y+1;
115  else
116  {
117  x--;
118  radiusError+=2*(y-x+1);
119  }
120  }
121 }
122 
123 
124 void plot_test() {
125  int x,y,k;
126  int radius=10;
127 
128 #ifdef C_SIMULATION
129  for (x=0; x<1; x++) {
130 #else
131  for (x=0; x<RESOLUTION_X; x++) {
132 #endif
133 #ifdef C_SIMULATION
134  for (y=0; y<1; y++) {
135 #else
136  for (y=0; y<RESOLUTION_Y; y++) {
137 #endif
138  unsigned short color = sw_ctrl();
139  unsigned char dir = btn_ctrl();
140  if(color==0) color = 7;
141  if(color>7) color = 7;
142  if(dir==BUTTON_UP) ++radius;
143  else if(dir==BUTTON_DOWN) --radius;
144  if(radius < 8) radius = 8;
145  if(radius > 31) radius = 31;
146  leds_ctrl(x);
147  leds_ctrl(y);
148  Circle(x,y,radius,color);
149 #ifdef C_SIMULATION
150  delay(1);
151 #else
152  delay(1000000);
153 #endif
154  Circle(x,y,radius,0);
155  }
156  }
157 }
158 
159 void main() {
160  plot_test();
161 }
void * top(node_stack *head)
Definition: tree.c:75
int main()
Definition: vgatest.c:204
unsigned char btn_ctrl()
Definition: btn_ctrl.c:3
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
#define RESOLUTION_Y
Definition: vgatest.c:9
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
unsigned short sw_ctrl()
Definition: sw_ctrl.c:2
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 BUTTON_DOWN
Definition: btn_ctrl.h:5
#define sgn(x)
Definition: vgatest.c:7
#define BUTTON_UP
Definition: btn_ctrl.h:4
#define RESOLUTION_X
Definition: vgatest.c:8
x
Return the smallest n such that 2^n >= _x.
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