Magik Says Happy Valentines by Drawing a Heart to Console

  • 时间:2020-10-12 15:39:01
  • 分类:网络文摘
  • 阅读:127 次

Hey, it is happy valentines today! And I think it would be nice to please my wife with something special. I am learning Magik – which is a OO programming language developed by GE Smallworld, and the following seems a good learning/coding exercise.

heart Magik Says Happy Valentines by Drawing a Heart to Console magik programming

Drawing a Heart to Console in Magik Programming

Draw a Heart Shape to Console using Magik

Drawing heart is a fun exercise.

# Drawing a heart to the console
# Happy Valentine's Day 2019
_package sw
$

_block
    _local c << 178.as_character() # heart symbol
    _local s << ""

    # Magik does not have a write without printing new lines
    # Therefore, we concatenate output strings
    _local concat << _proc(str, char) 
        >> str + char
    _endproc

    # 5 blank lines
    _for i _over range(1, 5) _loop s << concat(s, %newline) _endloop

    _for i _over range(1, 3)
    _loop
        _for j _over range(1, 32 - 2 * i) _loop s << concat(s, %space) _endloop
        _for k _over range(1, 4 * i + 1)  _loop s << concat(s, c) _endloop
        _for l _over range(1, 13 - 4 * i) _loop s << concat(s, %space) _endloop
        _for m _over range(1, 4 * i + 1) _loop s << concat(s, c) _endloop
        s << concat(s, %newline)        
    _endloop

    _for i _over range(1, 3)
    _loop
        _for j _over range(1, 24 + 1) _loop s << concat(s, %space) _endloop
        _for k _over range(1, 29)  _loop s << concat(s, c) _endloop
        s << concat(s, %newline)        
    _endloop

    _for i _over range(7, 1, -1)
    _loop
        _for j _over range(1, 40 - 2 * i) _loop s << concat(s, %space) _endloop
        _for k _over range(1, 4 * i - 1)  _loop s << concat(s, c) _endloop
        s << concat(s, %newline)        
    _endloop

    _for i _over range(1, 39) _loop s << concat(s, %space) _endloop

    # the last tiny bit
    s << concat(s, c)

    # 5 blank lines
    _for i _over range(1, 5) _loop s << concat(s, %newline) _endloop

    write(s)
_endblock

Magik does not provide a write without adding %newline – therefore we concatenate the output string and print it all once to the console.

–EOF (The Ultimate Computing & Technology Blog) —

推荐阅读:
最后一个六一儿童节作文500字  姥姥家的菜园作文  数学题:三位老师带50名学生去参观植物园  在一个面积5平方分米的正方形里画一个最大的圆  数学题:有两个底面半径相等的圆柱,高的比是2:5  数学题:用这堆沙在5米宽的公路上铺2厘米厚的路面  数学题:某县城去省城的高速公路长160千米  数学题:把一个棱长为4分米的正方体填满水  数学题:一批工人到甲乙两个工地进行清理工作  数学题:问乙等了甲多长时间? 
评论列表
添加评论