This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Triangle(lines: Int, char: Char): Shape() { | |
override val grid: Array<CharArray> = Array(lines) { row -> | |
val width = (lines - 1) * 2 + 1 | |
val dots = row * 2 + 1 | |
val offset = (width - dots) / 2 | |
CharArray(width) { column -> | |
when (column) { | |
in offset until offset + dots -> char | |
else -> WHITE_SPACE | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
panel { | |
val square = Square(8, 'd') | |
... | |
addShape(square) | |
... | |
}.print() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
panel { | |
val square = square { | |
lines = 8 | |
char = 'd' | |
} | |
... | |
}.print() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a b cc dd e e | |
bb ccc ddd eeee | |
ccc ddd eeeee | |
dddd eeee | |
eeeee |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
z*aa y * bb b x * ccc cc w * dddd dd v * eeeee e e | |
y ***bbbb xxx *** cccccc www *** dddd ddd vvv *** eeeee eeee | |
x *****cccccc www ***** dddd ddd vvvvv ***** eeeeeeeeee | |
w *******dddddddd vvv ******* eeeee eeee | |
v *********eeeeeeeeee |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
panel { | |
repeat(5) { | |
composed { | |
val rhombus = rhombus { | |
lines = it + 1 | |
char = 'z' - it | |
} | |
val triangle = triangle { | |
lines = it + 1 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a bbbbb ccccc d eeeee | |
aaa bbbbb ccccc ddd eeeee d | |
aaaaa bbbbb ccccc ddddd eeeee ddd | |
aaaaaaa bbbbb ccccc ddd eeeee ddd | |
aaaaaaaaa bbbbb ccccc d eeeee d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
panel { | |
val shapes = mutableListOf<Shape>() | |
repeat(5) { | |
shapes.add(when ((1..3).random()) { | |
1 -> square { | |
lines = 5 | |
char = 'a' + it | |
} | |
2 -> triangle { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a b c d e f g h i j | |
bbb ccc ddd eee fff ggg hhh iii jjj | |
ccccc ddddd eeeee fffff ggggg hhhhh iiiii jjjjj | |
ddddddd eeeeeee fffffff ggggggg hhhhhhh iiiiiii jjjjjjj | |
eeeeeeeee fffffffff ggggggggg hhhhhhhhh iiiiiiiii jjjjjjjjj | |
fffffffffff ggggggggggg hhhhhhhhhhh iiiiiiiiiii jjjjjjjjjjj | |
ggggggggggggg hhhhhhhhhhhhh iiiiiiiiiiiii jjjjjjjjjjjjj | |
hhhhhhhhhhhhhhh iiiiiiiiiiiiiii |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
panel { | |
for (i in 0..9) { | |
triangle { | |
lines = i + 1 | |
char = 'a' + i | |
} | |
space() | |
} |
NewerOlder