Hack Forums
Rotating ascii cube (Pascal) - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Coders Lounge (https://hackforums.net/forumdisplay.php?fid=5)
+---- Thread: Rotating ascii cube (Pascal) (/showthread.php?tid=2551768)



Rotating ascii cube (Pascal) - PseudoMander - Jun 3, 2012





Code
program ascii3d;
uses crt;
type
    TPoint = array[0..1] of Real;

Function XOffset(Z:Real) : Real;
Begin
XOffset := Z/2;
{Output: Assign the procedure name to the value.
If you forget to assign the function to the value,
you will get a trash value from the memory}
End;
Function YOffset(Z:Real) : Real;
Begin
YOffset := Z/3;
{Output: Assign the procedure name to the value.
If you forget to assign the function to the value,
you will get a trash value from the memory}
End;
Function Transform(X:Real;Y:Real;Z:Real) :TPoint;
VAR
P : Array[0..1] Of Real;
Begin
P[0]:=X+XOffset(Z)+20;
P[1]:=Y+YOffset(Z)+20;
Transform:= P;
End;
var
count: integer;
canvas : Array[1..40,1..40] of char;
i:tpoint;
i2:tpoint;
temp:integer;
steps:integer;
ti:integer;
temp2:integer;
chrr:char;
x:real;
y:real;
z:real;
begin
count:=0;
while 'a'='a' do begin
count:= (count+2)mod 360;
ClrScr;
Writeln('');
for temp:= 1 to 40 do begin
for temp2:= 1 to 40 do begin
canvas[temp][temp2]:='.';
end;end;

for temp := 0 to 3 do begin
    for temp2 := 0 to 1 do begin
    x:=Cos((temp /4.0 +count/360)* pi*2)*16.6;
    y:=(temp2-0.5)*2*7;
    z:=Sin((temp /4.0 +count/360)* pi*2)*16.6;
    i:=Transform(x,y,z);
    i2:=Transform(x,-y,z);
    Steps:=16;
for ti := 1 to Steps do begin
  canvas[round(i2[1]-((i2[1]-i[1])/ti))][round(i2[0]-((i2[0]-i[0])/ti))]:='&';
end;
x:=Cos(((temp+1) /4.0 +count/360)* pi*2)*16.6;
    y:=(temp2-0.5)*2*7;
    z:=Sin(((temp+1) /4.0 +count/360)* pi*2)*16.6;
    i2:=Transform(x,y,z);
    Steps:=16;
for ti := 1 to Steps do begin
  canvas[round(i2[1]-((i2[1]-i[1])/ti))][round(i2[0]-((i2[0]-i[0])/ti))]:='&';
end;
    Canvas[round(i[1])][round(i[0])]:='&';
    end;
end;



for temp:= 1 to 40 do begin
for temp2:= 1 to 40 do begin
chrr:= canvas[temp][temp2];
if chrr='.' then TextColor(LightBlue) ;
if chrr=','  then TextColor(Red)   ;
if chrr='&' then TextColor(White)  ;
Write(chrr);
end;
Writeln('');
end;
Delay(60);
end;
end.



* - SIM-1033745 - Jun 3, 2012

That's pretty amazing, what made you do this? Was it for a class?


* - Pseudonym - Jun 3, 2012

Cool stuff.
Nice example of what can bit of math achieve.


* - PseudoMander - Jun 3, 2012

(Jun 3, 2012 07:28 AM)Quentin Wrote:  That's pretty amazing, what made you do this? Was it for a class?

I wrote one in C a while back, I usually try to work with a multidimensional array, integers, floats, chars and functions as early as possible when familiarising myself with a language, the ascii canvas seems a sure fire solution to learning the basics of a new imperative language and thus variants of such are my equivalent of "hello world" when I need to learn or revise syntax.

Edit: Bonus scriptSpoiler (Click to View) I'll put it in a spoiler tag to save room since it's astoundingly similar to the previous shape.





* - tinkerman2000 - Jun 3, 2012

Good show love!!!..

What math did you use??? to achieve this???👍