干净,1014 904 892 884 840 814 782 772 769个字节
-6个字节(如果眼睛不需要捕捉到网格)
这不容易。功能语言的UI很少。
import StdEnv,StdIO,osfont,ostoolbox
a=toReal
c=1>0
Start w#(d,w)=openId w
#(t,w)=worldGetToolbox w
#(_,f,_)=osSelectfont("Courier",[],9)t
=let$p#(s,p)=accPIO getProcessWindowSize p
=snd(openWindow NilLS(Window""NilLS[WindowId d,WindowMouse(\_=c)Able(noLS1@),WindowViewSize s,WindowPen[PenFont f]])p);@(MouseUp p _)s={s&ls=p};@(MouseMove p _)s=:{ls={x,y},io}={s&io=setWindowLook d c(c,(\_{newFrame}i#(w,i)=getFontCharWidth f' '(unfill newFrame i)
=let g v=let m=y-p.y;n=p.x-x-v*w;s=abs(a m/a n);k|abs m<9&&abs n<w=5|s<0.4142=if(n>0)6 4=sign if(s>2.4143)0n+if(m>0)2 8in[".---.":["|"+++{if(k==e)'0'' '\\e<-[j..j+2]}+++"|"\\j<-[1,4,7]]]++["'---'"]in foldr(\e=drawAt{x=(x/w-5)*w,y=(y/9+e-2)*9}([a+++" "+++b\\a<-g -3&b<-g 3]!!e))i[0..4]))io};@_ s=s
in startIO SDI zero$[]w
确保您正在使用iTasks Clean,已Courier
安装字体并且在模块搜索路径中的StdLib
所有子文件夹之前ObjectIO
。
编译方式(示例,可能有所不同): clm -IL StdLib -IL ObjectIO -IL "ObjectIO/OS <YOUR_OS_HERE>" -IL Dynamics -IL Generics -IL Platform -nci <MODULE_NAME_HERE>
如果您以前从未运行过Clean,请期待此项目需要5分钟以上的时间来编译。
取消高尔夫:
module main
import StdEnv,StdIO,osfont,ostoolbox
height=9
SlopeFor225 :== 0.4142
StartSize :== 8
Universe :== {corner1={x=0,y=0},corner2={x=1,y=1}}
Start :: *World -> *World
Start world = startConsole (openIds 1 world)
startConsole :: ([Id],*World) -> *World
startConsole ([windowID],world)
# (toolbox,world) = worldGetToolbox world
# (_,font,toolbox) = osSelectfont ("Consolas",[],height) toolbox
= startIO SDI {x=0,y=0} (initialise font) [ProcessClose closeProcess] world
where
initialise font pst
# (size,pst) = accPIO getProcessWindowSize pst
# (error,pst) = openWindow undef (window font size) pst
| error<>NoError = abort "bad window"
= pst
window font size
= Window "Xeyes" NilLS
[WindowId windowID
,WindowClose (noLS closeProcess)
,WindowMouse mouseFilter Able (noLS1 track)
,WindowViewDomain Universe//(getViewDomain StartSize)
,WindowViewSize size
,WindowPen [PenFont font]
]
track (MouseDown pos _ _) state=:{ls=point=:{x,y},io}
# point = pos
// move to mouse position
= {state & ls=pos}
track (MouseMove pos _) state=:{ls=point=:{x,y},io}
//redraw to point at mouse
# io = setWindowLook windowID True (True, look) io
= {state & ls=point,io=io}
where
look _ {newFrame} picture
# picture = unfill newFrame picture
# (width,picture) = getPenFontCharWidth' 'picture
= let
determineSector u
# yDist = (y - pos.y)
# xDist = (pos.x - u)
# slope = abs(toReal yDist / toReal xDist)
| (abs yDist) < height && (abs xDist) < width = '9'
| slope < SlopeFor225 = if(xDist > 0) '1' '5'
| yDist > 0
| slope > (2.0+SlopeFor225) = '7'
= if(xDist > 0) '8' '6'
| slope > (2.0+SlopeFor225) = '3'
= if(xDist > 0) '2' '4'
getEye u=map(map(\e|isDigit e=if(e==determineSector(x+u*width))'0'' '=e))[['.---.'],['|678|'],['|591|'],['|432|'],['\'---\'']]
in foldr(\i pic=drawAt{x=(x/width-5)*width,y=(y/height+i-2)*height}([toString(a++[' ':b])\\a<-getEye -3&b<-getEye 3]!!i)pic)picture[0..4]
mouseFilter (MouseDown _ _ _) = True
mouseFilter (MouseMove _ _) = True
mouseFilter _ = False
从非高尔夫版本中可以看到,大多数代码只是设置“等宽字体”和“响应鼠标”的组合。尽管Courier
很难说清楚,但实际上是在绘制.
s和'
s。交换到类似的东西Consolas
可以使它更清晰。