Guest User

Untitled

a guest
Jan 17th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. import StdEnv,StdIO,osfont,ostoolbox
  2. Start w#(d,w)=openId w
  3. #(t,w)=worldGetToolbox w
  4. #(_,f,_)=osSelectfont("Consolas",[],9)t
  5. =let
  6. 	$p#(s,p)=accPIO getProcessWindowSize p
  7. 	=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)
  8. 	@(MouseDown p _ _)s=:{ls,io}={s&ls=p}
  9. 	@(MouseMove p _)s=:{ls={x,y},io}={s&io=setWindowLook d True(1>0,(_{newFrame}i#(w,i)=getPenFontCharWidth' '(unfill newFrame i)
  10. &#9;=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'
  11. &#9;&#9;in map(map(e|isDigit e=if(k==e)'0'' '=e))[['.---.'],['|678|'],['|591|'],['|432|'],[''---'']]
  12. &#9;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}
  13. &#9;?(MouseDown _ _ _)=1>0
  14. &#9;?(MouseMove _ _)=1>0
  15. &#9;? _=1<0
  16. in startIO SDI{x=0,y=0}$[ProcessClose closeProcess]w
  17.  
  18. module main
  19. import StdEnv,StdIO,osfont,ostoolbox
  20. height=9
  21. SlopeFor225 :== 0.4142
  22.  
  23. StartSize :== 8
  24.  
  25. Universe :== {corner1={x=0,y=0},corner2={x=1,y=1}}
  26.  
  27. Start :: *World -> *World
  28. Start world = startConsole (openIds 1 world)
  29.  
  30. startConsole :: ([Id],*World) -> *World
  31. startConsole ([windowID],world)
  32. # (toolbox,world) = worldGetToolbox world
  33. # (_,font,toolbox) = osSelectfont ("Consolas",[],height) toolbox
  34. = startIO SDI {x=0,y=0} (initialise font) [ProcessClose closeProcess] world
  35. where
  36. initialise font pst
  37. # (size,pst) = accPIO getProcessWindowSize pst
  38. # (error,pst) = openWindow undef (window font size) pst
  39. | error<>NoError = abort "bad window"
  40. = pst
  41.  
  42. window font size
  43. = Window "Xeyes" NilLS
  44. [WindowId windowID
  45. ,WindowClose (noLS closeProcess)
  46. ,WindowMouse mouseFilter Able (noLS1 track)
  47. ,WindowViewDomain Universe//(getViewDomain StartSize)
  48. ,WindowViewSize size
  49. ,WindowPen [PenFont font]
  50. ]
  51.  
  52. track (MouseDown pos _ _) state=:{ls=point=:{x,y},io}
  53. # point = pos
  54. // move to mouse position
  55. = {state & ls=pos}
  56.  
  57. track (MouseMove pos _) state=:{ls=point=:{x,y},io}
  58. //redraw to point at mouse
  59. # io = setWindowLook windowID True (True, look) io
  60. = {state & ls=point,io=io}
  61. where
  62. look _ {newFrame} picture
  63. # picture = unfill newFrame picture
  64. # (width,picture) = getPenFontCharWidth' 'picture
  65. = let
  66. determineSector u
  67. # yDist = (y - pos.y)
  68. # xDist = (pos.x - u)
  69. # slope = abs(toReal yDist / toReal xDist)
  70. | (abs yDist) < height && (abs xDist) < width = '9'
  71. | slope < SlopeFor225 = if(xDist > 0) '1' '5'
  72. | yDist > 0
  73. | slope > (2.0+SlopeFor225) = '7'
  74. = if(xDist > 0) '8' '6'
  75. | slope > (2.0+SlopeFor225) = '3'
  76. = if(xDist > 0) '2' '4'
  77. getEye u=map(map(e|isDigit e=if(e==determineSector(x+u*width))'0'' '=e))[['.---.'],['|678|'],['|591|'],['|432|'],[''---'']]
  78. 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]
  79.  
  80. mouseFilter (MouseDown _ _ _) = True
  81. mouseFilter (MouseMove _ _) = True
  82. mouseFilter _ = False
Add Comment
Please, Sign In to add comment