您能从代码中渲染出上述版本的BBC Micro Owl徽标吗?
规则:
- 您可以使用任何喜欢的编程语言。
- 输出可以是文本或图形。
- 圆不必重叠。
优胜者:
- 投票最多的答案将获胜。
对于在BBC基本版中尝试此操作的任何人都表示感谢。
您能从代码中渲染出上述版本的BBC Micro Owl徽标吗?
规则:
优胜者:
对于在BBC基本版中尝试此操作的任何人都表示感谢。
Answers:
我尝试使用Trig函数绘制适当的圆,但是那太慢了。提出来了:
10 MODE 1
20 GCOL 0,1 : VDU 19,1,3,0,0,0
30 FOR Y%=0 TO 20
40 READ N% : P%=65536
50 FOR X%=0 TO 16
60 IF (N% AND P%)=0 THEN GOTO 160
70 X0% = X%*32+384 : Y0% = 872-Y%*32
80 FOR DX%=-16 TO 16 STEP 8
90 FOR DY%=-8 TO 8 STEP 8
100 PLOT 69,X0%+DX%,Y0%+DY%
110 NEXT DY% : NEXT DX%
120 FOR DX%=-8 TO 8 STEP 8
130 FOR DY%=-16 TO 16 STEP 32
140 PLOT 69,X0%+DX%,Y0%+DY%
150 NEXT DY% : NEXT DX%
160 P%=P%/2
170 NEXT : NEXT
1000 DATA 87381,33410,69905,10280
1010 DATA 69649,33410,82181,40968
1020 DATA 87377,43520,87297,43520
1030 DATA 21761,10880,5441,2720
1040 DATA 1361,552,1093,43682,1
这是输出:
"!C-DD[5v`>U8G`J2zX['b#L*\\q>FQp "{32-}%96base 2base{" *"2/=}%18/{""*1>17/~n@n}/
该代码可打印徽标的ascii艺术版本(在此处运行)。
* * * * * * * * *
* * * *
* * * * *
* * * *
* * * *
* * * *
* * * * *
* * *
* * * * * * * *
* * * *
* * * * * *
* * * *
* * * * *
* * * *
* * * * *
* * * *
* * * * *
* * *
* * * *
* * * * * * *
*
除了艰苦的工作。
w = 20; h = 25; r = .7; r2 = .2; t = Table; d = Disk;
owl = Graphics[{Polygon[{{0, 0}, {w, 0}, {w, h}, {0, h}}],
ColorData[57, 4],
t[d[{k, 22}, r], {k, 2, 19, 2}],
t[d[{18, k}, r], {k, 2, 21, 2}],
t[d[{k, #}, r], {k, #2}] & @@@ {{21, {3, 9, 10, 11, 17}}, {20, {2,
6, 10, 14, 18}},
{19, {5, 6, 7, 13, 14, 15}}, {18, {6, 9, 11, 14}}, {17, {10,
17}, {16, {16}}, {15, {15}}, {14, {8, 10, 12, 14}},
{13, {9}}, {12, {9}}}},
t[d[{# - k, k}, r], #2] & @@@ {{20, {k, 18, 3, -1}}, {19, {k, 16,
6, -1}}, {18, {k, 16, 5, -1}}, {17, {k, 14, 7, -1}}, {16, {k,
14, 6, -1}}, {14, {k, 11, 5, -1}}, {14, {k, 12, 5, -1}}},
t[d[{k, 4}, r], {k, {8, 12}}],
t[d[{k, 3}, r], {k, 3, 13, 2}],
d[{8, 13}, r],
Black, d[{10, 21}, r2], d[{8, 13}, r2], d[{9, 12}, r2],
t[d[{19 - k, k}, r2], {k, 16, 6, -1}],
t[d[{17 - k, k}, r2], {k, 14, 7, -1}],
t[d[{15 - k, k}, r2], {k, 12, 6, -1}],
t[d[{k, 19}, r2], {k, {6, 14}}]}, ImageSize -> 220]
image(t(matrix(as.integer(sapply(c(1397760,567810,1070336,141954,1381696,133794,
1054036,559786,1332560,557218,1052756,131114,
1380368,139272,1064964,557058,1398101),
intToBits)[1:21,]),nr=21)),ax=F)
结果是:
基本上,该想法是采用17个数字的基数2表示形式(1397760、567810、1070336、141954、1381696、133794、1054036、559786、1332560、557218、1052756、131114、1380368、139272、1064964、557058和1398101) ,将其设为1和0的21x17矩阵,并按原样绘制该矩阵。
background{color<.14,.01,.01>}
camera{orthographic location z*-2 up y*24 right x*20}
#macro s(X,Y)sphere{<X,Y,0>,1.07,2.6}#end
#declare b=array[17]{1397760,567810,1070336,141954,1381696,133794,1054036,
559786,1332560,557218,1052756,131114,1380368,139272,1064964,557058,1398101}
blob{threshold 0.9 #for(j,0,16,1)#declare V=b[j];#for(i,0,28,1)
#if(mod(V,2))s(j-8,i-10)#end #declare V=floor(V/2);#end #end
pigment{color<1,1,.8>}finish{ambient 1}}
与“编译”
povray +Ibbc.pov -Obbc.png +A0.1 +R9 -W240 -H285
由于您未指定没有外部资源...
curl -s http://codegolf.stackexchange.com/questions/19214/render-a-version-of-the-bbc-micro-owl-logo | grep '* * *' | sed -n '/code>\*/,/<pre>/p' | sed '$d' | sed 's/<pre><code>//'
霍华德-偷了您的Ascii艺术,谢谢。
或者在我将其上传到这里之后 -
curl -s http://textuploader.com/1ojd | sed -n '/<code/,/<\/code>/p' | sed 's/<[^>]\+>//g'
149个字符。我在打高尔夫球方面并不是那么大(我更喜欢代码挑战),但是我喜欢BBC基础版中的高尔夫荒谬之处。BBC模拟器,网址为http://www.bbcbasic.co.uk/。在命令行以屏幕模式6运行。
FORK = 6TO185S = K MOD9 = 5VDU-32 *(K MOD18 = 15),17,128 + RND(6)*(ASCMID $(“?OSUuLEMSS ^ H?= A_W”,K / 6,1)/ 2 ^(K MOD6)AND1),32,17,128,32,-13 * S,-10 * S:NEXT
说明(非胶版)
没有IF语句,因为只有在IF为真的情况下才执行该行的其余部分(因此,为了确保到达NEXT,我必须使用行号来编写程序。)因此,我大量使用了ASC(null字符)= 0以控制输出。另外,在打印后,我不得不切掉右下角的像素以适应屏幕上的整个命令行(并且节省了2个字符。
我喜欢BBC Basic如何在FOR之后识别标识符,即使没有空格也是如此。FORE,FORD,FORK,FORM,FORS,FORT :-)
FOR K=6 TO 185
REM Set S to true(-1) if K mod 9 = 5, otherwise set S to false(0)
S = K MOD 9=5
REM If K mod 18 = 15, send asc(space)=32 to the VDU controller,otherwise send 0.
REM This causes staggering every 2 lines.
VDU-32*(K MOD18=15)
REM Vdu 17 for colour. foreground colours start at 0, background colours at 128.
REM Rnd(6) to choose a bright color. Multiply by the horrible expression.
REM The horrible expression evaluates to 1 if the pixel is to be printed, 0 if not.
REM Picture data is stored in base 64 in the string.
REM MID$ extracts the characters in order.
REM The FOR loop starts at K=6 so that this will work properly.
REM Extracted character SHR ((K mod 6)) AND 1 to decide to
REM colour pixel or not. BBC basic does not have SHR operator.
REM so we divide by 2^(K mod 6) instead.
VDU 17,128+RND(6)*
(ASC(MID$( "?OSUuLEMSS^H?=A_<A^tC|dGxEMh>W" ,K/6,1))/2^(K MOD 6)AND 1)
REM Print a space in the new background colour
VDU 32
REM Change background colour back to black
VDU 17,128
REM Print another space
VDU 32
REM If S is true (-1) print a carriage return and linefeed. otherwise two 0's
VDU -13*S,-10*S
NEXT
ASCII输出。
x[]={256,191,424,104,376,60,316,30,286,15,287,15,383,67,403,153,325,102,341,153,511};i=20;mai
n(){for(;i>=0;i--){i&1&&putchar(32);while(x[i]){putchar(x[i]&1?42:32);x[i]>>=1;putchar(32);}pu
tchar(10);}}
代码输出:
* * * * * * * * *
* * * *
* * * * *
* * * *
* * * *
* * * *
* * * * *
* * *
* * * * * * * *
* * * *
* * * * * *
* * * *
* * * * *
* * * *
* * * * *
* * * *
* * * * *
* * *
* * * *
* * * * * * *
*
a=[1716886015,1133746501,253693823,1010572830,3215485048,0];s="";with(Math)
for(y=0;44>y;y++,s+="\n")for(x=0;90>x;x++,s+="#8*+=:-. "[min(floor(d),8)])
for(j=d=0;22>j;j++)for(i=0;9>i;i++)1==((8==i?j+1:a[floor(j/4)]>>i+j%4*8)&1)
&&(d+=50/pow(pow(x-10*(i+j%2/2)-4,2)+pow(2*y-4*j-4,2),1.5));s;
可能不是最短的代码。我尝试仅使用ASCII尽可能接近原始徽标。
要执行:将粘贴复制到javascript控制台(例如chrome或firefox)。注意:该脚本可能需要一些时间才能运行,因此如果在按Enter键后仍然没有任何反应,请耐心等待。
m=Math;
,然后做m.floor
,m.pow
等等
for
循环包装在a中with (Math)
,然后Math.
在每次出现时都将其省略。将各s+=
部分移至for循环标题(y++
/ 旁边x++
)以除去一些花括号。我认为在JS打高尔夫球时通常将alert
/ prompt
用作I / O,因此我将alert(s)
在末尾使用。
代码没有打高尔夫。它使用一些metaballs -ish算法来模拟圆的“粘性”。ASCII猫头鹰从其他答案中被无耻地偷了:)
canvas = document.createElement 'canvas'
canvas.style.backgroundColor = '#240202'
canvas.style.transform = 'scale(0.5) translate(-480px,-570px)'
W = canvas.width = 960
H = canvas.height = 1140
D = 50
R = D / 2
ctx = canvas.getContext '2d'
imageData = ctx.getImageData 0, 0, W, H
data = imageData.data
owl = '''
\ * * * * * * * * *
\ * * * *
\ * * * * *
\ * * * *
\ * * * *
\ * * * *
\ * * * * *
\ * * *
\ * * * * * * * *
\ * * * *
\ * * * * * *
\ * * * *
\ * * * * *
\ * * * *
\ * * * * *
\ * * * *
\ * * * * *
\ * * *
\ * * * *
\ * * * * * * *
\ *
'''.split '\n'
insideDot = (x, y) ->
w = 0
for du in [-1..1] then for dv in [-1..1]
u = x // D + du
v = y // D + dv
continue unless owl[v]?[u] is '*'
dx = x - (u * D + R)
dy = y - (v * D + R)
d = dx * dx + dy * dy
w += 1 / (d * d)
return yes if w > 0.0000008
no
for y in [0...H] then for x in [0...W] when insideDot x, y
i = (y * W + x) * 4
data[i] = data[i+1] = data[i+3] = 255
data[i+2] = 214
ctx.putImageData imageData, 0, 0
document.body.appendChild canvas
观看它销毁coffeescript.org文档(命中Run):
的PHP
以先前提交的徽标的ascii艺术版本为基础,并使用其作为数组使用GD库渲染图形版本。
$circleWidth = 34;
$circleHeight = 34;
$movement = 24;
$canvasWidth = 480;
$canvasHeight = 570;
$image = imagecreatetruecolor($canvasWidth, $canvasHeight);
$backgroundColour = imagecolorallocate($image, 36, 2, 2);
ImageFillToBorder($image, 0, 0, $backgroundColour, $backgroundColour);
$circleColour = imagecolorallocate($image, 255, 255, 214);
$coordinates ='
* * * * * * * * *
* * * *
* * * * *
* * * *
* * * *
* * * *
* * * * *
* * *
* * * * * * * *
* * * *
* * * * * *
* * * *
* * * * *
* * * *
* * * * *
* * * *
* * * * *
* * *
* * * *
* * * * * * *
* ';
$coordinates = str_split($coordinates);
$coordinateX = $movement;
$coordinatY = $movement;
$i=1;
foreach ($coordinates as $coordinate) {
if ($i < 19) {
if ($coordinate == '*') {
ImageFilledEllipse($image, $coordinateX, $coordinatY, $circleWidth, $circleHeight, $circleColour);
}
$coordinateX = $coordinateX + $movement;
$i++;
} else {
$i=1;
$coordinateX = $movement;
$coordinatY = $coordinatY + $movement;
}
}
header("Content-type: image/png");
imagepng($image);
imagedestroy($image);
结果是:
BBC基础版+ GXR
但这很晚了,但是:Twitter上的“ bbcmicrobot”帐户运行progs <280个字符左右,因此添加了Acorn GXR ROM,允许绘制圆圈和椭圆。我想,我可以画几个圆圈吗?而这来到了我。它部分基于@Level River Street的答案,因此我使用了缩写的基本命令,使用位测试代替了SHR并更改了位表示形式:
2MO.2:P."HOW TO DRAW AN OWL":MOV.200,700:PL.&91,120,0:MOV.250,450:PL.0,-200,0:PL.&C1,155,250:V.29,640;130;
5F.G=0TO188:Z=(G MOD18)>8:X=G MOD9*2-Z:Y=G DIV18*2-Z
6IFASC(MID$("@|WhFMxeG|tC^|A_|A?]HSNSEuLUMS?G",(G+6)DIV6,1))AND2^(G MOD6) MOV.X*36,Y*36:PL.&99,24,0
8N.G
我的原始推文在这里