Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
5c93ba01
Commit
5c93ba01
authored
Aug 09, 2015
by
devsaurus
Browse files
finish GraphicsTest.lua
parent
ac1b5a11
Changes
12
Show whitespace changes
Inline
Side-by-side
app/modules/ucg.c
View file @
5c93ba01
...
...
@@ -117,6 +117,22 @@ static int lucg_drawBox( lua_State *L )
return
0
;
}
// Lua: ucg.drawFrame( self, x, y, w, h )
static
int
lucg_drawFrame
(
lua_State
*
L
)
{
lucg_userdata_t
*
lud
;
if
((
lud
=
get_lud
(
L
))
==
NULL
)
return
0
;
ucg_int_t
args
[
4
];
lucg_get_int_args
(
L
,
2
,
4
,
args
);
ucg_DrawFrame
(
LUCG
,
args
[
0
],
args
[
1
],
args
[
2
],
args
[
3
]
);
return
0
;
}
// Lua: ucg.drawGradientBox( self, x, y, w, h )
static
int
lucg_drawGradientBox
(
lua_State
*
L
)
{
...
...
@@ -356,6 +372,19 @@ static int lucg_setFontMode( lua_State *L )
return
0
;
}
// Lua: ucg.setMaxClipRange( self )
static
int
lucg_setMaxClipRange
(
lua_State
*
L
)
{
lucg_userdata_t
*
lud
;
if
((
lud
=
get_lud
(
L
))
==
NULL
)
return
0
;
ucg_SetMaxClipRange
(
LUCG
);
return
0
;
}
// Lua: ucg.setPrintPos( self, x, y )
static
int
lucg_setPrintPos
(
lua_State
*
L
)
{
...
...
@@ -610,6 +639,7 @@ static const LUA_REG_TYPE lucg_display_map[] =
{
LSTRKEY
(
"clearScreen"
),
LFUNCVAL
(
lucg_clearScreen
)
},
{
LSTRKEY
(
"draw90Line"
),
LFUNCVAL
(
lucg_draw90Line
)
},
{
LSTRKEY
(
"drawBox"
),
LFUNCVAL
(
lucg_drawBox
)
},
{
LSTRKEY
(
"drawFrame"
),
LFUNCVAL
(
lucg_drawFrame
)
},
{
LSTRKEY
(
"drawGradientBox"
),
LFUNCVAL
(
lucg_drawGradientBox
)
},
{
LSTRKEY
(
"drawHLine"
),
LFUNCVAL
(
lucg_drawHLine
)
},
{
LSTRKEY
(
"drawLine"
),
LFUNCVAL
(
lucg_drawLine
)
},
...
...
@@ -624,6 +654,7 @@ static const LUA_REG_TYPE lucg_display_map[] =
{
LSTRKEY
(
"setColor"
),
LFUNCVAL
(
lucg_setColor
)
},
{
LSTRKEY
(
"setFont"
),
LFUNCVAL
(
lucg_setFont
)
},
{
LSTRKEY
(
"setFontMode"
),
LFUNCVAL
(
lucg_setFontMode
)
},
{
LSTRKEY
(
"setMaxClipRange"
),
LFUNCVAL
(
lucg_setMaxClipRange
)
},
{
LSTRKEY
(
"setPrintDir"
),
LFUNCVAL
(
lucg_setPrintDir
)
},
{
LSTRKEY
(
"setPrintPos"
),
LFUNCVAL
(
lucg_setPrintPos
)
},
{
LSTRKEY
(
"setRotate90"
),
LFUNCVAL
(
lucg_setRotate90
)
},
...
...
@@ -648,6 +679,7 @@ const LUA_REG_TYPE lucg_map[] =
{
LSTRKEY
(
"font_helvB08_hr"
),
LUDATA
(
(
void
*
)(
ucg_font_helvB08_hr
)
)
},
{
LSTRKEY
(
"font_helvB10_hr"
),
LUDATA
(
(
void
*
)(
ucg_font_helvB10_hr
)
)
},
{
LSTRKEY
(
"font_helvB12_hr"
),
LUDATA
(
(
void
*
)(
ucg_font_helvB12_hr
)
)
},
{
LSTRKEY
(
"font_helvB18_hr"
),
LUDATA
(
(
void
*
)(
ucg_font_helvB18_hr
)
)
},
{
LSTRKEY
(
"font_ncenR12_tr"
),
LUDATA
(
(
void
*
)(
ucg_font_ncenR12_tr
)
)
},
{
LSTRKEY
(
"font_ncenR14_hr"
),
LUDATA
(
(
void
*
)(
ucg_font_ncenR14_hr
)
)
},
...
...
@@ -679,6 +711,7 @@ LUALIB_API int luaopen_ucg( lua_State *L )
MOD_REG_LUDATA
(
L
,
"font_helvB08_hr"
,
(
void
*
)(
ucg_font_helvB08_hr
)
);
MOD_REG_LUDATA
(
L
,
"font_helvB10_hr"
,
(
void
*
)(
ucg_font_helvB10_hr
)
);
MOD_REG_LUDATA
(
L
,
"font_helvB12_hr"
,
(
void
*
)(
ucg_font_helvB12_hr
)
);
MOD_REG_LUDATA
(
L
,
"font_helvB18_hr"
,
(
void
*
)(
ucg_font_helvB18_hr
)
);
MOD_REG_LUDATA
(
L
,
"font_ncenR12_tr"
,
(
void
*
)(
ucg_font_ncenR12_tr
)
);
MOD_REG_LUDATA
(
L
,
"font_ncenR14_hr"
,
(
void
*
)(
ucg_font_ncenR14_hr
)
);
...
...
lua_examples/ucglib/GT_box.lua
0 → 100644
View file @
5c93ba01
local
M
,
module
=
{},
...
_G
[
module
]
=
M
function
M
.
run
()
-- make this a volatile module:
package.loaded
[
module
]
=
nil
print
(
"Running component box..."
)
local
x
,
y
,
w
,
h
local
m
disp
:
setColor
(
0
,
0
,
40
,
80
)
disp
:
setColor
(
1
,
60
,
0
,
40
)
disp
:
setColor
(
2
,
128
,
0
,
140
)
disp
:
setColor
(
3
,
0
,
128
,
140
)
disp
:
drawGradientBox
(
0
,
0
,
disp
:
getWidth
(),
disp
:
getHeight
())
disp
:
setColor
(
255
,
255
,
255
)
disp
:
setPrintPos
(
2
,
18
)
disp
:
setPrintDir
(
0
)
disp
:
print
(
"Box"
)
m
=
millis
()
+
T
while
millis
()
<
m
do
disp
:
setColor
(
bit
.
band
(
lcg_rnd
(),
127
)
+
127
,
bit
.
band
(
lcg_rnd
(),
127
)
+
64
,
bit
.
band
(
lcg_rnd
(),
31
))
w
=
bit
.
band
(
lcg_rnd
(),
31
)
h
=
bit
.
band
(
lcg_rnd
(),
31
)
w
=
w
+
10
h
=
h
+
10
x
=
bit
.
rshift
(
lcg_rnd
()
*
(
disp
:
getWidth
()
-
w
),
8
)
y
=
bit
.
rshift
(
lcg_rnd
()
*
(
disp
:
getHeight
()
-
h
-
20
),
8
)
disp
:
drawBox
(
x
,
y
+
20
,
w
,
h
)
end
print
(
"...done"
)
end
return
M
lua_examples/ucglib/GT_clip.lua
0 → 100644
View file @
5c93ba01
local
M
,
module
=
{},
...
_G
[
module
]
=
M
function
M
.
run
()
-- make this a volatile module:
package.loaded
[
module
]
=
nil
print
(
"Running component clip..."
)
disp
:
setColor
(
0
,
0x00
,
0xd1
,
0x5e
)
-- dark green
disp
:
setColor
(
1
,
0xff
,
0xf7
,
0x61
)
-- yellow
disp
:
setColor
(
2
,
0xd1
,
0xc7
,
0x00
)
-- dark yellow
disp
:
setColor
(
3
,
0x61
,
0xff
,
0xa8
)
-- green
disp
:
drawGradientBox
(
0
,
0
,
disp
:
getWidth
(),
disp
:
getHeight
())
disp
:
setColor
(
255
,
255
,
255
)
disp
:
setPrintPos
(
2
,
18
)
disp
:
setPrintDir
(
0
)
disp
:
print
(
"ClipRange"
)
disp
:
setColor
(
0xd1
,
0x00
,
0x073
)
disp
:
setFont
(
ucg
.
font_helvB18_hr
)
disp
:
setPrintPos
(
25
,
45
)
disp
:
setPrintDir
(
0
)
disp
:
print
(
"Ucg"
)
disp
:
setPrintDir
(
1
)
disp
:
print
(
"Ucg"
)
disp
:
setPrintDir
(
2
)
disp
:
print
(
"Ucg"
)
disp
:
setPrintDir
(
3
)
disp
:
print
(
"Ucg"
)
disp
:
setMaxClipRange
()
disp
:
setColor
(
0xff
,
0xff
,
0xff
)
disp
:
drawFrame
(
20
-
1
,
30
-
1
,
15
+
2
,
20
+
2
)
disp
:
setClipRange
(
20
,
30
,
15
,
20
)
disp
:
setColor
(
0xff
,
0x61
,
0x0b8
)
disp
:
setPrintPos
(
25
,
45
)
disp
:
setPrintDir
(
0
)
disp
:
print
(
"Ucg"
)
disp
:
setPrintDir
(
1
)
disp
:
print
(
"Ucg"
)
disp
:
setPrintDir
(
2
)
disp
:
print
(
"Ucg"
)
disp
:
setPrintDir
(
3
)
disp
:
print
(
"Ucg"
)
disp
:
setMaxClipRange
()
disp
:
setColor
(
0xff
,
0xff
,
0xff
)
disp
:
drawFrame
(
60
-
1
,
35
-
1
,
25
+
2
,
18
+
2
)
disp
:
setClipRange
(
60
,
35
,
25
,
18
)
disp
:
setColor
(
0xff
,
0x61
,
0x0b8
)
disp
:
setPrintPos
(
25
,
45
)
disp
:
setPrintDir
(
0
)
disp
:
print
(
"Ucg"
)
disp
:
setPrintDir
(
1
)
disp
:
print
(
"Ucg"
)
disp
:
setPrintDir
(
2
)
disp
:
print
(
"Ucg"
)
disp
:
setPrintDir
(
3
)
disp
:
print
(
"Ucg"
)
disp
:
setMaxClipRange
()
disp
:
setColor
(
0xff
,
0xff
,
0xff
)
disp
:
drawFrame
(
7
-
1
,
58
-
1
,
90
+
2
,
4
+
2
)
disp
:
setClipRange
(
7
,
58
,
90
,
4
)
disp
:
setColor
(
0xff
,
0x61
,
0x0b8
)
disp
:
setPrintPos
(
25
,
45
)
disp
:
setPrintDir
(
0
)
disp
:
print
(
"Ucg"
)
disp
:
setPrintDir
(
1
)
disp
:
print
(
"Ucg"
)
disp
:
setPrintDir
(
2
)
disp
:
print
(
"Ucg"
)
disp
:
setPrintDir
(
3
)
disp
:
print
(
"Ucg"
)
disp
:
setFont
(
ucg
.
font_ncenR14_hr
)
disp
:
setMaxClipRange
()
print
(
"...done"
)
end
return
M
lua_examples/ucglib/GT_color_test.lua
0 → 100644
View file @
5c93ba01
local
M
,
module
=
{},
...
_G
[
module
]
=
M
function
M
.
run
()
-- make this a volatile module:
package.loaded
[
module
]
=
nil
print
(
"Running component color_test..."
)
local
mx
local
c
,
x
mx
=
disp
:
getWidth
()
/
2
--my = disp:getHeight() / 2
disp
:
setColor
(
0
,
0
,
0
,
0
)
disp
:
drawBox
(
0
,
0
,
disp
:
getWidth
(),
disp
:
getHeight
())
disp
:
setColor
(
255
,
255
,
255
)
disp
:
setPrintPos
(
2
,
18
)
disp
:
setPrintDir
(
0
)
disp
:
print
(
"Color Test"
)
disp
:
setColor
(
0
,
127
,
127
,
127
)
disp
:
drawBox
(
0
,
20
,
16
*
4
+
4
,
5
*
8
+
4
)
c
=
0
x
=
2
while
c
<
255
do
disp
:
setColor
(
0
,
c
,
c
,
c
)
disp
:
drawBox
(
x
,
22
,
4
,
8
)
disp
:
setColor
(
0
,
c
,
0
,
0
)
disp
:
drawBox
(
x
,
22
+
8
,
4
,
8
)
disp
:
setColor
(
0
,
0
,
c
,
0
)
disp
:
drawBox
(
x
,
22
+
2
*
8
,
4
,
8
)
disp
:
setColor
(
0
,
0
,
0
,
c
)
disp
:
drawBox
(
x
,
22
+
3
*
8
,
4
,
8
)
disp
:
setColor
(
0
,
c
,
255
-
c
,
0
)
disp
:
drawBox
(
x
,
22
+
4
*
8
,
4
,
8
)
c
=
c
+
17
x
=
x
+
4
end
print
(
"...done"
)
end
return
M
lua_examples/ucglib/GT_cross.lua
0 → 100644
View file @
5c93ba01
local
M
,
module
=
{},
...
_G
[
module
]
=
M
function
M
.
run
()
-- make this a volatile module:
package.loaded
[
module
]
=
nil
print
(
"Running component cross..."
)
local
mx
,
my
disp
:
setColor
(
0
,
250
,
0
,
0
)
disp
:
setColor
(
1
,
255
,
255
,
30
)
disp
:
setColor
(
2
,
220
,
235
,
10
)
disp
:
setColor
(
3
,
205
,
0
,
30
)
disp
:
drawGradientBox
(
0
,
0
,
disp
:
getWidth
(),
disp
:
getHeight
())
mx
=
disp
:
getWidth
()
/
2
my
=
disp
:
getHeight
()
/
2
disp
:
setColor
(
0
,
255
,
255
,
255
)
disp
:
setPrintPos
(
2
,
18
)
disp
:
print
(
"Cross"
)
disp
:
setColor
(
0
,
0
,
0x66
,
0xcc
)
disp
:
setPrintPos
(
mx
+
15
,
my
-
5
)
disp
:
print
(
"dir0"
)
disp
:
setPrintPos
(
mx
+
5
,
my
+
26
)
disp
:
print
(
"dir1"
)
disp
:
setPrintPos
(
mx
-
40
,
my
+
20
)
disp
:
print
(
"dir2"
)
disp
:
setPrintPos
(
mx
+
5
,
my
-
25
)
disp
:
print
(
"dir3"
)
disp
:
setColor
(
0
,
0
,
0x66
,
0xff
)
disp
:
setColor
(
1
,
0
,
0x66
,
0xcc
)
disp
:
setColor
(
2
,
0
,
0
,
0x99
)
disp
:
draw90Line
(
mx
+
2
,
my
-
1
,
20
,
0
,
0
)
disp
:
draw90Line
(
mx
+
2
,
my
,
20
,
0
,
1
)
disp
:
draw90Line
(
mx
+
2
,
my
+
1
,
20
,
0
,
2
)
disp
:
draw90Line
(
mx
+
1
,
my
+
2
,
20
,
1
,
0
)
disp
:
draw90Line
(
mx
,
my
+
2
,
20
,
1
,
1
)
disp
:
draw90Line
(
mx
-
1
,
my
+
2
,
20
,
1
,
2
)
disp
:
draw90Line
(
mx
-
2
,
my
+
1
,
20
,
2
,
0
)
disp
:
draw90Line
(
mx
-
2
,
my
,
20
,
2
,
1
)
disp
:
draw90Line
(
mx
-
2
,
my
-
1
,
20
,
2
,
2
)
disp
:
draw90Line
(
mx
-
1
,
my
-
2
,
20
,
3
,
0
)
disp
:
draw90Line
(
mx
,
my
-
2
,
20
,
3
,
1
)
disp
:
draw90Line
(
mx
+
1
,
my
-
2
,
20
,
3
,
2
)
print
(
"...done"
)
end
return
M
lua_examples/ucglib/GT_fonts.lua
0 → 100644
View file @
5c93ba01
local
M
,
module
=
{},
...
_G
[
module
]
=
M
function
M
.
run
()
-- make this a volatile module:
package.loaded
[
module
]
=
nil
print
(
"Running component fonts..."
)
local
d
=
5
disp
:
setColor
(
0
,
0
,
40
,
80
)
disp
:
setColor
(
1
,
150
,
0
,
200
)
disp
:
setColor
(
2
,
60
,
0
,
40
)
disp
:
setColor
(
3
,
0
,
160
,
160
)
disp
:
drawGradientBox
(
0
,
0
,
disp
:
getWidth
(),
disp
:
getHeight
())
disp
:
setColor
(
255
,
255
,
255
)
disp
:
setPrintDir
(
0
)
disp
:
setPrintPos
(
2
,
18
)
disp
:
print
(
"Fonts"
)
disp
:
setFontMode
(
ucg
.
FONT_MODE_TRANSPARENT
)
disp
:
setColor
(
255
,
200
,
170
)
disp
:
setFont
(
ucg
.
font_helvB08_hr
)
disp
:
setPrintPos
(
2
,
30
+
d
)
disp
:
print
(
"ABC abc 123"
)
disp
:
setFont
(
ucg
.
font_helvB10_hr
)
disp
:
setPrintPos
(
2
,
45
+
d
)
disp
:
print
(
"ABC abc 123"
)
disp
:
setFont
(
ucg
.
font_helvB12_hr
)
--disp:setPrintPos(2,62+d)
--disp:print("ABC abc 123")
disp
:
drawString
(
2
,
62
+
d
,
0
,
"ABC abc 123"
)
-- test drawString
disp
:
setFontMode
(
ucg
.
FONT_MODE_SOLID
)
disp
:
setColor
(
255
,
200
,
170
)
disp
:
setColor
(
1
,
0
,
100
,
120
)
-- background color in solid mode
disp
:
setFont
(
ucg
.
font_helvB08_hr
)
disp
:
setPrintPos
(
2
,
75
+
30
+
d
)
disp
:
print
(
"ABC abc 123"
)
disp
:
setFont
(
ucg
.
font_helvB10_hr
)
disp
:
setPrintPos
(
2
,
75
+
45
+
d
)
disp
:
print
(
"ABC abc 123"
)
disp
:
setFont
(
ucg
.
font_helvB12_hr
)
disp
:
setPrintPos
(
2
,
75
+
62
+
d
)
disp
:
print
(
"ABC abc 123"
)
disp
:
setFontMode
(
ucg
.
FONT_MODE_TRANSPARENT
)
disp
:
setFont
(
ucg
.
font_ncenR14_hr
)
print
(
"...done"
)
end
return
M
lua_examples/ucglib/GT_gradient.lua
0 → 100644
View file @
5c93ba01
local
M
,
module
=
{},
...
_G
[
module
]
=
M
function
M
.
run
()
-- make this a volatile module:
package.loaded
[
module
]
=
nil
print
(
"Running component gradient..."
)
disp
:
setColor
(
0
,
0
,
255
,
0
)
disp
:
setColor
(
1
,
255
,
0
,
0
)
disp
:
setColor
(
2
,
255
,
0
,
255
)
disp
:
setColor
(
3
,
0
,
255
,
255
)
disp
:
drawGradientBox
(
0
,
0
,
disp
:
getWidth
(),
disp
:
getHeight
())
disp
:
setColor
(
255
,
255
,
255
)
disp
:
setPrintPos
(
2
,
18
)
disp
:
setPrintDir
(
0
)
disp
:
print
(
"GradientBox"
)
disp
:
setColor
(
0
,
0
,
255
,
0
)
disp
:
drawBox
(
2
,
25
,
8
,
8
)
disp
:
setColor
(
0
,
255
,
0
,
0
)
disp
:
drawBox
(
2
+
10
,
25
,
8
,
8
)
disp
:
setColor
(
0
,
255
,
0
,
255
)
disp
:
drawBox
(
2
,
25
+
10
,
8
,
8
)
disp
:
setColor
(
0
,
0
,
255
,
255
)
disp
:
drawBox
(
2
+
10
,
25
+
10
,
8
,
8
)
print
(
"...done"
)
end
return
M
lua_examples/ucglib/GT_graphics_test.lua
0 → 100644
View file @
5c93ba01
local
M
,
module
=
{},
...
_G
[
module
]
=
M
function
M
.
run
()
-- make this a volatile module:
package.loaded
[
module
]
=
nil
print
(
"Running component graphics_test..."
)
--ucg.setMaxClipRange()
disp
:
setColor
(
0
,
0
,
40
,
80
)
disp
:
setColor
(
1
,
80
,
0
,
40
)
disp
:
setColor
(
2
,
255
,
0
,
255
)
disp
:
setColor
(
3
,
0
,
255
,
255
)
disp
:
drawGradientBox
(
0
,
0
,
disp
:
getWidth
(),
disp
:
getHeight
())
disp
:
setColor
(
255
,
168
,
0
)
disp
:
setPrintDir
(
0
)
disp
:
setPrintPos
(
2
,
18
)
disp
:
print
(
"Ucglib"
)
disp
:
setPrintPos
(
2
,
18
+
20
)
disp
:
print
(
"GraphicsTest"
)
print
(
"...done"
)
end
return
M
lua_examples/ucglib/GT_pixel_and_lines.lua
0 → 100644
View file @
5c93ba01
local
M
,
module
=
{},
...
_G
[
module
]
=
M
function
M
.
run
()
-- make this a volatile module:
package.loaded
[
module
]
=
nil
print
(
"Running component pixel_and_lines..."
)
local
mx
local
x
,
xx
mx
=
disp
:
getWidth
()
/
2
--my = disp:getHeight() / 2
disp
:
setColor
(
0
,
0
,
0
,
150
)
disp
:
setColor
(
1
,
0
,
60
,
40
)
disp
:
setColor
(
2
,
60
,
0
,
40
)
disp
:
setColor
(
3
,
120
,
120
,
200
)
disp
:
drawGradientBox
(
0
,
0
,
disp
:
getWidth
(),
disp
:
getHeight
())
disp
:
setColor
(
255
,
255
,
255
)
disp
:
setPrintPos
(
2
,
18
)
disp
:
setPrintDir
(
0
)
disp
:
print
(
"Pix&Line"
)
disp
:
drawPixel
(
0
,
0
)
disp
:
drawPixel
(
1
,
0
)
--disp:drawPixel(disp:getWidth()-1, 0)
--disp:drawPixel(0, disp:getHeight()-1)
disp
:
drawPixel
(
disp
:
getWidth
()
-
1
,
disp
:
getHeight
()
-
1
)
disp
:
drawPixel
(
disp
:
getWidth
()
-
1
-
1
,
disp
:
getHeight
()
-
1
)
x
=
0
while
x
<
mx
do
xx
=
((
x
)
*
255
)
/
mx
disp
:
setColor
(
255
,
255
-
xx
/
2
,
255
-
xx
)
disp
:
drawPixel
(
x
,
24
)
disp
:
drawVLine
(
x
+
7
,
26
,
13
)
x
=
x
+
1
end
print
(
"...done"
)
end
return
M
lua_examples/ucglib/GT_text.lua
0 → 100644
View file @
5c93ba01
local
M
,
module
=
{},
...
_G
[
module
]
=
M
function
M
.
run
()
-- make this a volatile module:
package.loaded
[
module
]
=
nil
print
(
"Running component text..."
)
local
x
,
y
,
w
,
h
,
i
local
m
disp
:
setColor
(
0
,
80
,
40
,
0
)
disp
:
setColor
(
1
,
60
,
0
,
40
)
disp
:
setColor
(
2
,
20
,
0
,
20
)
disp
:
setColor
(
3
,
60
,
0
,
0
)
disp
:
drawGradientBox
(
0
,
0
,
disp
:
getWidth
(),
disp
:
getHeight
())
disp
:
setColor
(
255
,
255
,
255
)
disp
:
setPrintPos
(
2
,
18
)
disp
:
setPrintDir
(
0
)
disp
:
print
(
"Text"
)
m
=
millis
()
+
T
i
=
0
while
millis
()
<
m
do
disp
:
setColor
(
bit
.
band
(
lcg_rnd
(),
31
),
bit
.
band
(
lcg_rnd
(),
127
)
+
127
,
bit
.
band
(
lcg_rnd
(),
127
)
+
64
)
w
=
40
h
=
22
x
=
bit
.
rshift
(
lcg_rnd
()
*
(
disp
:
getWidth
()
-
w
),
8
)
y
=
bit
.
rshift
(
lcg_rnd
()
*
(
disp
:
getHeight
()
-
h
),
8
)
disp
:
setPrintPos
(
x
,
y
+
h
)
disp
:
setPrintDir
(
bit
.
band
(
bit
.
rshift
(
i
,
2
),
3
))
i
=
i
+
1
disp
:
print
(
"Ucglib"
)
end
disp
:
setPrintDir
(
0
)
print
(
"...done"
)
end
return
M
lua_examples/ucglib/GT_triangle.lua
0 → 100644
View file @
5c93ba01
local
M
,
module
=
{},
...
_G
[
module
]
=
M
function
M
.
run
()
-- make this a volatile module:
package.loaded
[
module
]
=
nil
print
(
"Running component triangle..."
)
local
m
disp
:
setColor
(
0
,
0
,
80
,
20
)
disp
:
setColor
(
1
,
60
,
80
,
20
)
disp
:
setColor
(
2
,
60
,
120
,
0
)
disp
:
setColor
(
3
,
0
,
140
,
30
)
disp
:
drawGradientBox
(
0
,
0
,
disp
:
getWidth
(),
disp
:
getHeight
())
disp
:
setColor
(
255
,
255
,
255
)
disp
:
setPrintPos
(
2
,
18
)
disp
:
print
(
"Triangle"
)
m
=
millis
()
+
T
while
millis
()
<
m
do
disp
:
setColor
(
bit
.
band
(
lcg_rnd
(),
127
)
+
127
,
bit
.
band
(
lcg_rnd
(),
31
),
bit
.
band
(
lcg_rnd
(),
127
)
+
64
)
disp
:
drawTriangle
(
bit
.
rshift
(
lcg_rnd
()
*
(
disp
:
getWidth
()),
8
),
bit
.
rshift
(
lcg_rnd
()
*
(
disp
:
getHeight
()
-
20
),
8
)
+
20
,
bit
.
rshift
(
lcg_rnd
()
*
(
disp
:
getWidth
()),
8
),
bit
.
rshift
(
lcg_rnd
()
*
(
disp
:
getHeight
()
-
20
),
8
)
+
20
,
bit
.
rshift
(
lcg_rnd
()
*
(
disp
:
getWidth
()),
8
),
bit
.
rshift
(
lcg_rnd
()
*
(
disp
:
getHeight
()
-
20
),
8
)
+
20
)
tmr
.
wdclr
()
end
print
(
"...done"
)
end
return
M
lua_examples/ucglib/GraphicsTest.lua
View file @
5c93ba01
...
...
@@ -46,223 +46,11 @@ function lcg_rnd()
end
function
ucglib_graphics_test
()
--ucg.setMaxClipRange()
disp
:
setColor
(
0
,
0
,
40
,
80
)
disp
:
setColor
(
1
,
80
,
0
,
40
)
disp
:
setColor
(
2
,
255
,
0
,
255
)
disp
:
setColor
(
3
,
0
,
255
,
255
)
disp
:
drawGradientBox
(
0
,
0
,
disp
:
getWidth
(),
disp
:
getHeight
())
disp
:
setColor
(
255
,
168
,
0
)
disp
:
setPrintDir
(
0
)
disp
:
setPrintPos
(
2
,
18
)
disp
:
print
(
"Ucglib"
)
disp
:
setPrintPos
(
2
,
18
+
20
)
disp
:
print
(
"GraphicsTest"
)
end
function
cross
()
local
mx
,
my
disp
:
setColor
(
0
,
250
,
0
,
0
)
disp
:
setColor
(
1
,
255
,
255
,
30
)
disp
:
setColor
(
2
,
220
,
235
,
10
)
disp
:
setColor
(
3
,
205
,
0
,
30
)
disp
:
drawGradientBox
(
0
,
0
,
disp
:
getWidth
(),
disp
:
getHeight
())
mx
=
disp
:
getWidth
()
/
2
my
=
disp
:
getHeight
()
/
2
disp
:
setColor
(
0
,
255
,
255
,
255
)
disp
:
setPrintPos
(
2
,
18
)
disp
:
print
(
"Cross"
)
disp
:
setColor
(
0
,
0
,
0x66
,
0xcc
)
disp
:
setPrintPos
(
mx
+
15
,
my
-
5
)
disp
:
print
(
"dir0"
)
disp
:
setPrintPos
(
mx
+
5
,
my
+
26
)
disp
:
print
(
"dir1"
)
disp
:
setPrintPos
(
mx
-
40
,
my
+
20
)
disp
:
print
(
"dir2"
)
disp
:
setPrintPos
(
mx
+
5
,
my
-
25
)
disp
:
print
(
"dir3"
)
disp
:
setColor
(
0
,
0
,
0x66
,
0xff
)
disp
:
setColor
(
1
,
0
,
0x66
,
0xcc
)
disp
:
setColor
(
2
,
0
,
0
,
0x99
)
disp
:
draw90Line
(
mx
+
2
,
my
-
1
,
20
,
0
,
0
)
disp
:
draw90Line
(
mx
+
2
,
my
,
20
,
0
,
1
)
disp
:
draw90Line
(
mx
+
2
,
my
+
1
,
20
,
0
,
2
)
disp
:
draw90Line
(
mx
+
1
,
my
+
2
,
20
,
1
,
0
)
disp
:
draw90Line
(
mx
,
my
+
2
,
20
,
1
,
1
)
disp
:
draw90Line
(
mx
-
1
,
my
+
2
,
20
,
1
,
2
)
disp
:
draw90Line
(
mx
-
2
,
my
+
1
,
20
,
2
,
0
)
disp
:
draw90Line
(
mx
-
2
,
my
,
20
,
2
,
1
)
disp
:
draw90Line
(
mx
-
2
,
my
-
1
,
20
,
2
,
2
)
disp
:
draw90Line
(
mx
-
1
,
my
-
2
,
20
,
3
,
0
)
disp
:
draw90Line
(
mx
,
my
-
2
,
20
,
3
,
1
)
disp
:
draw90Line
(
mx
+
1
,
my
-
2
,
20
,
3
,
2
)
end
function
pixel_and_lines
()
local
mx
local
x
,
xx
mx
=
disp
:
getWidth
()
/
2
--my = disp:getHeight() / 2
disp
:
setColor
(
0
,
0
,
0
,
150
)
disp
:
setColor
(
1
,
0
,
60
,
40
)
disp
:
setColor
(
2
,
60
,
0
,
40
)
disp
:
setColor
(
3
,
120
,
120
,
200
)
disp
:
drawGradientBox
(
0
,
0
,
disp
:
getWidth
(),
disp
:
getHeight
())
disp
:
setColor
(
255
,
255
,
255
)
disp
:
setPrintPos
(
2
,
18
)
disp
:
setPrintDir
(
0
)
disp
:
print
(
"Pix&Line"
)
disp
:
drawPixel
(
0
,
0
)
disp
:
drawPixel
(
1
,
0
)
--disp:drawPixel(disp:getWidth()-1, 0)
--disp:drawPixel(0, disp:getHeight()-1)
disp
:
drawPixel
(
disp
:
getWidth
()
-
1
,
disp
:
getHeight
()
-
1
)
disp
:
drawPixel
(
disp
:
getWidth
()
-
1
-
1
,
disp
:
getHeight
()
-
1
)
x
=
0
while
x
<
mx
do
xx
=
((
x
)
*
255
)
/
mx
disp
:
setColor
(
255
,
255
-
xx
/
2
,
255
-
xx
)
disp
:
drawPixel
(
x
,
24
)
disp
:
drawVLine
(
x
+
7
,
26
,
13
)
x
=
x
+
1
end
end
function
color_test
()
local
mx
local
c
,
x
mx
=
disp
:
getWidth
()
/
2
--my = disp:getHeight() / 2
disp
:
setColor
(
0
,
0
,
0
,
0
)
disp
:
drawBox
(
0
,
0
,
disp
:
getWidth
(),
disp
:
getHeight
())
disp
:
setColor
(
255
,
255
,
255
)
disp
:
setPrintPos
(
2
,
18
)
disp
:
setPrintDir
(
0
)
disp
:
print
(
"Color Test"
)
disp
:
setColor
(
0
,
127
,
127
,
127
)
disp
:
drawBox
(
0
,
20
,
16
*
4
+
4
,
5
*
8
+
4
)
c
=
0
x
=
2
while
c
<
255
do
disp
:
setColor
(
0
,
c
,
c
,
c
)
disp
:
drawBox
(
x
,
22
,
4
,
8
)
disp
:
setColor
(
0
,
c
,
0
,
0
)
disp
:
drawBox
(
x
,
22
+
8
,
4
,
8
)
disp
:
setColor
(
0
,
0
,
c
,
0
)
disp
:
drawBox
(
x
,
22
+
2
*
8
,
4
,
8
)
disp
:
setColor
(
0
,
0
,
0
,
c
)
disp
:
drawBox
(
x
,
22
+
3
*
8
,
4
,
8
)
disp
:
setColor
(
0
,
c
,
255
-
c
,
0
)
disp
:
drawBox
(
x
,
22
+
4
*
8
,
4
,
8
)
c
=
c
+
17
x
=
x
+
4
end
end
function
millis
()
local
usec
=
tmr
.
now
()
return
usec
/
1000
end
function
triangle
()
local
m
disp
:
setColor
(
0
,
0
,
80
,
20
)
disp
:
setColor
(
1
,
60
,
80
,
20
)
disp
:
setColor
(
2
,
60
,
120
,
0
)
disp
:
setColor
(
3
,
0
,
140
,
30
)
disp
:
drawGradientBox
(
0
,
0
,
disp
:
getWidth
(),
disp
:
getHeight
())
disp
:
setColor
(
255
,
255
,
255
)
disp
:
setPrintPos
(
2
,
18
)
disp
:
print
(
"Triangle"
)
m
=
millis
()
+
T
while
millis
()
<
m
do
disp
:
setColor
(
bit
.
band
(
lcg_rnd
(),
127
)
+
127
,
bit
.
band
(
lcg_rnd
(),
31
),
bit
.
band
(
lcg_rnd
(),
127
)
+
64
)
disp
:
drawTriangle
(
bit
.
rshift
(
lcg_rnd
()
*
(
disp
:
getWidth
()),
8
),
bit
.
rshift
(
lcg_rnd
()
*
(
disp
:
getHeight
()
-
20
),
8
)
+
20
,
bit
.
rshift
(
lcg_rnd
()
*
(
disp
:
getWidth
()),
8
),
bit
.
rshift
(
lcg_rnd
()
*
(
disp
:
getHeight
()
-
20
),
8
)
+
20
,
bit
.
rshift
(
lcg_rnd
()
*
(
disp
:
getWidth
()),
8
),
bit
.
rshift
(
lcg_rnd
()
*
(
disp
:
getHeight
()
-
20
),
8
)
+
20
)
tmr
.
wdclr
()
end
end
function
fonts
()
local
d
=
5
disp
:
setColor
(
0
,
0
,
40
,
80
)
disp
:
setColor
(
1
,
150
,
0
,
200
)
disp
:
setColor
(
2
,
60
,
0
,
40
)
disp
:
setColor
(
3
,
0
,
160
,
160
)
disp
:
drawGradientBox
(
0
,
0
,
disp
:
getWidth
(),
disp
:
getHeight
())
disp
:
setColor
(
255
,
255
,
255
)
disp
:
setPrintDir
(
0
)
disp
:
setPrintPos
(
2
,
18
)
disp
:
print
(
"Fonts"
)
disp
:
setFontMode
(
ucg
.
FONT_MODE_TRANSPARENT
)
disp
:
setColor
(
255
,
200
,
170
)
disp
:
setFont
(
ucg
.
font_helvB08_hr
)
disp
:
setPrintPos
(
2
,
30
+
d
)
disp
:
print
(
"ABC abc 123"
)
disp
:
setFont
(
ucg
.
font_helvB10_hr
)
disp
:
setPrintPos
(
2
,
45
+
d
)
disp
:
print
(
"ABC abc 123"
)
disp
:
setFont
(
ucg
.
font_helvB12_hr
)
--disp:setPrintPos(2,62+d)
--disp:print("ABC abc 123")
disp
:
drawString
(
2
,
62
+
d
,
0
,
"ABC abc 123"
)
-- test drawString
disp
:
setFontMode
(
ucg
.
FONT_MODE_SOLID
)
disp
:
setColor
(
255
,
200
,
170
)
disp
:
setColor
(
1
,
0
,
100
,
120
)
-- background color in solid mode
disp
:
setFont
(
ucg
.
font_helvB08_hr
)
disp
:
setPrintPos
(
2
,
75
+
30
+
d
)
disp
:
print
(
"ABC abc 123"
)
disp
:
setFont
(
ucg
.
font_helvB10_hr
)
disp
:
setPrintPos
(
2
,
75
+
45
+
d
)
disp
:
print
(
"ABC abc 123"
)
disp
:
setFont
(
ucg
.
font_helvB12_hr
)
disp
:
setPrintPos
(
2
,
75
+
62
+
d
)
disp
:
print
(
"ABC abc 123"
)
disp
:
setFontMode
(
ucg
.
FONT_MODE_TRANSPARENT
)
disp
:
setFont
(
ucg
.
font_ncenR14_hr
)
end
function
set_clip_range
()
local
x
,
y
,
w
,
h
w
=
bit
.
band
(
lcg_rnd
(),
31
)
...
...
@@ -295,20 +83,27 @@ function loop()
switch
(
loop_idx
)
:
caseof
{
[
0
]
=
function
()
end
,
[
1
]
=
function
()
ucglib_graphics_test
()
end
,
[
2
]
=
function
()
cross
()
end
,
[
3
]
=
function
()
pixel_and_lines
()
end
,
[
4
]
=
function
()
color_test
()
end
,
[
5
]
=
function
()
triangle
()
end
,
[
6
]
=
function
()
fonts
()
end
,
[
1
]
=
function
()
require
(
"GT_graphics_test"
).
run
()
end
,
[
2
]
=
function
()
require
(
"GT_cross"
).
run
()
end
,
[
3
]
=
function
()
require
(
"GT_pixel_and_lines"
).
run
()
end
,
[
4
]
=
function
()
require
(
"GT_color_test"
).
run
()
end
,
[
5
]
=
function
()
require
(
"GT_triangle"
).
run
()
end
,
[
6
]
=
function
()
require
(
"GT_fonts"
).
run
()
end
,
[
7
]
=
function
()
require
(
"GT_text"
).
run
()
end
,
[
8
]
=
function
()
if
r
<=
3
then
require
(
"GT_clip"
).
run
()
end
end
,
[
9
]
=
function
()
require
(
"GT_box"
).
run
()
end
,
[
10
]
=
function
()
require
(
"GT_gradient"
).
run
()
end
,
[
11
]
=
function
()
disp
:
setMaxClipRange
()
end
,
default
=
function
()
loop_idx
=
-
1
end
}
loop_idx
=
loop_idx
+
1
print
(
"Heap: "
..
node
.
heap
())
end
T
=
1
5
00
T
=
1
0
00
r
=
0
loop_idx
=
0
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment