C talk together with chestnuts bar (eighty-second back: C language examples - Simple Christmas tree)

Label C language to achieve the Christmas tree
509 people read comments(0) Collection Report

Everybody, everybody is good, today is Christmas eve,First of all I wish you a happy ChristmasAt the same time, also thank you for the attention of the historical novel. As the saying goes, digression, get to the point. Let's C talk chestnuts!

What we said today is not related to the content in front of us,Today we are going to be a simple Christmas tree, even if I give you a Christmas gift.. When we make Christmas tree, we use the curses library, which is convenient to describe the simple figure in the window. The curses library is Linux a simple graphics library, I in the other blog simple introduced the curses library, if there is any reader of the curses library does not understand,click hereTo view, in order to have a simple understanding of the curses library.

Here are the steps to make a Christmas tree, please refer to:

  • 1 initialization screen;
  • 2 describe the top level of the Christmas tree;
  • 3 and then paint the next layer, which is larger than the upper layer;
  • 4 repeat the last step, we describe the 6 layer. The more the number of layers, the greater the Christmas tree, we can according to their own needs, customized layers;
  • 5 describe the trunk;
  • 6 refresh screen;
  • 7 release screen related resources.

Here is the code we write, please refer to:

    Initscr ();

    (moveOne,Ten);The top layer / / show
    Printw ("%c",');
    Printw ("%c",\ \ ');

    (moveTwo,Nine);The next layer / / show
    Printw ("%c",');
    Printw ("%c",\ \ ');

    (moveThree,Eight);The next layer / / show
    Printw ("%c",');
    Printw ("%c",\ \ ');
    (moveThree,Seven);The gift on the tree / / put
    Printw ("%c",The '@');
    Printw ("%c",*);

    (moveFour,Seven);The next layer / / show
    Printw ("%c",');
    Printw ("%c",\ \ ');
    (moveFour,Six);The gift on the tree / / put
    Printw ("%c",*);
    Printw ("%c",The '@');

    (moveFive,Six);The next layer / / show
    Printw ("%c",');
    Printw ("%c",\ \ ');

    (moveSix,Five);The bottom layer / / show
    Printw ("%c",');
    Printw ("%c",\ \ ');

    Mvvline (Five,Ten,'|',Five);


    Refresh ();
    Endwin ();

The reader,We illustrate some of the details of the code above.

We depict the Christmas tree in each layer of the content, first using a move and move the cursor to the corresponding position, and then in the position using function Printw output a symbol to represent the branches of the Christmas tree. We also use this method to add some "gifts" in the Christmas tree, using the symbol "@" and "*" said code.

Description of the tree trunk when using the mvvline function directly draw the trunk.

The Christmas tree is a Pyramid shape, therefore, we can calculate the coordinates, I is not described in detail.

Here are the results of the operation of the program, please refer to.(this is a static figure, we can run the program, the Christmas tree will flash up)
Write the picture here.

in order toTo create a flashing effect, we use the offset method to depict the Christmas tree.. The following is the specific code:

        If(I%2= =Zero)
Show ();

In the code show to depict a Christmas tree, and the Christmas tree of the global coordinates deviated to the right a bit, using the print once again portray the Christmas tree. So repeatedly, to achieve the effect of flashing.

The reader will not write the text, code, detailed code in my resources, you canclick hereDownload and use. Compiler when you need to use the l parameters linked to the curses library, the specific order is:

ChristmasTree GCC.C-oS-lcurses

Kanguan, a simple Christmas tree example we speak of here, if you want to know what example behind, and listen to the next time decomposition. LastMerry Christmas to all of you!

Guess you're looking for
View comments
* the above user comments only represent their personal views, does not represent the views or position of the CSDN website
    personal data
    • Visit50426 times
    • Integral:Two thousand two hundred and forty-four
    • Grade
    • Rank:10014th name
    • Original178
    • Reproduced:0
    • Translation:0
    • Comments:30
    Blog column
    Classification of articles
    Latest comments