查找暂定大小的ASCII美工程序的空白算法 [英] Finding the white space algorithm for a tentative size ASCII art program

查看:75
本文介绍了查找暂定大小的ASCII美工程序的空白算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我们必须设计一本ASCII美术书,我几乎完成了,但是我想不出一点小事情: Building Java Programs一词的两边的间距

So we have to design an ASCII art book, and I'm almost done, but I can't figure out one little thing: The spacing on either side of the words "Building Java Programs"

这是本书的外观

到目前为止,这是我的代码(为方便起见,我仅显示需要空格帮助的方法。假设drawLine()均匀绘制虚线到SIZE常量是什么)

Here is my code so far (for ease of help, I'm only showing the method where the spacing help is needed. Assume drawLine() draws the dashed line evenly to what the SIZE constant is)

    //constant SIZE = 8
    public static void drawBottom()
    {
        //Dash line on top of the bottom portion of the book
        drawLine();

        //Printing first set of rightmost "/"'s
        for(int i = 1; i <= SIZE; i++)
            System.out.print("/");
        System.out.println();

        for(int i = 1; i <= SIZE / 2; i++)
        {
            //Leftmost pipe
            System.out.print("|");

//            TO DO: Code label of book
//            for(int j = 1; j <= ; j++)
//            {
//                
//            }

            //This loop is only here for example. To show I can fill the space but need
            //the words in the space
            for(int j = 1; j <= SIZE * 3; j++)
            {
                System.out.print(" ");
            }

            //Rightmost pipe
            System.out.print("|");

            //"Pages" to right of label
            for(int j = 1; j <= -2 * i + (SIZE + 2); j++)
            {
                System.out.print("/");
            }

            //Move to draw next row
            System.out.println();
        }

        //Dash line on very bottom of entire drawing
        drawLine();
    }

这是我的输出(当SIZE = 8时)

我如何计算到

我所知道的是,当SIZE = 8时,在两侧都有一个空格

All I know is that when SIZE = 8, there is one space on either side

当SIZE = 10时,每边有4个空格

When SIZE = 10, there are 4 spaces on either side

当SIZE = 13时,每边有8个空格

When SIZE = 13, there are 8 spaces on either side

什么算法可以在这里帮助我?

What algorithm can help me here?

推荐答案

我知道了!我一直需要使用的方程是斜率截距!

I figured it out! The equation I needed to use was slope-intercept all along!

SIZE = 8,空格= 1

SIZE = 8, space = 1

SIZE = 10,空格= 4

SIZE = 10, space = 4

将它们变成点
(8,1)和(10,4)

Turn them into points (8, 1) and (10, 4)

记住斜率截距形式 y = mx + b

Remember slope-intercept form y = mx + b

查找m m =(y2-y1)/(x2-x1)

Find m m = (y2 - y1)/(x2 - x1)

m =(4-1)/(10-8)

m = (4 - 1)/(10 - 8)

m = 3/2

求解b 使用任一点。我将使用(8,1)

Solve for b Using either point. I'll use (8, 1)

1 = 3/2 x 8 + b

1 = 3/2 x 8 + b

b = 1-(3/2)(8)

b = 1 - (3/2)(8)

b = -11

利润! y = 3 / 2x-11

Profit! y = 3/2x - 11

或者在我们的情况下...

for(int j = 1; j <= (3*SIZE)/2 - 11; j++)
{
    System.out.print(" ");
}

System.out.print("Building Java Programs");

//put same loop here again

这篇关于查找暂定大小的ASCII美工程序的空白算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆