I have always been fascinated by how computer screens work, computer graphics, and how images are displayed and stored on computers. This curiosity inspired me to undertake this project.
Currently, my goal for this project is to render images such as circles, lines, and bijective functions, and then output these images in PNG and BMP formats. Additionally, the program should be able to read images in JPEG and BMP formats for processing within the code.
- Computer Graphic
- Table of contents
- Requirements
- How to install?
- How to use?
- Project implementation
- License
- References
Tool | Version |
---|---|
C++ | >=20 |
CMakeFile | >=3.28 |
git clone "https://github.com/nguyenpanda/ComputerGraphic.git"
cd /path/to/where/you/place/ComputerGraphic
mkdir build cd build
Please ensure your computer meets all the requirements listed in the Requirements section
cmake ..
make
./ComputerGraphic
First, check if you have installed GNU Make on your Windows system:
make --version
You should see output similar to the following:
GNU Make 4.4.1
Built for Windows32
Copyright (C) 1988-2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
If the above command outputs the version information for **GNU Make**, you can proceed with the following commands:
If the above command outputs the version information for GNU Make, you can proceed with the following commands:
cmake -G "MinGW Makefiles" ..
make
./ComputerGraphic.exe
All the output files created by int main()
function locate in build
directory.
./ComputerGraphic --h
./ComputerGraphic --tc all
./ComputerGraphic --ta -mnist ../mnist/199.csv
Initially, we must create graphic::Screen
object.
// graphic::Screen(int width, int height)
graphic::Screen scr(w, h);
int width, height;
scr.shape(width, height); // Getting the `scr` shape
// graphic::Line(int x0, int y0, int x1, int y1)
scr << graphic::Line(27, 17, 11, 27); // Directly draw
// scr::drawline(int x0, int y0, int x1, int y1)
scr.drawline(1, 1, 11, 5); // Recommence using this way
std::cout << scr; // Print the screen onto console/terminal
scr.reset(); // Reset all Pixel
// graphic::Circle(int x, int y, int r)
scr << graphic::Circle(25, 25, 15);
// graphic::drawcircle(int x, int y, int r)
scr.drawcircle(25, 17, 5);
scr.drawcircle(17, 25, 5);
scr.drawcircle(25, 33, 5);
scr.drawcircle(33, 25, 5);
scr.drawcircle(3, 3, 1);
scr.drawcircle(8, 8, 0);
std::cout << scr;
![]() |
![]() |
In this example, we will plot f(x) = 0.01*x^3 - 3x
in range [-16, 16]
.
// Screen::discretePlot(int x_start, int x_end, int (* f)(int))
scr.discretePlot(-16, 16,[](int x) -> int {
return (int) (std::pow(x, 3) / 100 - 3 * x);
});
std::cout << scr;
// Screen::plot(int x_start, int x_end, int (* f)(int))
scr.plot(-16, 16,[](int x) -> int {
return (int) (std::pow(x, 3) / 100 - 3 * x);
});
std::cout << scr;
![]() |
![]() |
graphic::Screen scr(w, 51);
scr.setUp()->setMapChar(graphic::mapchar::std_dot);
scr.plot(0, w - 1,[](int x) -> int {
return (int) (25 * std::sin(0.2 * (x - 2)));
});
std::cout << scr;
std::ofstream file("write_ofstream0.txt");
file << scr;
file.close();
![]() |
![]() |
This is some example of animating using curesor
class.
Get more information on usage
at here & here
./ComputerGraphic --tc changeAt
./ComputerGraphic --ta -mnist 199.csv
Additionally, it can be used to simulate physical phenomenons.
./ComputerGraphic --ta -bouncing
./ComputerGraphic --ta -orbit
The left side simulates the motion of a rigid object under gravity with fluid resistance, while the right side simulates the motion of an object experiencing only gravitational force.
graphic::Bitmap("filename") << scr;
graphic::Bitmap("filename.bmp") << scr;
graphic::Bitmap("filename") >> scr;
graphic::Bitmap("filename.bmp") >> scr;
graphic::Screen scr;
graphic::Bitmap("Steveeeeeee") >> scr;
int w, h;
scr.shape(w, h);
for (int j = 0; j < h; ++j) {
for (int i = 0; i < w; ++i) {
// Set the green component of all pixels to 100
scr.pixel(i, j).set_g(100); // Similar to red & blue
}
}
graphic::Bitmap("Emotional Damage_green=100") << scr;
![]() |
![]() |
![]() |
![]() |
Check DOCS.md for more information.
MIT License (see LICENSE.txt
file).
Check REFERENCES.md for more information.