User Tools

Site Tools


notes:unix:fall2023:projects:gtf0

GTF0

GRABIT

grabit unix gtf0

REPOSITORY STEPS

Use the “hg add” command after you grab the project to add it to the repository.

Then use the “hg commit -m ”(message here)“” command to let yourself know any changes you made before adding it to your repository.

Then use the “hg push” command to finalize adding the file with the commit message.

On a different system, you can use “hg pull” and “hg update” to update your changes on different systems, allowing you to save and load your work on lab 46 or on your personal system.

RUN THE PROGRAM

To use the gtf0.c program you do not need to compile it. Once you have edited and changed the code with a text editor and saved it, you can run ./gtf0.c to run it.

Afterwards you can use the mv command to move it to public_html.

It can be helpful to have a second terminal and a window showing your gtf0.png picture so that you can see your changes more quickly. Have your open .c file on one terminal, use the other terminal to run your .c file and to move the resulting .png file to public_html, and the window showing your picture so you can refresh it to see changes.

VIEW THE IMAGE

To view your picture you go into your file explorer where you put your Unix file and find the “gtf0.png” and then click on it to view your image.

You can also view it in a web browser at https://lab46.g7n.org/~username/gtf0.png

LIBGD FUNCTIONALITY

MIXING A COLOR

You can make a color by declaring a new variable int colorName = 0; and then defining it like colorName = gdImageColor (image, 0x??, 0x??, 0x??);. The 0x?? is the amount of red, green, and blue (respectively) that is in your color. The 0x?? format is hexidecimal so the highest amount of each color would be 0xFF and the lowest would be 0x00.

DRAWING A LINE

A line can be drawn with the command gdImageLine (image, x, y, x2, y2, color);. x and y are the starting x and y positions, x2 and y2 are the ending x and y positions and color is which color you want it to be.

DRAWING A RECTANGLE

gdImageRectangle (image, x, y, x2, y2, color);

FILLING AN ENCLOSED SPACE

gdImageFill (image, x, y, color);

DRAWING A FILLED RECTANGLE

gdImageFilledRectangle (image, x, y, x2, y2, color);

DRAWING A CIRCLE

gdImageArc (image, center x, center y, width, height, 360, 360, color);

In order to make a perfect circle, you should ensure that the width and height are the same.

DRAWING AN ELLIPSE

An ellipse is much like a circle, but the main difference is that where a circle has an equal diameter for both the x and y axis, an ellipse will have different diameters. To draw, use the same function used for drawing circles gdImageArc (image, center x, center y, x diameter, y diameter, angle start, angle end, color). Understand that when the machine is drawing the arc, the line of the arc itself is half the distance of the diameter from the center. In other words, the diameter inputs refer to the measurement from end to end of the arc horizontally and vertically once fully drawn. An easy way to produce an ellipse is to double the integer of just one diameter input. This will stretch it out in the direction you choose in the function.

notes/unix/fall2023/projects/gtf0.txt · Last modified: 2023/09/13 20:13 by jbernata