是啊。实现一个更简单的05ab1e帆布元素版本。
画布元素用于在屏幕上绘制ASCII线。
画布元素的(更简单的版本)接受一个整数列表,并返回一个多行字符串(或字符串列表)。整数映射到以下方向:
7 0 1
↖ ↑ ↗
6 ← X → 2
↙ ↓ ↘
5 4 3
0: upwards
1: top-right
2: right
3: bottom-right
4: downwards
5: bottom-left
6: left
7: top-left如果被给予的话。[6, 4, 2],它输出如下:
###
#
###
X)6方向)4方向)2方向)#,但每个方向必须绘制2个散列,并以散列开头In: [1, 5, 3, 7, 5, 1, 7, 3]
Out:
# #
# #
#
# #
# #
In: [2, 2, 2, 2, 4, 4, 7, 7]
Out:
#########
# #
# #
##
#
In: [1, 2, 3, 6, 6, 2, 4, 2, 2, 4, 2, 6, 4, 2, 1, 3, 2, 6, 7, 5, 6, 6, 4, 0, 6, 4, 0, 6, 0, 6, 2, 0, 2]
Out:
###
# #
# #####
#
#######
# #
### ### #
# # # #
######### ###
# #
# #
```发布于 2022-06-06 07:52:42
->d{m=2*x=y=d.size*2;c=[]
[-5,*d].map{|k|2.times{(c[y+=k==6?0:k%7<=>2]||=[0]*m)[x+=k<1?0:4<=>k]=1}};c-[p]}在网上试试!返回一个二进制矩阵(1表示#,0表示表示)。为了可读性起见,用分号替换换行符(以及相同的字节计数)。在每一行中产生许多前导/尾随空格(大多数情况下)。
我确信还有一些字节需要剃除,但我目前无法看到它们是什么。
我不确定这是否是最短的,但我认为这个方法比用复幂的方法要短。对于给定的方向k,我们希望生成三角形方向dx和dy,以“推动”我们的中心坐标。我们可以看到,通过一些公式操作,我们可以做到:
上面粗体的单元格表示接受了前面的表达式,但如果前面的条件仍然有效,则选择零。在代码中,我们更新我们的坐标如下:
x += k < 1 ? 0 : 4 <=> k
y += k == 6 ? 0 : k % 7 <=> 2需要注意的是,-5以及任何其他数字c<1 ( c\equiv 2\mod 7 )都在两个坐标中生成0,并且作为占位符表示“无操作”,因此是有用的初始化指令。
-> d {
# x and y are initially set to d.size * 2, guaranteeing us sufficient room
# so that our calculations will not step outside of bounds.
# m is our minimum width for padding purposes for such a bound, and extends
# the distance from 0 to x or y in each direction, that is, 2x or 2y
m = 2 * x = y = d.size * 2
c = []
# to account for the initial cell, we prepend -5 to the input (see above table)
[-5, *d].map { |k|
# since each line is two characters long, we update each cell individually
2.times {
# update y, as per above
y += k == 6 ? 0 : k % 7 <=> 2
# get the current row, defaulting to an appropriate row of 0s
row = c[y] ||= [0] * m
# update x, as per above
x += k < 1 ? 0 : 4 <=> k
# update (x,y) in the output array
row[x] = 1
}
}
# remove all nil rows from the output array
c - [p]
}发布于 2022-06-06 19:26:00
from turtle import*
mode("logo")
def f(l,w=write):
reset();ht();pu();w("#")
for d in l:seth(d*45);fd(9);w("#");fd(9);w("#") https://codegolf.stackexchange.com/questions/248244
复制相似问题