-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathturtle.fs
94 lines (81 loc) · 1.94 KB
/
turtle.fs
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
\ Turtle graphics for the bitkanone
\ (c)copyright 2016 by Gerald Wodni<[email protected]>
compiletoflash
\ turtle position and color
0 variable tx
0 variable ty
$202020 variable tc
\ turtle offsets
0 variable tox
0 variable toy
\ set turtle position
: pos ( x y -- )
ty ! tx ! ;
\ set turtle color
: color ( d-rgb -- )
tc ! ;
\ draw dot
: dot ( -- )
tc @ tx @ tox @ +
ty @ toy @ + xy! ;
\ order 2 number descending, increment higher
: desc1+ ( u1 u2 -- u3 u4 )
2dup < if swap then swap 1+ swap ;
\ draw orthogonal line
: line ( to-x to-y -- )
2dup \ save end point
dup ty @ = if
\ horizontal line
drop
tx @ desc1+ ?do
i tx ! dot
loop
else
\ vertical line
nip
ty @ desc1+ ?do
i ty ! dot
loop
then pos ; \ save new position
: rect ( n-width n-height -- )
>r tx @ swap bounds \ horizontal bounds
ty @ r> bounds do \ vertical loop
2dup do
i j pos dot \ draw
loop
loop 2drop ;
\ https://en.wikipedia.org/wiki/In-place_matrix_transposition
\ transpose buffer
: transpose ( -- )
cols 1- 0 do \ for j = 0 to N - 2
cols i 1+ do \ for i = j + 1 to N - 1
j i xy@ \ swap A(j,i) with A(i,j)
i j xy@
j i xy!
i j xy!
loop
loop ;
\ mirror buffer along y-axis
: mirror ( -- )
cols 0 do \ row (j)
cols 2/ 0 do \ column (i)
i j xy@
cols 1- i - j xy@
i j xy!
cols 1- i - j xy!
loop
loop ;
\ http://stackoverflow.com/questions/42519/how-do-you-rotate-a-two-dimensional-array
\ rotate clock-wise
: cw ( -- )
transpose
mirror ;
: test-img ( -- )
leds 0 do
leds i - 0 i led-n! \ blue background
loop
rows 1 do
$001000 i i xy! \ green diagonal
loop
$3F0000 0 led-n! \ start-px
$1F1F00 4 led-n! ; \ right-top-px