yazdmich

Untitled

Dec 4th, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.66 KB | None | 0 0
  1. setscreen ("graphics:mcga, offscreenonly")
  2. var x, y, z : array 1 .. 8 of int
  3. var spin, spid : int
  4. var xb, yb, xc, yc : array 1 .. 8 of int
  5. var ecol : array 1 .. 8 of int
  6. var fcol : int
  7. var rx : int
  8. var f1, f2 : int
  9. var e, r : int
  10. var ch : string (1)
  11. var edgeshow : array 1 .. 4 of int
  12. x (1) := 120
  13. for b : 1 .. 4
  14. y (b) := 50
  15. end for
  16. for b : 5 .. 8
  17. y (b) := 110
  18. end for
  19. z (1) := 1
  20. proc getxy (xx, yy, zz, dot : int)
  21. %% xx,yy,zz is the x,y,z value of the point
  22. %% dot is the number of the dot to assign values.
  23. xb (dot) := xx + round ( (zz / 100) * (160 - xx))
  24. yb (dot) := yy + round ( (zz / 100) * (120 - yy))
  25. end getxy
  26.  
  27. proc getxy2 (xx, yy, zz, dot : int)
  28. xc (dot) := xx + round ( (zz / 100) * (160 - xx))
  29. yc (dot) := yy + round ( (zz / 100) * (120 - yy))
  30. end getxy2
  31.  
  32. proc getedgecol (zz : int)
  33. % zz is the point number
  34. % z(zz) is the depth of that point.
  35.  
  36. % edge colours: 18 - 24
  37. % farthest back z showing is 48; max 60
  38. % closest z showing is -20
  39. % range of 68; each colour is 10 depth, with the exception of the farthest.
  40. ecol (zz) := 24 - round ( (z (zz) + 20) / 10)
  41. end getedgecol
  42.  
  43. proc getfacecol (e1, e2 : int)
  44. %% e1 and e2 are the point numbers of the bottom of the 2 edges.
  45. %% use the difference between e1 and e2 for picking a color
  46. %% max width is about 100
  47. %% min width is 0.
  48. %% so, the 10 colours being used - divide by 10
  49. %% colours 105 - 116 or so
  50. if e < 4 then
  51. f1 := round ( (e1 + xb (e + 4)) / 2 - (e2 + xb (e + 5)) / 2)
  52. else
  53. f1 := round ( (e1 + xb (e + 4)) / 2 - (e2 + xb (5)) / 2)
  54. end if
  55. if f1 < 0 then
  56. f1 := - f1
  57. end if
  58.  
  59. fcol := round (f1 / 10 + 22)
  60. end getfacecol
  61.  
  62. colourback (3)
  63. colour (1)
  64.  
  65. proc xzcalc
  66. for g : 1 .. 4
  67. x (g) := 160 - round (sqrt (40 ** 2 * 2) * cos ( (r + 78 +
  68. 157 *
  69. g)
  70. / 100))
  71. z (g) := 12 - round (40 * sin ( (r + 78 + 157 * g) / 100))
  72. x (g + 4) := 160 - round (sqrt (40 ** 2 * 2) * cos ( (r + 78
  73. +
  74. 157 *
  75. g) / 100))
  76. z (g + 4) := 10 - round (40 * sin ( (r + 78 + 157 * g) /
  77. 100))
  78. end for
  79. end xzcalc
  80.  
  81. proc vertline (col : int)
  82. % vertical lines
  83.  
  84. if e = 1 then
  85. % check whether it is in first or second half
  86. if xb (4) < xb (e) and xb (e) > 160 then
  87. drawline (xb (e), yb (e), xb (e + 4), yb (e + 4), col)
  88.  
  89. elsif xb (2) > xb (e) and xb (e) < 160 then
  90. drawline (xb (e), yb (e), xb (e + 4), yb (e + 4), col)
  91. end if
  92. elsif e = 2 then
  93. if xb (1) < xb (e) and xb (e) > 160 then
  94. drawline (xb (e), yb (e), xb (e + 4), yb (e + 4), col)
  95.  
  96. elsif xb (3) > xb (e) and xb (e) < 160 then
  97. drawline (xb (e), yb (e), xb (e + 4), yb (e + 4), col)
  98. end if
  99.  
  100. elsif e = 3 then
  101. if xb (2) < xb (e) and xb (e) > 160 then
  102. drawline (xb (e), yb (e), xb (e + 4), yb (e + 4), col)
  103.  
  104. elsif xb (4) > xb (e) and xb (e) < 160 then
  105. drawline (xb (e), yb (e), xb (e + 4), yb (e + 4), col)
  106. end if
  107. elsif e = 4 then
  108. if xb (3) < xb (e) and xb (e) > 160 then
  109. drawline (xb (e), yb (e), xb (e + 4), yb (e + 4), col)
  110.  
  111. elsif xb (1) > xb (e) and xb (e) < 160 then
  112. drawline (xb (e), yb (e), xb (e + 4), yb (e + 4), col)
  113. end if
  114. end if
  115. end vertline
  116.  
  117. proc horizline (col, col2 : int)
  118. if e <= 3 then
  119.  
  120. if xb (e) <= xb (e + 1) then
  121. drawline (xb (e), yb (e), xb (e + 1), yb (e
  122. + 1),
  123. round
  124. ( (col + col2) / 2))
  125.  
  126. end if
  127. else
  128. if xb (e) <= xb (1) then
  129. drawline (xb (e), yb (e), xb (1), yb (1),
  130. round
  131. ( (col + col2) / 2))
  132.  
  133. end if
  134. end if
  135. end horizline
  136.  
  137. proc topline (col, col2 : int)
  138. % top lines
  139. if e <= 3 then
  140. drawline (xb (e + 4), yb (e + 4), xb (e + 5), yb
  141. (e + 5),
  142. round
  143. ( (col + col2) / 2))
  144. else
  145. drawline (xb (e + 4), yb (e + 4), xb (5), yb
  146. (5), round
  147. ( (col + col2) / 2))
  148. end if
  149. end topline
  150.  
  151. proc topface
  152. % top lines
  153. for ez : 1 .. 4
  154. e := ez
  155. topline (22, 22)
  156. end for
  157. drawfill (round ( (xb (5) + xb (7)) / 2), round ( (yb (5) + yb
  158. (7))
  159. / 2), 22, 22)
  160. end topface
  161.  
  162. proc flatface
  163. %% draw the flat faces next; more difficult
  164. %% if z < 28 then it is showing, thus should be calculated.
  165. for ez : 1 .. 4
  166. e := ez
  167. if z (e) < 28 then
  168. edgeshow (e) := 1
  169. drawline (xb (e), yb (e), xb (e + 4), yb (e + 4), 22)
  170. else
  171. edgeshow (e) := 0
  172. end if
  173. end for
  174. topline (22, 22)
  175. for ez : 1 .. 4
  176. e := ez
  177. if e <= 3 then
  178.  
  179. if xb (e) <= xb (e + 1) then
  180. drawline (xb (e), yb (e), xb (e + 1), yb (e + 1), 22)
  181.  
  182. end if
  183. else
  184. if xb (e) <= xb (1) then
  185. drawline (xb (e), yb (e), xb (1), yb (1), 22)
  186.  
  187. end if
  188. end if
  189. end for
  190. vertline (22)
  191. % delay(1)
  192.  
  193. for ez : 1 .. 4
  194. e := ez
  195.  
  196. if e < 4 then
  197. if edgeshow (e) = 1 and edgeshow (e + 1) = 1 then
  198. getfacecol (xb (e), xb (e + 1))
  199. if f1 < 5 then
  200. drawfill (round ( (xb (e) + xb (e + 5)) / 2) + 1, round
  201. ( (yb (e) + yb (e + 5)) / 2), fcol, 22)
  202. else
  203. drawfill (round ( (xb (e) + xb (e + 5)) / 2), round
  204. ( (yb (e) + yb (e + 5)) / 2), fcol, 22)
  205. end if
  206. end if
  207. elsif e = 4 then
  208. if edgeshow (e) = 1 and edgeshow (1) = 1 then
  209. getfacecol (xb (e), xb (1))
  210. if f1 < 5 then
  211. drawfill (round ( (xb (e) + xb (5)) / 2) + 1, round
  212. ( (yb (e) + yb (5)) / 2), fcol, 22)
  213. else
  214. drawfill (round ( (xb (e) + xb (5)) / 2), round
  215. ( (yb (e) + yb (5)) / 2), fcol, 22)
  216. end if
  217. end if
  218. end if
  219. end for
  220. if hasch then
  221. getch (ch)
  222. if ch = "p" then
  223. delay (1000)
  224. end if
  225. end if
  226. end flatface
  227.  
  228. proc rotatecube (ct, spd : int)
  229. for ra : 1 .. ct
  230. for rz : 1 .. 628 by spd
  231. Time.DelaySinceLast(16)
  232.  
  233. drawfillbox (0, 0, maxx, maxy, 0)
  234. r := rz
  235. xzcalc
  236.  
  237. rx := r
  238.  
  239.  
  240. for f : 1 .. 8
  241. % drawdot (x (f) + round ( (z (f) / 100) * (160 - x (f))), y (f) +
  242. % round ( (z (f) / 100) * (120 - y (f))), f + 3)
  243. end for
  244.  
  245. %% get the edge and face colours
  246.  
  247. for c : 1 .. 8
  248. getxy (x (c), y (c), z (c), c)
  249. getedgecol (c)
  250. end for
  251.  
  252.  
  253. % draw the top face first:
  254.  
  255. topface
  256.  
  257. % draw the flat faces
  258.  
  259. flatface
  260.  
  261.  
  262. % draw the lines
  263. for c : 1 .. 8
  264. getxy (x (c), y (c), z (c), c)
  265. getedgecol (c)
  266. end for
  267.  
  268. for ez : 1 .. 4
  269. e := ez
  270.  
  271. %% draw the vertical lines in their colour
  272.  
  273. vertline (ecol (e))
  274.  
  275. % horizontal lines, top lines
  276. if e < 4 then
  277. horizline (ecol (e), ecol (e + 1))
  278. topline (ecol (e + 4), ecol (e + 5))
  279. else
  280. horizline (ecol (e), ecol (1))
  281. topline (ecol (e + 4), ecol (5))
  282. end if
  283. % top lines in colour
  284.  
  285.  
  286.  
  287. end for
  288.  
  289.  
  290. % colour (105)
  291. % locate (2, 2)
  292. % put r, " " ..
  293. locate (1, 1)
  294. if spin not= 1 then
  295. put spin, " spins, speed = ", spid ..
  296. else
  297. put spin, " spin, speed = ", spid ..
  298. end if
  299. end for
  300. View.Update
  301. spin := spin - 1
  302. end for
  303. end rotatecube
  304.  
  305. loop
  306. locate (1, 1)
  307. colour (88)
  308. spin:=1
  309. put "How many spins? -- (0 to exit)" ..
  310. colour (89)
  311. locate(1,17)
  312. get spin
  313. exit when spin=0
  314. colour (90)
  315. locate(2,1)
  316. put "How fast (1 = slow, 15 = fast)? -- " ..
  317. colour (91)
  318. locate(2,33)
  319. get spid
  320.  
  321. rotatecube (spin, spid)
  322. end loop
Advertisement
Add Comment
Please, Sign In to add comment