-
Notifications
You must be signed in to change notification settings - Fork 17
/
arrow.nim
43 lines (34 loc) · 890 Bytes
/
arrow.nim
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
# HowTo
# 1. install https://nim-lang.org
# 2. compile with `nim c arrow.nim`
# 3. launch with `./arrow`
import os, strutils, parseutils
# Get CLI args
let arguments = commandLineParams()
var sizeInt: int = 0
proc pUsage(): string =
result = "An integer between 2 and 20 is needed\nUsage: ./arrow 4"
try:
sizeInt = parseInt(arguments[0])
except:
let
e = getCurrentException()
msg = getCurrentExceptionMsg()
# echo "Got exception ", repr(e), " with message ", msg
echo pUsage()
quit()
if sizeInt <= 2 or sizeInt >= 20:
echo pUsage()
quit()
# Draw spike
echo repeat(" ", sizeInt), "*"
# Draw head
var rowSize: int = sizeInt
for i in 2..sizeInt:
echo repeat(" ", rowSize - 1), "*", repeat(" ", (sizeInt - rowSize ) * 2 + 1), "*"
rowSize -= 1
# Draw base
echo repeat("*", sizeInt * 2 + 1)
# Draw tail
for i in 1..sizeInt:
echo repeat(" ", sizeInt), "*"