Java &引用;图纸;由 ;控制台应用程序
我想在控制台应用程序中绘制一个给定的字符,形成一个椭圆 我不知道如何解决的问题是,我只知道在知道角度和半径(使用正弦和余弦函数)后在哪里绘制角色,但这样我可能会留下间隙 它甚至更复杂,因为我想“画”一个填充的椭圆,而不仅仅是边界 我怎么做 我想要的方法如下:Java &引用;图纸;由 ;控制台应用程序,java,c#,.net,algorithm,drawing,Java,C#,.net,Algorithm,Drawing,我想在控制台应用程序中绘制一个给定的字符,形成一个椭圆 我不知道如何解决的问题是,我只知道在知道角度和半径(使用正弦和余弦函数)后在哪里绘制角色,但这样我可能会留下间隙 它甚至更复杂,因为我想“画”一个填充的椭圆,而不仅仅是边界 我怎么做 我想要的方法如下: DrawEllipse(char ch, int centerX, int centerY, int width, int height) 只是一个想法:我可以在椭圆的矩形区域中编写一个带有内循环的循环,并确定某个位置是在椭圆区域的内部还
DrawEllipse(char ch, int centerX, int centerY, int width, int height)
只是一个想法:我可以在椭圆的矩形区域中编写一个带有内循环的循环,并确定某个位置是在椭圆区域的内部还是外部。首先,这里是如何绘制一个填充圆(假设为80x25控制台窗口)。其他人可能知道允许宽度和高度参数的数学
static void DrawCircle(char ch, int centerX, int centerY, int radius)
{
for(int y = 0; y < 25; y++)
{
for(int x = 0; x < 80; x++)
{
char c = ' ';
var dX = x - centerX;
var dY = y - centerY;
if(dX * dX + dY * dY < (radius * radius))
{
c = ch;
}
Console.Write(c);
}
}
}
static void DrawCircle(字符ch、int centerX、int centerY、int半径)
{
对于(int y=0;y<25;y++)
{
对于(int x=0;x<80;x++)
{
字符c='';
var dX=x-centerX;
var dY=y-centerY;
如果(dX*dX+dY*dY<(半径*半径))
{
c=ch;
}
控制台。写入(c);
}
}
}
首先,这里是如何绘制一个填充圆(假设为80x25控制台窗口)。其他人可能知道允许宽度和高度参数的数学
static void DrawCircle(char ch, int centerX, int centerY, int radius)
{
for(int y = 0; y < 25; y++)
{
for(int x = 0; x < 80; x++)
{
char c = ' ';
var dX = x - centerX;
var dY = y - centerY;
if(dX * dX + dY * dY < (radius * radius))
{
c = ch;
}
Console.Write(c);
}
}
}
static void DrawCircle(字符ch、int centerX、int centerY、int半径)
{
对于(int y=0;y<25;y++)
{
对于(int x=0;x<80;x++)
{
字符c='';
var dX=x-centerX;
var dY=y-centerY;
如果(dX*dX+dY*dY<(半径*半径))
{
c=ch;
}
控制台。写入(c);
}
}
}
这将是一个合理的近似值
public static void DrawEllipse( char c, int centerX, int centerY, int width, int height )
{
for( int i = 0; i < width; i++ )
{
int dx = i - width / 2;
int x = centerX + dx;
int h = (int) Math.Round( height * Math.Sqrt( width * width / 4.0 - dx * dx ) / width );
for( int dy = 1; dy <= h; dy++ )
{
Console.SetCursorPosition( x, centerY + dy );
Console.Write( c );
Console.SetCursorPosition( x, centerY - dy );
Console.Write( c );
}
if( h >= 0 )
{
Console.SetCursorPosition( x, centerY );
Console.Write( c );
}
}
}
publicstaticvoidpaurellipse(字符c、int-centerX、int-centerY、int-width、int-height)
{
对于(int i=0;i
这将是一个合理的近似值
public static void DrawEllipse( char c, int centerX, int centerY, int width, int height )
{
for( int i = 0; i < width; i++ )
{
int dx = i - width / 2;
int x = centerX + dx;
int h = (int) Math.Round( height * Math.Sqrt( width * width / 4.0 - dx * dx ) / width );
for( int dy = 1; dy <= h; dy++ )
{
Console.SetCursorPosition( x, centerY + dy );
Console.Write( c );
Console.SetCursorPosition( x, centerY - dy );
Console.Write( c );
}
if( h >= 0 )
{
Console.SetCursorPosition( x, centerY );
Console.Write( c );
}
}
}
publicstaticvoidpaurellipse(字符c、int-centerX、int-centerY、int-width、int-height)
{
对于(int i=0;i
您想要什么样的答案?Java(使用JavaFX)、C#?我认为最重要的部分是算法,但在C#中就完美了!什么椭圆?轴对齐,任意角度?(原型建议轴对齐)。你知道你可以把这个问题转化为圆问题,利用x*x+y*y好的,你想要一个由控制台字符组成的填充椭圆在控制台上打印,就像ASCII艺术一样。我想要用任意字符填充椭圆的形状,给定中心坐标和大小(宽度和高度)。大小是椭圆所在矩形的大小。你想要什么样的答案?Java(使用JavaFX)、C#?我认为最重要的部分是算法,但在C#中就完美了!什么椭圆?轴对齐,任意角度?(原型建议轴对齐)。你知道你可以把这个问题转化为圆问题,利用x*x+y*y好的,你想要一个由控制台字符组成的填充椭圆在控制台上打印,就像ASCII艺术一样。我想要用任意字符填充椭圆的形状,给定中心坐标和大小(宽度和高度)。大小是椭圆所在矩形的大小。