Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import StdEnv,StdIO,osfont,ostoolbox
- Start w#(d,w)=openId w
- #(t,w)=worldGetToolbox w
- #(_,f,_)=osSelectfont("Consolas",[],9)t
- =let
- 	$p#(s,p)=accPIO getProcessWindowSize p
- 	=snd(openWindow undef(Window""NilLS[WindowId d,WindowClose(noLS closeProcess),WindowMouse?Able(noLS1@),WindowViewDomain{corner1={x=0,y=0},corner2={x=1,y=1}},WindowViewSize s,WindowPen[PenFont f]])p)
- 	@(MouseDown p _ _)s=:{ls,io}={s&ls=p}
- 	@(MouseMove p _)s=:{ls={x,y},io}={s&io=setWindowLook d True(1>0,(_{newFrame}i#(w,i)=getPenFontCharWidth' '(unfill newFrame i)
- 	=let g v=let m=y-p.y;n=p.x-x-v*w;s=abs(toReal m/toReal n);k|(abs m)<9&&(abs n)<w='9'|s<0.4142=if(n>0)'1''5'|m>0=if(s>2.4143)'7'if(n>0)'8''6'|s>2.4143='3'=if(n>0)'2''4'
- 		in map(map(e|isDigit e=if(k==e)'0'' '=e))[['.---.'],['|678|'],['|591|'],['|432|'],[''---'']]
- 	in foldr(e=drawAt{x=(x/w-5)*w,y=(y/9+e-2)*9}([toString(a++[' ':b])\a<-g -3&b<-g 3]!!e))i[0..4]))io}
- 	?(MouseDown _ _ _)=1>0
- 	?(MouseMove _ _)=1>0
- 	? _=1<0
- in startIO SDI{x=0,y=0}$[ProcessClose closeProcess]w
- 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
Add Comment
Please, Sign In to add comment