Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- setscreen ("graphics:mcga, offscreenonly")
- var x, y, z : array 1 .. 8 of int
- var spin, spid : int
- var xb, yb, xc, yc : array 1 .. 8 of int
- var ecol : array 1 .. 8 of int
- var fcol : int
- var rx : int
- var f1, f2 : int
- var e, r : int
- var ch : string (1)
- var edgeshow : array 1 .. 4 of int
- x (1) := 120
- for b : 1 .. 4
- y (b) := 50
- end for
- for b : 5 .. 8
- y (b) := 110
- end for
- z (1) := 1
- proc getxy (xx, yy, zz, dot : int)
- %% xx,yy,zz is the x,y,z value of the point
- %% dot is the number of the dot to assign values.
- xb (dot) := xx + round ( (zz / 100) * (160 - xx))
- yb (dot) := yy + round ( (zz / 100) * (120 - yy))
- end getxy
- proc getxy2 (xx, yy, zz, dot : int)
- xc (dot) := xx + round ( (zz / 100) * (160 - xx))
- yc (dot) := yy + round ( (zz / 100) * (120 - yy))
- end getxy2
- proc getedgecol (zz : int)
- % zz is the point number
- % z(zz) is the depth of that point.
- % edge colours: 18 - 24
- % farthest back z showing is 48; max 60
- % closest z showing is -20
- % range of 68; each colour is 10 depth, with the exception of the farthest.
- ecol (zz) := 24 - round ( (z (zz) + 20) / 10)
- end getedgecol
- proc getfacecol (e1, e2 : int)
- %% e1 and e2 are the point numbers of the bottom of the 2 edges.
- %% use the difference between e1 and e2 for picking a color
- %% max width is about 100
- %% min width is 0.
- %% so, the 10 colours being used - divide by 10
- %% colours 105 - 116 or so
- if e < 4 then
- f1 := round ( (e1 + xb (e + 4)) / 2 - (e2 + xb (e + 5)) / 2)
- else
- f1 := round ( (e1 + xb (e + 4)) / 2 - (e2 + xb (5)) / 2)
- end if
- if f1 < 0 then
- f1 := - f1
- end if
- fcol := round (f1 / 10 + 22)
- end getfacecol
- colourback (3)
- colour (1)
- proc xzcalc
- for g : 1 .. 4
- x (g) := 160 - round (sqrt (40 ** 2 * 2) * cos ( (r + 78 +
- 157 *
- g)
- / 100))
- z (g) := 12 - round (40 * sin ( (r + 78 + 157 * g) / 100))
- x (g + 4) := 160 - round (sqrt (40 ** 2 * 2) * cos ( (r + 78
- +
- 157 *
- g) / 100))
- z (g + 4) := 10 - round (40 * sin ( (r + 78 + 157 * g) /
- 100))
- end for
- end xzcalc
- proc vertline (col : int)
- % vertical lines
- if e = 1 then
- % check whether it is in first or second half
- if xb (4) < xb (e) and xb (e) > 160 then
- drawline (xb (e), yb (e), xb (e + 4), yb (e + 4), col)
- elsif xb (2) > xb (e) and xb (e) < 160 then
- drawline (xb (e), yb (e), xb (e + 4), yb (e + 4), col)
- end if
- elsif e = 2 then
- if xb (1) < xb (e) and xb (e) > 160 then
- drawline (xb (e), yb (e), xb (e + 4), yb (e + 4), col)
- elsif xb (3) > xb (e) and xb (e) < 160 then
- drawline (xb (e), yb (e), xb (e + 4), yb (e + 4), col)
- end if
- elsif e = 3 then
- if xb (2) < xb (e) and xb (e) > 160 then
- drawline (xb (e), yb (e), xb (e + 4), yb (e + 4), col)
- elsif xb (4) > xb (e) and xb (e) < 160 then
- drawline (xb (e), yb (e), xb (e + 4), yb (e + 4), col)
- end if
- elsif e = 4 then
- if xb (3) < xb (e) and xb (e) > 160 then
- drawline (xb (e), yb (e), xb (e + 4), yb (e + 4), col)
- elsif xb (1) > xb (e) and xb (e) < 160 then
- drawline (xb (e), yb (e), xb (e + 4), yb (e + 4), col)
- end if
- end if
- end vertline
- proc horizline (col, col2 : int)
- if e <= 3 then
- if xb (e) <= xb (e + 1) then
- drawline (xb (e), yb (e), xb (e + 1), yb (e
- + 1),
- round
- ( (col + col2) / 2))
- end if
- else
- if xb (e) <= xb (1) then
- drawline (xb (e), yb (e), xb (1), yb (1),
- round
- ( (col + col2) / 2))
- end if
- end if
- end horizline
- proc topline (col, col2 : int)
- % top lines
- if e <= 3 then
- drawline (xb (e + 4), yb (e + 4), xb (e + 5), yb
- (e + 5),
- round
- ( (col + col2) / 2))
- else
- drawline (xb (e + 4), yb (e + 4), xb (5), yb
- (5), round
- ( (col + col2) / 2))
- end if
- end topline
- proc topface
- % top lines
- for ez : 1 .. 4
- e := ez
- topline (22, 22)
- end for
- drawfill (round ( (xb (5) + xb (7)) / 2), round ( (yb (5) + yb
- (7))
- / 2), 22, 22)
- end topface
- proc flatface
- %% draw the flat faces next; more difficult
- %% if z < 28 then it is showing, thus should be calculated.
- for ez : 1 .. 4
- e := ez
- if z (e) < 28 then
- edgeshow (e) := 1
- drawline (xb (e), yb (e), xb (e + 4), yb (e + 4), 22)
- else
- edgeshow (e) := 0
- end if
- end for
- topline (22, 22)
- for ez : 1 .. 4
- e := ez
- if e <= 3 then
- if xb (e) <= xb (e + 1) then
- drawline (xb (e), yb (e), xb (e + 1), yb (e + 1), 22)
- end if
- else
- if xb (e) <= xb (1) then
- drawline (xb (e), yb (e), xb (1), yb (1), 22)
- end if
- end if
- end for
- vertline (22)
- % delay(1)
- for ez : 1 .. 4
- e := ez
- if e < 4 then
- if edgeshow (e) = 1 and edgeshow (e + 1) = 1 then
- getfacecol (xb (e), xb (e + 1))
- if f1 < 5 then
- drawfill (round ( (xb (e) + xb (e + 5)) / 2) + 1, round
- ( (yb (e) + yb (e + 5)) / 2), fcol, 22)
- else
- drawfill (round ( (xb (e) + xb (e + 5)) / 2), round
- ( (yb (e) + yb (e + 5)) / 2), fcol, 22)
- end if
- end if
- elsif e = 4 then
- if edgeshow (e) = 1 and edgeshow (1) = 1 then
- getfacecol (xb (e), xb (1))
- if f1 < 5 then
- drawfill (round ( (xb (e) + xb (5)) / 2) + 1, round
- ( (yb (e) + yb (5)) / 2), fcol, 22)
- else
- drawfill (round ( (xb (e) + xb (5)) / 2), round
- ( (yb (e) + yb (5)) / 2), fcol, 22)
- end if
- end if
- end if
- end for
- if hasch then
- getch (ch)
- if ch = "p" then
- delay (1000)
- end if
- end if
- end flatface
- proc rotatecube (ct, spd : int)
- for ra : 1 .. ct
- for rz : 1 .. 628 by spd
- Time.DelaySinceLast(16)
- drawfillbox (0, 0, maxx, maxy, 0)
- r := rz
- xzcalc
- rx := r
- for f : 1 .. 8
- % drawdot (x (f) + round ( (z (f) / 100) * (160 - x (f))), y (f) +
- % round ( (z (f) / 100) * (120 - y (f))), f + 3)
- end for
- %% get the edge and face colours
- for c : 1 .. 8
- getxy (x (c), y (c), z (c), c)
- getedgecol (c)
- end for
- % draw the top face first:
- topface
- % draw the flat faces
- flatface
- % draw the lines
- for c : 1 .. 8
- getxy (x (c), y (c), z (c), c)
- getedgecol (c)
- end for
- for ez : 1 .. 4
- e := ez
- %% draw the vertical lines in their colour
- vertline (ecol (e))
- % horizontal lines, top lines
- if e < 4 then
- horizline (ecol (e), ecol (e + 1))
- topline (ecol (e + 4), ecol (e + 5))
- else
- horizline (ecol (e), ecol (1))
- topline (ecol (e + 4), ecol (5))
- end if
- % top lines in colour
- end for
- % colour (105)
- % locate (2, 2)
- % put r, " " ..
- locate (1, 1)
- if spin not= 1 then
- put spin, " spins, speed = ", spid ..
- else
- put spin, " spin, speed = ", spid ..
- end if
- end for
- View.Update
- spin := spin - 1
- end for
- end rotatecube
- loop
- locate (1, 1)
- colour (88)
- spin:=1
- put "How many spins? -- (0 to exit)" ..
- colour (89)
- locate(1,17)
- get spin
- exit when spin=0
- colour (90)
- locate(2,1)
- put "How fast (1 = slow, 15 = fast)? -- " ..
- colour (91)
- locate(2,33)
- get spid
- rotatecube (spin, spid)
- end loop
Advertisement
Add Comment
Please, Sign In to add comment