-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcowsay.bf
163 lines (127 loc) · 4.55 KB
/
cowsay.bf
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
########################################
# #
# cowsay in Brainfuck by zonia3000 #
# #
########################################
# read user input until newline is detected
----------
[
++++++++++
>>
# store user input
>,
# store 2 extra cells for performing future computation
# cells are initialized at 1 so we can go back smoothly
>+>+<<
----------
]
# cleanup extra cells
>[-]>[-]<<<[-]
# temporary reset last support cell for performing next if
<[-]
# if input is not empty
<[>+>+<<-]>[<+>-]+>
[
# valid input detected: temporary cells cleanup
[-]<[-]
# restore last support cell
+
# go back!
[<]<<
# print space
++++++[>++++++<-]>----.
# print underscore
>++++++++[-<++++ ++++>]<-.
# move underscore forward and print it
>+>[<<[->>>+<<<]+>>>-.>>]
# print extra underscore
<<.>
# print newline (10)
++++++++++.
# print lt (add 50)
[->++++++<]>.
# print space
<++++[->-------<]>.
# go back to start of text
<<[<]>>>
# print input text (and last space)
[.>>>]
<<< # last cells contain 95 0 32
# print gt (add 30 to 32)
<++++++++++[->+++<]>.
# print newline
<++++++++++.
# print space (sub 30 to 62)
[->---<]>.
# reset last cell
[-]<
# transform underscore to dash (sub 50 to 95)
++++++++++[-<----->]<.
# move dash to the beginning and print it
<[>[-<<<+>>>]+<<<-.<]>.
# go to the end
[>]
print first part of cow head
++++++ ++++.- -[>+++ +>++++ ++>+++ +++++> ++++++
++++>+ ++++++ +++++< <<<<-] >..... ...>>> >----.
<<<<.. .>>>>+ +.+..- .<<<<- ------ ------ ------
---.>- ------ ------ ---... ...... >>>--. <<<..+
+++++++.
# reset memory
>>>[-]<[-]<[-]<[-]<[-]<[-]
# check if last input char is !
<++ # current value is 3
[-<---------->]<---
# if char is not !
[>+>+<<-]>[<+>-]+>
[ # print normal cow eyes
>
++++++++++[->+++++++++++<]>+..[-]<
<
<->[-]]< # else
[ # print crazy cow eyes
>>
++++++++[->++++++++<]>..[-]<
<<-
]
print rest of the cow
++++++++ [>++++>++ ++++> +++++
+++>+++++++++ +>+++++++++++ +<<<< <-]>>
-------.>>>---- .+++.......<<<< ----- -----
----- ---- ---.>-- ------- ..... .....
..++ +++++ +.>>> ..<<< + .>>>-
--.< <<--- ----- -.... ... +++++
++++ .>>>. <<<++ ++++. >>>.< <<<.>
---- ----- ----- -................
>>>++ ++++ +++++++ +++++++ +++++++ +++++..
<<<++++++++++++ +....>>>-----.< <<--- -----
-----.>>>++++ +.<<<<.>..... ... ...
.....>>> ..<<<.... . >
>>..
# reset memory
[-]<[-]<[-]<[-]<[-]
# black magic fix before else
<[-]+>
# else: empty input detected
<->[-]]<
[ kill the cow
>>
|+++++\ /+++[>| |++++>++++++>+++++| |+++>++++++++++>++| |++++++++++<<<<<-]| |>>>..|
|......\ /......| |.................| |......<<---------| |-------------.>>.| |<----|
|-------\ /-----.>| |+++++.>>+++++++++| |++++.+++.++++.+++| |++.<<<.>>>-------| |-----|
|----.+++ ++.++.++| |+++.-.<<<.>>>----| |.++.---.+++++++.-| |------------.----| |-.+.-|
|.<<<+++++++++++++| |+.---| |-----| |-----| |-.>--| |.>>++| |+++++| |++++.|
|+++++|+++.<|<<.>>| |+++++| |+++++| |+++++| |++++.| |>----| |-.<--| |.>+.<|
|+++++|\++./|---.-| |.<<.>| |---.<| |<.>>.| |.....| |.....| |.....| |.....|
|.....| \./ |.....| |.....| |<<..>| |.....| |.....| |....>| |>>+++| |+++++|
|+..<<| |<....| |.>>>..<<<........| |......<.>........| |......>>>..<<<+++|
|+++++| |+++++| |....>++++++++++++| |+.<-------------.| |>>>.<<<<.>.......| |...++|
|+++++| |+.+++| |++..----.++++++.-| |--------------...| |....+++++++++.+++| |+++.>|
|>----| |----.| |<<.<.>-----------| |----..........+++| |+++++.>>>----..<<| |<+.++|
++++.--.......<.>-------------..........>>>--.<<<+++++++++++++..>>>.
# reset memory
[-]<[-]<[-]<[-]<[-]<
<<-
]
# newline
++++++++++.