Moar drawing functions
This commit is contained in:
parent
56e30a0e36
commit
b58087f22c
2 changed files with 201 additions and 9 deletions
|
|
@ -1,20 +1,23 @@
|
||||||
|
local math = require('math')
|
||||||
local paper = require('paper')
|
local paper = require('paper')
|
||||||
|
|
||||||
paper.init()
|
paper.init()
|
||||||
paper.clear()
|
paper.clear()
|
||||||
|
|
||||||
|
local width = paper.get_width()
|
||||||
|
local height = paper.get_height()
|
||||||
|
|
||||||
print(
|
print(
|
||||||
'width: ' .. paper.get_width(),
|
'width: ' .. width,
|
||||||
'height: ' .. paper.get_height()
|
'height: ' .. height
|
||||||
)
|
)
|
||||||
|
|
||||||
pad_w = paper.get_width() * 0.12
|
for i = 1, 50 do
|
||||||
pad_h = paper.get_height() * 0.12
|
x = math.random() * width
|
||||||
|
y = math.random() * height
|
||||||
|
r = 24 + math.ceil(math.random() * 12)
|
||||||
|
|
||||||
for i = 0, 15 do
|
paper.fill_circle(x, y, r, math.floor(math.random() * 0xFF))
|
||||||
for j = 1, 4 do
|
|
||||||
paper.draw_line(paper.get_height() / 16 * i, j, paper.get_width(), paper.get_height() - 4 + j, i * 16)
|
|
||||||
end
|
|
||||||
-- paper.draw_line(0, paper.get_height(), paper.get_width(), paper.get, i * 16)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
paper.update()
|
paper.update()
|
||||||
|
|
|
||||||
189
main/paper.h
189
main/paper.h
|
|
@ -46,6 +46,21 @@ static int set_rotation (lua_State *L) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int draw_pixel (lua_State *L) {
|
||||||
|
int x, y, color;
|
||||||
|
int isnum;
|
||||||
|
|
||||||
|
x = lua_tonumberx(L, -3, &isnum);
|
||||||
|
luaL_argcheck(L, isnum, -3, "expected `x` to be a number");
|
||||||
|
y = lua_tonumberx(L, -2, &isnum);
|
||||||
|
luaL_argcheck(L, isnum, -2, "expected `y` to be a number");
|
||||||
|
color = lua_tonumberx(L, -1, &isnum);
|
||||||
|
luaL_argcheck(L, isnum && color >= 0 && color < 256, -1, "expected `color` to be a number within [0, 255]");
|
||||||
|
|
||||||
|
epd_draw_pixel(x, y, color, fb);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int draw_line (lua_State *L) {
|
static int draw_line (lua_State *L) {
|
||||||
int x1, y1, x2, y2, color;
|
int x1, y1, x2, y2, color;
|
||||||
int isnum;
|
int isnum;
|
||||||
|
|
@ -65,6 +80,170 @@ static int draw_line (lua_State *L) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int draw_hline (lua_State *L) {
|
||||||
|
int x, y, length, color;
|
||||||
|
int isnum;
|
||||||
|
|
||||||
|
x = lua_tonumberx(L, -4, &isnum);
|
||||||
|
luaL_argcheck(L, isnum, -4, "expected `x` to be a number");
|
||||||
|
y = lua_tonumberx(L, -3, &isnum);
|
||||||
|
luaL_argcheck(L, isnum, -3, "expected `y` to be a number");
|
||||||
|
length = lua_tonumberx(L, -2, &isnum);
|
||||||
|
luaL_argcheck(L, isnum, -2, "expected `length` to be a number");
|
||||||
|
color = lua_tonumberx(L, -1, &isnum);
|
||||||
|
luaL_argcheck(L, isnum && color >= 0 && color < 256, -1, "expected `color` to be a number within [0, 255]");
|
||||||
|
|
||||||
|
epd_draw_hline(x, y, length, color, fb);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int draw_vline (lua_State *L) {
|
||||||
|
int x, y, length, color;
|
||||||
|
int isnum;
|
||||||
|
|
||||||
|
x = lua_tonumberx(L, -4, &isnum);
|
||||||
|
luaL_argcheck(L, isnum, -4, "expected `x` to be a number");
|
||||||
|
y = lua_tonumberx(L, -3, &isnum);
|
||||||
|
luaL_argcheck(L, isnum, -3, "expected `y` to be a number");
|
||||||
|
length = lua_tonumberx(L, -2, &isnum);
|
||||||
|
luaL_argcheck(L, isnum, -2, "expected `length` to be a number");
|
||||||
|
color = lua_tonumberx(L, -1, &isnum);
|
||||||
|
luaL_argcheck(L, isnum && color >= 0 && color < 256, -1, "expected `color` to be a number within [0, 255]");
|
||||||
|
|
||||||
|
epd_draw_vline(x, y, length, color, fb);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int draw_circle (lua_State *L) {
|
||||||
|
int x, y, radius, color;
|
||||||
|
int isnum;
|
||||||
|
|
||||||
|
x = lua_tonumberx(L, -4, &isnum);
|
||||||
|
luaL_argcheck(L, isnum, -4, "expected `x` to be a number");
|
||||||
|
y = lua_tonumberx(L, -3, &isnum);
|
||||||
|
luaL_argcheck(L, isnum, -3, "expected `y` to be a number");
|
||||||
|
radius = lua_tonumberx(L, -2, &isnum);
|
||||||
|
luaL_argcheck(L, isnum, -2, "expected `radius` to be a number");
|
||||||
|
color = lua_tonumberx(L, -1, &isnum);
|
||||||
|
luaL_argcheck(L, isnum && color >= 0 && color < 256, -1, "expected `color` to be a number within [0, 255]");
|
||||||
|
|
||||||
|
epd_draw_circle(x, y, radius, color, fb);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int fill_circle (lua_State *L) {
|
||||||
|
int x, y, radius, color;
|
||||||
|
int isnum;
|
||||||
|
|
||||||
|
x = lua_tonumberx(L, -4, &isnum);
|
||||||
|
luaL_argcheck(L, isnum, -4, "expected `x` to be a number");
|
||||||
|
y = lua_tonumberx(L, -3, &isnum);
|
||||||
|
luaL_argcheck(L, isnum, -3, "expected `y` to be a number");
|
||||||
|
radius = lua_tonumberx(L, -2, &isnum);
|
||||||
|
luaL_argcheck(L, isnum, -2, "expected `radius` to be a number");
|
||||||
|
color = lua_tonumberx(L, -1, &isnum);
|
||||||
|
luaL_argcheck(L, isnum && color >= 0 && color < 256, -1, "expected `color` to be a number within [0, 255]");
|
||||||
|
|
||||||
|
epd_fill_circle(x, y, radius, color, fb);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int draw_rect (lua_State *L) {
|
||||||
|
int x1, y1, x2, y2, color;
|
||||||
|
int isnum;
|
||||||
|
|
||||||
|
x1 = lua_tonumberx(L, -5, &isnum);
|
||||||
|
luaL_argcheck(L, isnum, -5, "expected `x1` to be a number");
|
||||||
|
y1 = lua_tonumberx(L, -4, &isnum);
|
||||||
|
luaL_argcheck(L, isnum, -4, "expected `y1` to be a number");
|
||||||
|
x2 = lua_tonumberx(L, -3, &isnum);
|
||||||
|
luaL_argcheck(L, isnum, -3, "expected `x2` to be a number");
|
||||||
|
y2 = lua_tonumberx(L, -2, &isnum);
|
||||||
|
luaL_argcheck(L, isnum, -2, "expected `y2` to be a number");
|
||||||
|
color = lua_tonumberx(L, -1, &isnum);
|
||||||
|
luaL_argcheck(L, isnum && color >= 0 && color < 256, -1, "expected `color` to be a number within [0, 255]");
|
||||||
|
|
||||||
|
EpdRect rect = {
|
||||||
|
.x = x1,
|
||||||
|
.y = y1,
|
||||||
|
.width = x2 - x1,
|
||||||
|
.height = y2 - y1
|
||||||
|
};
|
||||||
|
epd_draw_rect(rect, color, fb);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int fill_rect (lua_State *L) {
|
||||||
|
int x1, y1, x2, y2, color;
|
||||||
|
int isnum;
|
||||||
|
|
||||||
|
x1 = lua_tonumberx(L, -5, &isnum);
|
||||||
|
luaL_argcheck(L, isnum, -5, "expected `x1` to be a number");
|
||||||
|
y1 = lua_tonumberx(L, -4, &isnum);
|
||||||
|
luaL_argcheck(L, isnum, -4, "expected `y1` to be a number");
|
||||||
|
x2 = lua_tonumberx(L, -3, &isnum);
|
||||||
|
luaL_argcheck(L, isnum, -3, "expected `x2` to be a number");
|
||||||
|
y2 = lua_tonumberx(L, -2, &isnum);
|
||||||
|
luaL_argcheck(L, isnum, -2, "expected `y2` to be a number");
|
||||||
|
color = lua_tonumberx(L, -1, &isnum);
|
||||||
|
luaL_argcheck(L, isnum && color >= 0 && color < 256, -1, "expected `color` to be a number within [0, 255]");
|
||||||
|
|
||||||
|
EpdRect rect = {
|
||||||
|
.x = x1,
|
||||||
|
.y = y1,
|
||||||
|
.width = x2 - x1,
|
||||||
|
.height = y2 - y1
|
||||||
|
};
|
||||||
|
epd_fill_rect(rect, color, fb);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int draw_triangle (lua_State *L) {
|
||||||
|
int x1, y1, x2, y2, x3, y3, color;
|
||||||
|
int isnum;
|
||||||
|
|
||||||
|
x1 = lua_tonumberx(L, -7, &isnum);
|
||||||
|
luaL_argcheck(L, isnum, -7, "expected `x1` to be a number");
|
||||||
|
y1 = lua_tonumberx(L, -6, &isnum);
|
||||||
|
luaL_argcheck(L, isnum, -6, "expected `y1` to be a number");
|
||||||
|
x2 = lua_tonumberx(L, -5, &isnum);
|
||||||
|
luaL_argcheck(L, isnum, -5, "expected `x2` to be a number");
|
||||||
|
y2 = lua_tonumberx(L, -4, &isnum);
|
||||||
|
luaL_argcheck(L, isnum, -4, "expected `y2` to be a number");
|
||||||
|
x3 = lua_tonumberx(L, -3, &isnum);
|
||||||
|
luaL_argcheck(L, isnum, -3, "expected `x3` to be a number");
|
||||||
|
y3 = lua_tonumberx(L, -2, &isnum);
|
||||||
|
luaL_argcheck(L, isnum, -2, "expected `y3` to be a number");
|
||||||
|
color = lua_tonumberx(L, -1, &isnum);
|
||||||
|
luaL_argcheck(L, isnum && color >= 0 && color < 256, -1, "expected `color` to be a number within [0, 255]");
|
||||||
|
|
||||||
|
epd_draw_triangle(x1, y1, x2, y2, x3, y3, color, fb);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int fill_triangle (lua_State *L) {
|
||||||
|
int x1, y1, x2, y2, x3, y3, color;
|
||||||
|
int isnum;
|
||||||
|
|
||||||
|
x1 = lua_tonumberx(L, -7, &isnum);
|
||||||
|
luaL_argcheck(L, isnum, -7, "expected `x1` to be a number");
|
||||||
|
y1 = lua_tonumberx(L, -6, &isnum);
|
||||||
|
luaL_argcheck(L, isnum, -6, "expected `y1` to be a number");
|
||||||
|
x2 = lua_tonumberx(L, -5, &isnum);
|
||||||
|
luaL_argcheck(L, isnum, -5, "expected `x2` to be a number");
|
||||||
|
y2 = lua_tonumberx(L, -4, &isnum);
|
||||||
|
luaL_argcheck(L, isnum, -4, "expected `y2` to be a number");
|
||||||
|
x3 = lua_tonumberx(L, -3, &isnum);
|
||||||
|
luaL_argcheck(L, isnum, -3, "expected `x3` to be a number");
|
||||||
|
y3 = lua_tonumberx(L, -2, &isnum);
|
||||||
|
luaL_argcheck(L, isnum, -2, "expected `y3` to be a number");
|
||||||
|
color = lua_tonumberx(L, -1, &isnum);
|
||||||
|
luaL_argcheck(L, isnum && color >= 0 && color < 256, -1, "expected `color` to be a number within [0, 255]");
|
||||||
|
|
||||||
|
epd_fill_triangle(x1, y1, x2, y2, x3, y3, color, fb);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int update (lua_State *L) {
|
static int update (lua_State *L) {
|
||||||
int temperature = 25;
|
int temperature = 25;
|
||||||
epd_poweron();
|
epd_poweron();
|
||||||
|
|
@ -81,7 +260,17 @@ static const struct luaL_Reg paper[] = {
|
||||||
{"get_height", get_height},
|
{"get_height", get_height},
|
||||||
|
|
||||||
{"set_rotation", set_rotation},
|
{"set_rotation", set_rotation},
|
||||||
|
|
||||||
|
{"draw_pixel", draw_pixel},
|
||||||
{"draw_line", draw_line},
|
{"draw_line", draw_line},
|
||||||
|
{"draw_hline", draw_hline},
|
||||||
|
{"draw_vline", draw_vline},
|
||||||
|
{"draw_circle", draw_circle},
|
||||||
|
{"fill_circle", fill_circle},
|
||||||
|
{"draw_rect", draw_rect},
|
||||||
|
{"fill_rect", fill_rect},
|
||||||
|
{"draw_triangle", draw_triangle},
|
||||||
|
{"fill_triangle", fill_triangle},
|
||||||
{"update", update},
|
{"update", update},
|
||||||
|
|
||||||
{NULL, NULL},
|
{NULL, NULL},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue