private void DrawStackedCubes(Graphics g, Point baseLocation, int levels, int width, int height, int depth)
{
for (int i = 0; i < levels; i )
{
int offset = i * depth; // 计算每个立方体的深度偏移量
Point location = new Point(baseLocation.X - offset, baseLocation.Y offset); // 计算每个立方体的位置
DrawCube(g, location, width, height, depth);
}
}
private void DrawCube(Graphics g, Point location, int width, int height, int depth)
{
// 定义立方体各个面的顶点
Point[] front = { location, new Point(location.X width, location.Y), new Point(location.X width, location.Y height), new Point(location.X, location.Y height) };
Point[] side = { new Point(location.X width, location.Y), new Point(location.X width depth, location.Y - depth), new Point(location.X width depth, location.Y - depth height), new Point(location.X width, location.Y height) };
Point[] top = { location, new Point(location.X width, location.Y), new Point(location.X width depth, location.Y - depth), new Point(location.X depth, location.Y - depth) };
// 绘制立方体的正面
g.FillPolygon(Brushes.Red, front);
g.DrawPolygon(Pens.Black, front);
// 绘制立方体的侧面
g.FillPolygon(Brushes.LightGreen, side);
g.DrawPolygon(Pens.Black, side);
// 绘制立方体的顶面
g.FillPolygon(Brushes.LightPink, top);
g.DrawPolygon(Pens.Red, top);
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
// 绘制堆叠的立方体
DrawStackedCubes(g, new Point(250, 350), 5, 100, 50, 50);
DrawStackedCubes(g, new Point(350, 350), 1, 100, 50, 50);
DrawStackedCubes(g, new Point(450, 350), 1, 100, 50, 50);
DrawStackedCubes(g, new Point(550, 350), 1, 100, 50, 50);
DrawStackedCubes(g, new Point(650, 350), 1, 100, 50, 50);
DrawStackedCubes(g, new Point(250, 300), 4, 100, 50, 50);
DrawStackedCubes(g, new Point(350, 300), 1, 100, 50, 50);
DrawStackedCubes(g, new Point(450, 300), 1, 100, 50, 50);
DrawStackedCubes(g, new Point(550, 300), 1, 100, 50, 50);
DrawStackedCubes(g, new Point(250, 250), 3, 100, 50, 50);
DrawStackedCubes(g, new Point(350, 250), 1, 100, 50, 50);
DrawStackedCubes(g, new Point(450, 250), 1, 100, 50, 50);
DrawStackedCubes(g, new Point(250, 200), 2, 100, 50, 50);
DrawStackedCubes(g, new Point(350, 200), 1, 100, 50, 50);
DrawStackedCubes1(g, new Point(250, 150), 1, 100, 50, 50);
DrawStackedCubes(g, new Point(250, 100), 1, 100, 50, 50);
DrawStackedCubes(g, new Point(750, 350), 1, 100, 50, 50);
DrawStackedCubes(g, new Point(750, 300), 1, 100, 50, 50);
DrawStackedCubes(g, new Point(850, 350), 1, 100, 50, 50);
DrawStackedCubes(g, new Point(850, 300), 1, 100, 50, 50);
DrawStackedCubes(g, new Point(850, 250), 1, 100, 50, 50);
DrawStackedCubes(g, new Point(950, 350), 1, 100, 50, 50);
DrawStackedCubes(g, new Point(950, 300), 1, 100, 50, 50);
DrawStackedCubes(g, new Point(950, 250), 1, 100, 50, 50);
DrawStackedCubes(g, new Point(950, 200), 1, 100, 50, 50);
DrawStackedCubes(g, new Point(1050, 350), 5, 100, 50, 50);
DrawStackedCubes(g, new Point(1050, 300), 4, 100, 50, 50);
DrawStackedCubes(g, new Point(1050, 250), 3, 100, 50, 50);
DrawStackedCubes(g, new Point(1050, 200), 2, 100, 50, 50);
DrawStackedCubes1(g, new Point(1050, 150), 1, 100, 50, 50);
DrawStackedCubes(g, new Point(1050, 100), 1, 100, 50, 50);
}
Copyright © 2024 妖气游戏网 www.17u1u.com All Rights Reserved