Skip to content

Commit de2539f

Browse files
committed
first release
1 parent ebcaf77 commit de2539f

7 files changed

Lines changed: 334 additions & 1 deletion

File tree

README.md

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,51 @@
1-
# ScrollText
1+
# ScrollText
2+
3+
makecode ScrollText package for micro:bit, it may show a scroll text in four direction with custom speed.
4+
5+
Author: shaoziyang
6+
Date: 2018.Octo
7+
8+
![](https://raw.githubusercontent.com/microbit-makecode-packages/ScrollText/master/icon.png)
9+
10+
11+
## usage
12+
13+
open your microbit makecode project, in Add Package, paste
14+
15+
https://github.com/microbit-makecode-packages/ScrollText
16+
17+
to search box then search.
18+
19+
20+
## API
21+
22+
- **showString(s: string, dir: SCROLL_DIR, delay: number)**
23+
show a scroll string
24+
s: string
25+
dir: scroll direction
26+
delay: display speed
27+
28+
- **showNumber(n: number, dir: SCROLL_DIR, delay: number)**
29+
show a scroll number
30+
n: number
31+
dir: scroll direction
32+
delay: display speed
33+
34+
## Demo
35+
36+
![](https://raw.githubusercontent.com/microbit-makecode-packages/ScrollText/master/demo.png)
37+
38+
![](https://raw.githubusercontent.com/microbit-makecode-packages/ScrollText/master/demo.gif)
39+
40+
## License
41+
42+
MIT
43+
44+
Copyright (c) 2018, microbit/micropython Chinese community
45+
46+
## Supported targets
47+
48+
* for PXT/microbit
49+
50+
51+
[From microbit/micropython Chinese community](http://www.micropython.org.cn)

demo.gif

365 KB
Loading

demo.png

28.6 KB
Loading

docs/static/libs/tropic.png

26.9 KB
Loading

main.ts

Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
/**
2+
* microbit makecode Package: Scroll Text.
3+
* From microbit/micropython Chinese community.
4+
* http://www.micropython.org.cn
5+
*/
6+
7+
enum SCROLL_DIR {
8+
LEFT,
9+
UP,
10+
RIGHT,
11+
DOWN
12+
}
13+
14+
//% weight=100 color=#Ffbc11 icon="T" block="ScrollText"
15+
namespace ScrolText {
16+
let FONTS = [
17+
[0x00, 0x00, 0x00, 0x00, 0x00], //0:
18+
[0x00, 0x00, 0x00, 0x00, 0x00], //1:
19+
[0x00, 0x00, 0x00, 0x00, 0x00], //2:
20+
[0x00, 0x00, 0x00, 0x00, 0x00], //3:
21+
[0x00, 0x00, 0x00, 0x00, 0x00], //4:
22+
[0x00, 0x00, 0x00, 0x00, 0x00], //5:
23+
[0x00, 0x00, 0x00, 0x00, 0x00], //6:
24+
[0x00, 0x00, 0x00, 0x00, 0x00], //7:
25+
[0x00, 0x00, 0x00, 0x00, 0x00], //8:
26+
[0x00, 0x00, 0x00, 0x00, 0x00], //9:
27+
[0x00, 0x00, 0x00, 0x00, 0x00], //10:
28+
[0x00, 0x00, 0x00, 0x00, 0x00], //11:
29+
[0x00, 0x00, 0x00, 0x00, 0x00], //12:
30+
[0x00, 0x00, 0x00, 0x00, 0x00], //13:
31+
[0x00, 0x00, 0x00, 0x00, 0x00], //14:
32+
[0x00, 0x00, 0x00, 0x00, 0x00], //15:
33+
[0x00, 0x00, 0x00, 0x00, 0x00], //16:
34+
[0x00, 0x00, 0x00, 0x00, 0x00], //17:
35+
[0x00, 0x00, 0x00, 0x00, 0x00], //18:
36+
[0x00, 0x00, 0x00, 0x00, 0x00], //19:
37+
[0x00, 0x00, 0x00, 0x00, 0x00], //20:
38+
[0x00, 0x00, 0x00, 0x00, 0x00], //21:
39+
[0x00, 0x00, 0x00, 0x00, 0x00], //22:
40+
[0x00, 0x00, 0x00, 0x00, 0x00], //23:
41+
[0x00, 0x00, 0x00, 0x00, 0x00], //24:
42+
[0x00, 0x00, 0x00, 0x00, 0x00], //25:
43+
[0x00, 0x00, 0x00, 0x00, 0x00], //26:
44+
[0x00, 0x00, 0x00, 0x00, 0x00], //27:
45+
[0x00, 0x00, 0x00, 0x00, 0x00], //28:
46+
[0x00, 0x00, 0x00, 0x00, 0x00], //29:
47+
[0x00, 0x00, 0x00, 0x00, 0x00], //30:
48+
[0x00, 0x00, 0x00, 0x00, 0x00], //31:
49+
[0x00, 0x00, 0x00, 0x00, 0x00], //32:
50+
[0x02, 0x02, 0x02, 0x00, 0x02], //33: !
51+
[0x0A, 0x0A, 0x00, 0x00, 0x00], //34: "
52+
[0x0A, 0x1F, 0x0A, 0x1F, 0x0A], //35: #
53+
[0x0E, 0x13, 0x0E, 0x19, 0x0E], //36: $
54+
[0x13, 0x09, 0x04, 0x12, 0x19], //37: %
55+
[0x06, 0x09, 0x06, 0x09, 0x16], //38: &
56+
[0x02, 0x02, 0x00, 0x00, 0x00], //39: '
57+
[0x04, 0x02, 0x02, 0x02, 0x04], //40: (
58+
[0x02, 0x04, 0x04, 0x04, 0x02], //41: )
59+
[0x00, 0x0A, 0x04, 0x0A, 0x00], //42: *
60+
[0x00, 0x04, 0x0E, 0x04, 0x00], //43: +
61+
[0x00, 0x00, 0x00, 0x04, 0x02], //44: ,
62+
[0x00, 0x00, 0x0E, 0x00, 0x00], //45: -
63+
[0x00, 0x00, 0x00, 0x02, 0x00], //46: .
64+
[0x10, 0x08, 0x04, 0x02, 0x01], //47: /
65+
[0x06, 0x09, 0x09, 0x09, 0x06], //48: 0
66+
[0x04, 0x06, 0x04, 0x04, 0x0E], //49: 1
67+
[0x07, 0x08, 0x06, 0x01, 0x0F], //50: 2
68+
[0x0F, 0x08, 0x04, 0x09, 0x06], //51: 3
69+
[0x0C, 0x0A, 0x09, 0x1F, 0x08], //52: 4
70+
[0x1F, 0x01, 0x0F, 0x10, 0x0F], //53: 5
71+
[0x08, 0x04, 0x0E, 0x11, 0x0E], //54: 6
72+
[0x1F, 0x08, 0x04, 0x02, 0x01], //55: 7
73+
[0x0E, 0x11, 0x0E, 0x11, 0x0E], //56: 8
74+
[0x0E, 0x11, 0x0E, 0x04, 0x02], //57: 9
75+
[0x00, 0x02, 0x00, 0x02, 0x00], //58: :
76+
[0x00, 0x04, 0x00, 0x04, 0x02], //59: ;
77+
[0x08, 0x04, 0x02, 0x04, 0x08], //60: <
78+
[0x00, 0x0E, 0x00, 0x0E, 0x00], //61: =
79+
[0x02, 0x04, 0x08, 0x04, 0x02], //62: >
80+
[0x0E, 0x11, 0x0C, 0x00, 0x04], //63: ?
81+
[0x0E, 0x11, 0x15, 0x19, 0x06], //64: @
82+
[0x06, 0x09, 0x0F, 0x09, 0x09], //65: A
83+
[0x07, 0x09, 0x07, 0x09, 0x07], //66: B
84+
[0x0E, 0x01, 0x01, 0x01, 0x0E], //67: C
85+
[0x07, 0x09, 0x09, 0x09, 0x07], //68: D
86+
[0x0F, 0x01, 0x07, 0x01, 0x0F], //69: E
87+
[0x0F, 0x01, 0x07, 0x01, 0x01], //70: F
88+
[0x0E, 0x01, 0x19, 0x11, 0x0E], //71: G
89+
[0x09, 0x09, 0x0F, 0x09, 0x09], //72: H
90+
[0x07, 0x02, 0x02, 0x02, 0x07], //73: I
91+
[0x1F, 0x08, 0x08, 0x09, 0x06], //74: J
92+
[0x09, 0x05, 0x03, 0x05, 0x09], //75: K
93+
[0x01, 0x01, 0x01, 0x01, 0x0F], //76: L
94+
[0x11, 0x1B, 0x15, 0x11, 0x11], //77: M
95+
[0x11, 0x13, 0x15, 0x19, 0x11], //78: N
96+
[0x06, 0x09, 0x09, 0x09, 0x06], //79: O
97+
[0x07, 0x09, 0x07, 0x01, 0x01], //80: P
98+
[0x06, 0x09, 0x09, 0x06, 0x0C], //81: Q
99+
[0x07, 0x09, 0x07, 0x09, 0x11], //82: R
100+
[0x0E, 0x01, 0x06, 0x08, 0x07], //83: S
101+
[0x1F, 0x04, 0x04, 0x04, 0x04], //84: T
102+
[0x09, 0x09, 0x09, 0x09, 0x06], //85: U
103+
[0x11, 0x11, 0x11, 0x0A, 0x04], //86: V
104+
[0x11, 0x11, 0x15, 0x1B, 0x11], //87: W
105+
[0x09, 0x09, 0x06, 0x09, 0x09], //88: X
106+
[0x11, 0x0A, 0x04, 0x04, 0x04], //89: Y
107+
[0x0F, 0x04, 0x02, 0x01, 0x0F], //90: Z
108+
[0x0E, 0x02, 0x02, 0x02, 0x0E], //91: [
109+
[0x01, 0x02, 0x04, 0x08, 0x10], //92: \
110+
[0x0E, 0x08, 0x08, 0x08, 0x0E], //93: ]
111+
[0x04, 0x0A, 0x00, 0x00, 0x00], //94: ^
112+
[0x00, 0x00, 0x00, 0x00, 0x1F], //95: _
113+
[0x02, 0x04, 0x00, 0x00, 0x00], //96: `
114+
[0x00, 0x0E, 0x09, 0x09, 0x1E], //97: a
115+
[0x01, 0x01, 0x07, 0x09, 0x07], //98: b
116+
[0x00, 0x0E, 0x01, 0x01, 0x0E], //99: c
117+
[0x08, 0x08, 0x0E, 0x09, 0x0E], //100: d
118+
[0x06, 0x09, 0x07, 0x01, 0x0E], //101: e
119+
[0x0C, 0x02, 0x07, 0x02, 0x02], //102: f
120+
[0x0E, 0x09, 0x0E, 0x08, 0x06], //103: g
121+
[0x01, 0x01, 0x07, 0x09, 0x09], //104: h
122+
[0x02, 0x00, 0x02, 0x02, 0x02], //105: i
123+
[0x08, 0x00, 0x08, 0x08, 0x06], //106: j
124+
[0x01, 0x05, 0x03, 0x05, 0x09], //107: k
125+
[0x02, 0x02, 0x02, 0x02, 0x0C], //108: l
126+
[0x00, 0x1B, 0x15, 0x11, 0x11], //109: m
127+
[0x00, 0x07, 0x09, 0x09, 0x09], //110: n
128+
[0x00, 0x06, 0x09, 0x09, 0x06], //111: o
129+
[0x00, 0x07, 0x09, 0x07, 0x01], //112: p
130+
[0x00, 0x0E, 0x09, 0x0E, 0x08], //113: q
131+
[0x00, 0x0E, 0x01, 0x01, 0x01], //114: r
132+
[0x00, 0x0C, 0x02, 0x04, 0x03], //115: s
133+
[0x02, 0x02, 0x0E, 0x02, 0x1C], //116: t
134+
[0x00, 0x09, 0x09, 0x09, 0x1E], //117: u
135+
[0x00, 0x11, 0x11, 0x0A, 0x04], //118: v
136+
[0x00, 0x11, 0x11, 0x15, 0x1B], //119: w
137+
[0x00, 0x09, 0x06, 0x06, 0x09], //120: x
138+
[0x00, 0x11, 0x0A, 0x04, 0x03], //121: y
139+
[0x00, 0x0F, 0x04, 0x02, 0x0F], //122: z
140+
[0x0C, 0x04, 0x06, 0x04, 0x0C], //123: {
141+
[0x02, 0x02, 0x02, 0x02, 0x02], //124: |
142+
[0x03, 0x02, 0x06, 0x02, 0x03], //125: }
143+
[0x00, 0x00, 0x06, 0x18, 0x00], //126: ~
144+
[0x00, 0x00, 0x00, 0x00, 0x00] //127:
145+
]
146+
let img: Image = null
147+
img = images.createImage(`
148+
. . . . .
149+
. . . . .
150+
. . . . .
151+
. . . . .
152+
. . . . .
153+
`)
154+
155+
function DatToImg(dat: number[]): void {
156+
for (let i = 0; i < 5; i++) {
157+
img.setPixel(0, i, (dat[i] & 0x01) == 0x01)
158+
img.setPixel(1, i, (dat[i] & 0x02) == 0x02)
159+
img.setPixel(2, i, (dat[i] & 0x04) == 0x04)
160+
img.setPixel(3, i, (dat[i] & 0x08) == 0x08)
161+
img.setPixel(4, i, (dat[i] & 0x10) == 0x10)
162+
}
163+
}
164+
165+
/**
166+
* show a scroll string
167+
* @param s , eg: "Hello"
168+
* @param dir , eg: SCROLL_DIR.LEFT
169+
* @param delay , eg: 100
170+
*/
171+
//% blockId="SCROLL_SHOWSTRING" block="scroll string %s|dir %dir|delay %delay"
172+
//% weight=100 blockGap=8
173+
export function showString(s: string, dir: SCROLL_DIR, delay: number): void {
174+
let L = s.length + 1
175+
let a = FONTS[0]
176+
let b = FONTS[0]
177+
178+
if (s == '')
179+
return
180+
181+
s = ' ' + s + ' '
182+
183+
switch (dir) {
184+
case SCROLL_DIR.LEFT:
185+
for (let i = 0; i < L; i++) {
186+
a = FONTS[s.charCodeAt(i)]
187+
b = FONTS[s.charCodeAt(i + 1)]
188+
let c: number[] = [0, 0, 0, 0, 0]
189+
for (let j = 0; j < 5; j++) {
190+
for (let k = 0; k < 5; k++)
191+
c[k] = (a[k] >> j) | ((b[k] << (8 - j)) >> 3)
192+
DatToImg(c)
193+
img.showImage(0, delay)
194+
}
195+
}
196+
break;
197+
case SCROLL_DIR.RIGHT:
198+
for (let i = 0; i < L; i++) {
199+
a = FONTS[s.charCodeAt(i)]
200+
b = FONTS[s.charCodeAt(i + 1)]
201+
let c: number[] = [0, 0, 0, 0, 0]
202+
for (let j = 0; j < 5; j++) {
203+
for (let k = 0; k < 5; k++)
204+
c[k] = (a[k] << j) | ((b[k] >> (5 - j)))
205+
DatToImg(c)
206+
img.showImage(0, delay)
207+
}
208+
}
209+
break;
210+
case SCROLL_DIR.UP:
211+
for (let i = 0; i < L; i++) {
212+
a = FONTS[s.charCodeAt(i)]
213+
b = FONTS[s.charCodeAt(i + 1)]
214+
let c: number[] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
215+
for (let j = 0; j < 5; j++) {
216+
c[j] = a[j]
217+
c[j + 6] = b[j]
218+
}
219+
for (let j = 0; j < 6; j++) {
220+
DatToImg(c)
221+
img.showImage(0, delay)
222+
c.removeAt(0)
223+
}
224+
}
225+
break;
226+
case SCROLL_DIR.DOWN:
227+
for (let i = 0; i < L; i++) {
228+
a = FONTS[s.charCodeAt(i)]
229+
b = FONTS[s.charCodeAt(i + 1)]
230+
let c: number[] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
231+
for (let j = 0; j < 5; j++) {
232+
c[j] = a[j]
233+
c[j + 6] = b[j]
234+
}
235+
for (let j = 0; j < 6; j++) {
236+
DatToImg(c)
237+
img.showImage(0, delay)
238+
for (let k = 5; k > 0; k--) {
239+
c[k] = c[k - 1]
240+
}
241+
c[0] = c[11 - j]
242+
}
243+
}
244+
break;
245+
}
246+
}
247+
248+
/**
249+
* show a scroll number
250+
* @param n , eg: 123
251+
* @param dir , eg: SCROLL_DIR.LEFT
252+
* @param delay , eg: 100
253+
*/
254+
//% blockId="SCROLL_SHOWNUMBER" block="scroll number %n|dir %dir|delay %delay"
255+
//% weight=100 blockGap=8
256+
export function showNumber(n: number, dir: SCROLL_DIR, delay: number): void {
257+
showString(n.toString(), dir, delay)
258+
}
259+
}

pxt.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "ScrollText",
3+
"version": "1.0.0",
4+
"description": "makecode ScrollText Package for micro:bit",
5+
"icon": "./static/libs/tropic.png",
6+
"license": "MIT",
7+
"dependencies": {
8+
"core": "*"
9+
},
10+
"files": [
11+
"README.md",
12+
"main.ts"
13+
],
14+
"testFiles": [
15+
"test.ts"
16+
],
17+
"public": true
18+
}

test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
basic.forever(function () {
2+
ScrolText.showString("Hello", SCROLL_DIR.LEFT, 100)
3+
ScrolText.showString("Hello", SCROLL_DIR.UP, 100)
4+
ScrolText.showString("Hello", SCROLL_DIR.RIGHT, 100)
5+
ScrolText.showString("Hello", SCROLL_DIR.DOWN, 100)
6+
})

0 commit comments

Comments
 (0)