-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphics.c
49 lines (44 loc) · 1.29 KB
/
graphics.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* graphics.c
*
* Created on: 2017年12月12日
* Author: frank
*/
#include "graphics.h"
#include "enviroment.h"
void drawRectangle(rgba *p, int x, int y, int width, int height, int rgb) {
for (int i = x; i < x + width; i++) {
setRgb(p + y * screen_width + i, rgb);
setRgb(p + (y + height - 1) * screen_width + i, rgb);
}
for (int j = y + 1; j < y + height - 1; j++) {
setRgb(p + j * screen_width + x, rgb);
setRgb(p + j * screen_width + x + width - 1, rgb);
}
}
void drawRectangleWithRgba(rgba *p, int x, int y, int width, int height,
rgba *color) {
for (int i = x; i < x + width; i++) {
drawRgba(p + y * screen_width + i, color);
drawRgba(p + (y + height - 1) * screen_width + i, color);
}
for (int j = y + 1; j < y + height - 1; j++) {
drawRgba(p + j * screen_width + x, color);
drawRgba(p + j * screen_width + x + width - 1, color);
}
}
void fillRectangle(rgba *p, int x, int y, int width, int height, int rgb) {
for (int i = x; i < x + width; i++) {
for (int j = y; j < y + height; j++) {
setRgb(p + j * screen_width + i, rgb);
}
}
}
void fillRectangleWithRgba(rgba *p, int x, int y, int width, int height,
rgba *color) {
for (int i = x; i < x + width; i++) {
for (int j = y; j < y + height; j++) {
drawRgba(p + j * screen_width + i, color);
}
}
}