[英]Console 3D Cube Rotating
在控制台中创建“ 3D”多维数据集并将其旋转(骰子滚动样式)的良好算法是什么?
创造性的答案将不胜感激。
我不知道这是否符合您要寻找的“算法”,但是您始终可以进行完整的3D计算。
绘制立方体线框的示例代码(我使用的是OpenTK的Vector / Matrix类,也可以从XNA或其他一些库中获得它们)
using System;
using System.Linq;
using OpenTK;
class Cubes
{
static void Main() {
var resolution = 25;
var points = from i in Enumerable.Range(1, 8) select new Vector3(i / 4 % 2 * 2 - 1, i / 2 % 2 * 2 - 1, i % 2 * 2 - 1);
var lines = from a in points
from b in points
where (a - b).Length == 2 // adjacent points
&& a.X + a.Y + a.Z > b.X + b.Y + b.Z // select each pair once
select new { a, b };
var t = 0f;
while (true) {
t += .1f;
var projection = Matrix4.CreatePerspectiveFieldOfView(.8f, 1, .01f, 100f);
var view = Matrix4.LookAt(2 * new Vector3((float)Math.Sin(t), .5f, (float)Math.Cos(t)), Vector3.Zero, Vector3.UnitY);
Console.Clear();
foreach (var line in lines) {
for (int i = 0; i < resolution; i++) {
var point = (1f / resolution) * (i * line.a + (resolution - 1 - i) * line.b); // interpolate a point between the two corners
var p1 = 5 * Vector3.Transform(point, view * projection) + new Vector3(30, 20, 0);
Console.SetCursorPosition((int)p1.X, (int)p1.Y);
Console.Write("#");
}
}
Console.ReadKey();
}
}
}
输出样本帧:
# ###### #### # ## #### # ## #### # ## ### # ## ## # ### ### # ## # ## # ## # ## # ### # ## # ### # # ## # ### # # ## ##### # # ## ### # # ##### # # # # # # # # # # # # # # # # # # # # # # # # # # # # ##### # # ### ## # # ##### ## # # ### # ## # # ### # ## # ### # ## # ## # ## # ## # ### ### # ## ## # ### ## # #### ## # #### ## # #### ###### # # ###### ## # ### ## # ### ## # #### ## # #### ## # ## ## # ### # # ## # ## # ## # # #### # ## # # #### # # # # #### ## # # ##### ## # # # #### # # # # # # # # # # # # # # # # # # # # # # # # # # #### # # # ## ##### # # ## #### # # # # #### # # ## # #### # # ## # ## # ## # # ### # ## ## # ## #### # ## #### # ## ### # ## ### # ## ###### # # ############## # ########## ## ## ## ## ### ### # # # # # # # # ## # ## # # # # # ## # # # ############## # # # # ########## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ########## # # # # ############## # # # ## # # # # # ## # ## # # # # # # # # ### ### ## ## ## ## ########## # ############## #
我认为没有好的“ 3D多维数据集ascii艺术算法”。 我只使用3D立方体动画-您可以在设计时或运行时创建-并使用普通的ASCII艺术生成器。
您可以创建一个while循环,该循环显示一个字符数组,以生成多维数据集的3D ascii动画,直到您希望它停止为止。 使用foreach (char spinCube in spinCubeTest)
东西foreach (char spinCube in spinCubeTest)
地移动字符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.