├── 10
├── 10.md
├── Qs.md
└── extra
│ └── Ch-10-image processing.docx
├── 11
├── 11.md
├── Qs.md
└── extra
│ └── Ch-12-Computer vision.docx
├── 12
├── 12.md
├── Qs.md
└── extra
│ └── Chapter 08-Game Design Basics.docx
├── .gitattributes
├── .gitignore
├── 01
├── 01.md
├── Qs.md
├── demo
│ ├── 01.py
│ ├── 02.py
│ ├── 03.py
│ └── 04.py
└── extra
│ ├── Ch-01-introduction.docx
│ └── chapter-01-introduction.pptx
├── 02
├── 02.md
├── Qs.md
├── chapter-02-color theory.pdf
└── extra
│ ├── Ch-02-Color models and color spaces.docx
│ └── chapter-03-color theory.pptx
├── 03
├── 03.md
├── CGChapterSix.pptx
├── Qs.md
└── extra
│ ├── Ch-03-Graphics primitives.docx
│ └── chapter-03-Scan conversion.pptx
├── 04
├── 04.md
├── Qs.md
├── Tutorial
│ ├── 01.html
│ ├── 02.html
│ ├── 03.html
│ ├── 04.html
│ ├── 05.html
│ ├── 06.html
│ ├── 07.html
│ ├── 08.html
│ ├── 09.html
│ ├── 10.html
│ ├── 11.html
│ ├── 13.html
│ ├── 14.html
│ ├── 15.html
│ ├── 16.html
│ ├── 17.html
│ ├── 18.html
│ ├── 19.html
│ ├── 20.html
│ ├── 21.html
│ ├── picture.png
│ └── sprite.jpg
├── extra
│ └── Ch-04-HTML 5 canvas and SVG.docx
└── main.md
├── 05
├── 05.md
├── A-Math for game Developers.pdf
├── Qs.md
└── extra
│ ├── Ch-05-2D Transformations.docx
│ └── chapter-5-2D transformation.pptx
├── 06
├── 06.md
├── AR-VR-MR introduction-V2.pdf
├── Qs.md
└── extra
│ ├── Chapter06-Math, Basic Techniques and Animation Basics.docx
│ ├── Lecture07-DemoMath.zip
│ └── slides
│ ├── Chapter 06- Math and Animation for game Developers.pdf
│ └── Chapter 06- Math and Animation for game Developers.pptx
├── 07
├── 07.md
├── Qs.md
└── extra
│ ├── Chapter 07-3d basics.pptx
│ └── Chapter07-Three Dimensional Graphics.docx
├── 08
├── 08.md
├── Qs.md
└── extra
│ ├── Chapter-11-Introduction to medical applications.docx
│ └── Introduction AR-VR-v6.pptx
├── 09
├── 09.md
├── Qs.md
└── extra
│ └── CH-09-Data visualization.docx
├── 99-Lab-Manual
├── Lab 01- Gimp Basics.docx
├── Lab 02- Inkscape Basics -part 1.docx
├── Lab 03- Inkscape case studies-part 2.docx
├── Lab 04- Synfig studio-part 1.docx
├── Lab 05- Synfig studio-part 2.docx
├── Lab 06-Blender 3d Basics - part 1.docx
├── Lab 07-Blender 3d Basics - part 2.docx
├── Lab 08-Html canvas graphics.docx
├── Lab 09- Unity Basics - part 1.docx
└── Lab 10- Unity Basics - part 2.docx
├── LICENSE
└── README.md
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 |
9 | # Distribution / packaging
10 | .Python
11 | build/
12 | develop-eggs/
13 | dist/
14 | downloads/
15 | eggs/
16 | .eggs/
17 | lib/
18 | lib64/
19 | parts/
20 | sdist/
21 | var/
22 | wheels/
23 | share/python-wheels/
24 | *.egg-info/
25 | .installed.cfg
26 | *.egg
27 | MANIFEST
28 |
29 | # PyInstaller
30 | # Usually these files are written by a python script from a template
31 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
32 | *.manifest
33 | *.spec
34 |
35 | # Installer logs
36 | pip-log.txt
37 | pip-delete-this-directory.txt
38 |
39 | # Unit test / coverage reports
40 | htmlcov/
41 | .tox/
42 | .nox/
43 | .coverage
44 | .coverage.*
45 | .cache
46 | nosetests.xml
47 | coverage.xml
48 | *.cover
49 | *.py,cover
50 | .hypothesis/
51 | .pytest_cache/
52 | cover/
53 |
54 | # Translations
55 | *.mo
56 | *.pot
57 |
58 | # Django stuff:
59 | *.log
60 | local_settings.py
61 | db.sqlite3
62 | db.sqlite3-journal
63 |
64 | # Flask stuff:
65 | instance/
66 | .webassets-cache
67 |
68 | # Scrapy stuff:
69 | .scrapy
70 |
71 | # Sphinx documentation
72 | docs/_build/
73 |
74 | # PyBuilder
75 | .pybuilder/
76 | target/
77 |
78 | # Jupyter Notebook
79 | .ipynb_checkpoints
80 |
81 | # IPython
82 | profile_default/
83 | ipython_config.py
84 |
85 | # pyenv
86 | # For a library or package, you might want to ignore these files since the code is
87 | # intended to run in multiple environments; otherwise, check them in:
88 | # .python-version
89 |
90 | # pipenv
91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
94 | # install all needed dependencies.
95 | #Pipfile.lock
96 |
97 | # poetry
98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99 | # This is especially recommended for binary packages to ensure reproducibility, and is more
100 | # commonly ignored for libraries.
101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102 | #poetry.lock
103 |
104 | # pdm
105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106 | #pdm.lock
107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108 | # in version control.
109 | # https://pdm.fming.dev/#use-with-ide
110 | .pdm.toml
111 |
112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113 | __pypackages__/
114 |
115 | # Celery stuff
116 | celerybeat-schedule
117 | celerybeat.pid
118 |
119 | # SageMath parsed files
120 | *.sage.py
121 |
122 | # Environments
123 | .env
124 | .venv
125 | env/
126 | venv/
127 | ENV/
128 | env.bak/
129 | venv.bak/
130 |
131 | # Spyder project settings
132 | .spyderproject
133 | .spyproject
134 |
135 | # Rope project settings
136 | .ropeproject
137 |
138 | # mkdocs documentation
139 | /site
140 |
141 | # mypy
142 | .mypy_cache/
143 | .dmypy.json
144 | dmypy.json
145 |
146 | # Pyre type checker
147 | .pyre/
148 |
149 | # pytype static type analyzer
150 | .pytype/
151 |
152 | # Cython debug symbols
153 | cython_debug/
154 |
155 | # PyCharm
156 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158 | # and can be added to the global gitignore or merged into this file. For a more nuclear
159 | # option (not recommended) you can uncomment the following to ignore the entire idea folder.
160 | #.idea/
161 |
--------------------------------------------------------------------------------
/01/01.md:
--------------------------------------------------------------------------------
1 | # بسم الله الرحمن الرحيم
2 | # الحمد لله وحده، والصلاة والسلام على من لا نبي بعده ﷺ
3 |
4 | # Introduction to Computer Graphics 🎨✨🖥️
5 |
6 | ## 1. Overview
7 | Computer Graphics (CG) is an interdisciplinary field that encompasses the generation, manipulation, and visualization of visual content through computational methods. It integrates principles from **mathematics, physics, and computer science** to produce graphical representations of data and objects. With applications spanning diverse industries—such as **interactive entertainment, scientific simulation, engineering design, and artificial intelligence**—computer graphics is a fundamental domain within modern computing. Advances in computational power, rendering techniques, and artificial intelligence have significantly expanded its capabilities, enabling real-time rendering, photorealistic simulations, and immersive virtual environments. 🎮🖌️💡
8 |
9 | ## 2. Importance of Computer Graphics 🎥🕹️🖼️
10 | The study of computer graphics is essential due to its transformative impact on numerous fields:
11 | - **Entertainment and Media:** Feature films, television productions, game development, and virtual production pipelines rely on advanced graphics techniques for realism and immersion.
12 | - **Scientific Visualization:** High-fidelity visual representations of complex scientific phenomena, such as molecular dynamics, astrophysics simulations, and medical imaging.
13 | - **Engineering and Design:** Applications in **Computer-Aided Design (CAD), architectural visualization, and product prototyping** streamline development cycles.
14 | - **Medical Imaging and Bioinformatics:** 3D imaging techniques such as **Magnetic Resonance Imaging (MRI)** and **Computed Tomography (CT)** scans aid in medical diagnostics and research.
15 | - **Artificial Intelligence and Machine Learning:** AI-driven techniques such as **neural rendering, style transfer, and generative adversarial networks (GANs)** are revolutionizing content creation.
16 | - **Virtual and Augmented Reality (VR/AR):** VR simulations enhance training, education, and interactive experiences, while AR applications are increasingly integrated into mobile platforms and smart devices. 🌐🧠📱
17 |
18 | ## 3. Fundamental Concepts 📊🔢🎭
19 | ### 3.1 Definition and Scope
20 | Computer graphics is the computational representation and manipulation of visual data. It is classified into two primary types:
21 | - **Raster Graphics:** Pixel-based images stored in a matrix format (e.g., JPEG, PNG), commonly used for digital images and textures.
22 | - **Vector Graphics:** Resolution-independent graphics defined using mathematical equations (e.g., SVG, PDF), suitable for scalable illustrations and typography. 🖍️🖼️📐
23 |
24 | ### 3.2 Display Parameters 📏🖥️🔍
25 | - **Pixel:** The smallest addressable unit in a digital image, serving as a fundamental building block for raster graphics.
26 | - **Resolution:** Defined as the number of pixels along the width and height of an image (e.g., `1920×1080`).
27 | - **Aspect Ratio:** The proportional relationship between width and height (e.g., `16:9`).
28 | - **Color Depth:** Measured in bits per pixel, dictating the number of colors an image can represent (e.g., 24-bit color supports 16.7 million colors). 🎨📊🌈
29 |
30 | ### 3.3 Rendering and Shading Techniques 🖌️✨💡
31 | Rendering is the process of generating a 2D image from a 3D model through computational algorithms. Key techniques include:
32 | - **Rasterization:** Converting geometric data into pixel data for display.
33 | - **Ray Tracing:** Simulating light behavior for photorealistic shading and reflections.
34 | - **Global Illumination:** Advanced lighting calculations that simulate natural light behavior.
35 | - **Shading Models:** Includes Phong, Gouraud, and physically based rendering (PBR) techniques for accurate material depiction. 🕶️🔦📸
36 |
37 | ## 4. Applications of Computer Graphics 🏗️🎮📺
38 | | Field | Application Examples |
39 | |----------------------|---------------------|
40 | | **Game Development** | Real-time graphics engines (Unity, Unreal Engine), character animation |
41 | | **Cinematic VFX** | CGI effects, motion capture, digital compositing |
42 | | **Virtual Reality** | Immersive simulations, interactive environments |
43 | | **Medical Imaging** | 3D organ modeling, surgical planning, biomedical visualization |
44 | | **Engineering & CAD** | Mechanical modeling, architectural visualization |
45 | | **Artificial Intelligence** | Neural rendering, AI-driven animation, generative design |
46 |
47 | ## 5. Graphics Processing and APIs 🖥️⚡📜
48 | ### 5.1 Graphics Processing Unit (GPU)
49 | The **GPU** is a specialized processor optimized for parallel computation, significantly enhancing rendering performance. Key advancements in GPU technology include:
50 | - **Ray Tracing Acceleration:** NVIDIA RTX series and AMD Radeon RX 6000 series enable real-time ray tracing.
51 | - **AI-Assisted Rendering:** GPUs are increasingly leveraged for deep learning-based content generation and enhancement. 🎮💾🖥️
52 |
53 | ### 5.2 Graphics APIs 🛠️📜⚡
54 | Graphics libraries provide an abstraction layer for hardware acceleration. Common APIs include:
55 | - **OpenGL:** A widely used cross-platform graphics API for 2D and 3D rendering.
56 | - **DirectX:** Microsoft’s API suite for gaming and multimedia applications.
57 | - **WebGL:** A JavaScript API enabling GPU-accelerated graphics within web browsers.
58 | - **Vulkan:** A low-overhead API optimized for high-performance graphics workloads. 🌍🖱️🛠️
59 |
60 | ## 6. Python for Computer Graphics 🐍🎨🖼️
61 | Python is a versatile language for graphics programming, with extensive support for both 2D and 3D applications:
62 | - **Pygame:** Simple 2D game development framework.
63 | - **PyOpenGL:** Python bindings for OpenGL, facilitating 3D rendering.
64 | - **Matplotlib & Seaborn:** Data visualization libraries for generating plots and heatmaps.
65 | - **Pillow (PIL):** Image processing library for manipulation of raster graphics.
66 | - **TensorFlow/Keras:** Machine learning frameworks supporting AI-driven image generation. 🖥️🐍📊
67 |
68 | ### Example: Drawing a Simple 2D Shape with Pygame 🎨🐍🎮
69 | ```python
70 | import pygame
71 | pygame.init()
72 |
73 | # Set up display
74 | screen = pygame.display.set_mode((500, 500))
75 | pygame.display.set_caption("Simple Graphics")
76 |
77 | # Define colors
78 | WHITE = (255, 255, 255)
79 | RED = (255, 0, 0)
80 |
81 | # Main loop
82 | running = True
83 | while running:
84 | for event in pygame.event.get():
85 | if event.type == pygame.QUIT:
86 | running = False
87 |
88 | screen.fill(WHITE)
89 | pygame.draw.circle(screen, RED, (250, 250), 50)
90 | pygame.display.flip()
91 |
92 | pygame.quit()
93 | ```
94 |
95 | ## 7. Research Directions 🔬📊🖥️
96 | The evolution of computer graphics continues to be shaped by cutting-edge research in:
97 | - **Real-Time Ray Tracing:** Efficient algorithms for interactive photorealistic rendering.
98 | - **Neural Rendering:** AI-driven techniques that enhance traditional rendering pipelines.
99 | - **Virtual and Augmented Reality:** The next generation of immersive computing.
100 | - **Procedural Content Generation:** Algorithmically generating textures, models, and environments.
101 | - **Holography and Next-Gen Displays:** Novel display technologies that redefine user experience. 🎥🖥️🔍
102 |
103 | Best Wishes
104 | Dr. Haitham El-Ghareeb
105 | 🚀📈💡
106 |
107 |
--------------------------------------------------------------------------------
/01/Qs.md:
--------------------------------------------------------------------------------
1 | # بسم الله الرحمن الرحيم
2 | # الحمد لله وحده، والصلاة والسلام على من لا نبي بعده ﷺ
3 |
4 | # Computer Graphics - Multiple Choice Questions (MCQs)
5 |
6 | This set of multiple-choice questions is designed for college-level students studying **Computer Graphics**.
7 | Try to answer the questions before checking the answers at the bottom of the page.
8 |
9 | ## Easy Questions (1-10)
10 |
11 | 1. What is the smallest addressable unit in a raster image?
12 | - a) Voxel
13 | - b) Pixel
14 | - c) Polygon
15 | - d) Triangle
16 |
17 | 2. Which of the following is NOT a graphics API?
18 | - a) OpenGL
19 | - b) DirectX
20 | - c) Vulkan
21 | - d) Python
22 |
23 | 3. The term **rendering** refers to:
24 | - a) The process of creating 3D models
25 | - b) The process of converting 3D models into 2D images
26 | - c) The process of defining colors in a raster image
27 | - d) The process of increasing image resolution
28 |
29 | 4. **RGB** stands for:
30 | - a) Red, Green, Blue
31 | - b) Random Graphic Blend
32 | - c) Raster Graphics Binary
33 | - d) Rendered Graphics Bitmap
34 |
35 | 5. In **2D graphics**, images are represented using:
36 | - a) X and Y coordinates
37 | - b) X, Y, and Z coordinates
38 | - c) Voxels
39 | - d) Triangular Meshes
40 |
41 | 6. **Which of these is a raster graphics format?**
42 | - a) SVG
43 | - b) PNG
44 | - c) PDF
45 | - d) EPS
46 |
47 | 7. Which device is primarily responsible for rendering graphics?
48 | - a) CPU
49 | - b) RAM
50 | - c) GPU
51 | - d) SSD
52 |
53 | 8. **Which of the following shading models provides the most realistic lighting?**
54 | - a) Flat shading
55 | - b) Gouraud shading
56 | - c) Phong shading
57 | - d) Wireframe shading
58 |
59 | 9. What is the primary advantage of **vector graphics** over raster graphics?
60 | - a) They require more storage
61 | - b) They are resolution-independent
62 | - c) They use pixels to store data
63 | - d) They cannot be scaled
64 |
65 | 10. **Which graphics software library is used for 3D rendering in Python?**
66 | - a) NumPy
67 | - b) Matplotlib
68 | - c) PyOpenGL
69 | - d) Pandas
70 |
71 | ---
72 |
73 | ## Medium Questions (11-20)
74 |
75 | 11. The process of converting continuous images into discrete pixels is known as:
76 | - a) Rasterization
77 | - b) Ray tracing
78 | - c) Sampling
79 | - d) Aliasing
80 |
81 | 12. In 3D modeling, what is a **polygonal mesh** composed of?
82 | - a) Points
83 | - b) Lines
84 | - c) Triangles and polygons
85 | - d) Voxels
86 |
87 | 13. Which graphics rendering technique simulates the behavior of light for realism?
88 | - a) Rasterization
89 | - b) Ray tracing
90 | - c) Phong shading
91 | - d) Texture mapping
92 |
93 | 14. What is the primary purpose of **z-buffering**?
94 | - a) To store textures
95 | - b) To handle image resolution
96 | - c) To resolve depth conflicts in rendering
97 | - d) To improve performance of rasterization
98 |
99 | 15. In **real-time graphics**, which factor is crucial for smooth user experience?
100 | - a) High resolution
101 | - b) Low frame rate
102 | - c) High frame rate
103 | - d) Large textures
104 |
105 | 16. **Which of the following is a key feature of Physically Based Rendering (PBR)?**
106 | - a) It ignores light interactions
107 | - b) It uses physically accurate lighting and materials
108 | - c) It applies simple color blending
109 | - d) It renders objects only in wireframe mode
110 |
111 | 17. What does **anti-aliasing** improve in an image?
112 | - a) Performance
113 | - b) Sharpness of edges
114 | - c) Resolution
115 | - d) Storage size
116 |
117 | 18. **Which technique allows real-time rendering by approximating global illumination?**
118 | - a) Ray tracing
119 | - b) Rasterization
120 | - c) Screen space ambient occlusion (SSAO)
121 | - d) Wireframe modeling
122 |
123 | 19. What is **bilinear filtering** used for?
124 | - a) Anti-aliasing
125 | - b) Texture smoothing
126 | - c) Increasing resolution
127 | - d) Depth testing
128 |
129 | 20. **Which property determines how reflective an object is in a 3D scene?**
130 | - a) Diffuse lighting
131 | - b) Ambient lighting
132 | - c) Specular lighting
133 | - d) Shadow mapping
134 |
135 | ---
136 |
137 | ## Hard Questions (21-30)
138 |
139 | 21. Which **acceleration structure** is commonly used in ray tracing for optimization?
140 | - a) Octree
141 | - b) KD-tree
142 | - c) Bounding Volume Hierarchy (BVH)
143 | - d) Quadtree
144 |
145 | 22. **What is the primary challenge of real-time ray tracing?**
146 | - a) Aliasing
147 | - b) High computational cost
148 | - c) Low resolution
149 | - d) Lack of realism
150 |
151 | 23. **Why are shaders important in computer graphics?**
152 | - a) They define how 3D objects are stored
153 | - b) They dictate how pixels and vertices are processed
154 | - c) They control polygon count
155 | - d) They store rendering settings
156 |
157 | 24. **Which of the following is NOT a texture mapping technique?**
158 | - a) Bump mapping
159 | - b) Displacement mapping
160 | - c) Screen space reflection
161 | - d) Parallax mapping
162 |
163 | 25. In **GPU programming**, what is a "fragment"?
164 | - a) A pixel before final color calculation
165 | - b) A part of a 3D model
166 | - c) A section of a mesh
167 | - d) A compressed texture
168 |
169 | 26. **Which data structure is used for spatial partitioning in real-time rendering?**
170 | - a) Hash table
171 | - b) Binary search tree
172 | - c) BSP tree
173 | - d) Linked list
174 |
175 | 27. **Why is tessellation used in 3D graphics?**
176 | - a) To store texture data
177 | - b) To increase polygon count dynamically
178 | - c) To smooth out textures
179 | - d) To speed up rendering
180 |
181 | 28. **Which technique is used to compute realistic soft shadows?**
182 | - a) Shadow mapping
183 | - b) Ambient occlusion
184 | - c) Ray marching
185 | - d) Screen space reflection
186 |
187 | 29. **What is the primary purpose of MIP mapping?**
188 | - a) Reducing texture aliasing
189 | - b) Increasing texture resolution
190 | - c) Applying realistic reflections
191 | - d) Enhancing shadow accuracy
192 |
193 | 30. **What does a Compute Shader primarily do?**
194 | - a) Handles lighting calculations
195 | - b) Runs general-purpose computations on the GPU
196 | - c) Performs physics simulations
197 | - d) Generates 3D models
198 |
199 |
200 | ## Answers
201 |
202 |
203 | Click to reveal answers
204 |
205 | 1. **b**
206 | 2. **d**
207 | 3. **b**
208 | 4. **a**
209 | 5. **a**
210 | 6. **b**
211 | 7. **c**
212 | 8. **c**
213 | 9. **b**
214 | 10. **c**
215 | 11. **c**
216 | 12. **c**
217 | 13. **b**
218 | 14. **c**
219 | 15. **c**
220 | 16. **b**
221 | 17. **b**
222 | 18. **c**
223 | 19. **b**
224 | 20. **c**
225 | 21. **c**
226 | 22. **b**
227 | 23. **b**
228 | 24. **c**
229 | 25. **a**
230 | 26. **c**
231 | 27. **b**
232 | 28. **a**
233 | 29. **a**
234 | 30. **b**
235 |
236 |
237 |
238 | Hope this helps! 🚀😃
239 |
--------------------------------------------------------------------------------
/01/demo/01.py:
--------------------------------------------------------------------------------
1 | import pygame
2 | pygame.init()
3 |
4 | # Set up display
5 | screen = pygame.display.set_mode((500, 500))
6 | pygame.display.set_caption("Simple Graphics")
7 |
8 | # Define colors
9 | WHITE = (255, 255, 255)
10 | RED = (255, 0, 0)
11 |
12 | # Main loop
13 | running = True
14 | while running:
15 | for event in pygame.event.get():
16 | if event.type == pygame.QUIT:
17 | running = False
18 |
19 | screen.fill(WHITE)
20 | pygame.draw.circle(screen, RED, (250, 250), 50)
21 | pygame.display.flip()
22 |
23 | pygame.quit()
--------------------------------------------------------------------------------
/01/demo/02.py:
--------------------------------------------------------------------------------
1 | #Here is a simple Pygame script that introduces the basics of computer graphics concepts like drawing shapes, handling user input, and animating objects.
2 | #The script demonstrates:
3 | #Drawing basic shapes (rectangle, circle, line)
4 | #Changing colors dynamically
5 | #Handling user events (keyboard and mouse interactions)
6 | #Basic animation (moving a shape)
7 |
8 | import pygame
9 | import sys
10 |
11 | # Initialize pygame
12 | pygame.init()
13 |
14 | # Screen dimensions
15 | WIDTH, HEIGHT = 800, 600
16 | # Create the game window
17 | screen = pygame.display.set_mode((WIDTH, HEIGHT))
18 | # Set the title of the window
19 | pygame.display.set_caption("Computer Graphics Basics with Pygame")
20 |
21 | # Define colors using RGB format
22 | WHITE = (255, 255, 255) # Background color
23 | RED = (255, 0, 0) # Rectangle color
24 | BLUE = (0, 0, 255) # Circle color
25 | GREEN = (0, 255, 0) # Line color
26 |
27 | # Circle properties
28 | circle_x, circle_y = WIDTH // 2, HEIGHT // 2 # Initial position of the circle
29 | circle_radius = 30 # Radius of the circle
30 | circle_dx, circle_dy = 4, 4 # Speed and direction of movement
31 |
32 | # Rectangle properties
33 | rect_x, rect_y = 100, 500 # Initial position of the rectangle
34 | rect_width, rect_height = 100, 50 # Dimensions of the rectangle
35 | rect_speed = 5 # Speed of movement for the rectangle
36 |
37 | # Game loop to keep the window open and handle interactions
38 | running = True
39 | while running:
40 | # Fill the screen with white to clear the previous frame
41 | screen.fill(WHITE)
42 |
43 | # Event handling loop to check for user input
44 | for event in pygame.event.get():
45 | if event.type == pygame.QUIT: # If the user clicks the close button, exit the loop
46 | running = False
47 |
48 | # Capture the state of the keyboard
49 | keys = pygame.key.get_pressed()
50 | # Move rectangle based on arrow key presses
51 | if keys[pygame.K_LEFT] and rect_x > 0:
52 | rect_x -= rect_speed # Move left
53 | if keys[pygame.K_RIGHT] and rect_x < WIDTH - rect_width:
54 | rect_x += rect_speed # Move right
55 | if keys[pygame.K_UP] and rect_y > 0:
56 | rect_y -= rect_speed # Move up
57 | if keys[pygame.K_DOWN] and rect_y < HEIGHT - rect_height:
58 | rect_y += rect_speed # Move down
59 |
60 | # Move the circle (simulating a bouncing ball)
61 | circle_x += circle_dx
62 | circle_y += circle_dy
63 |
64 | # Bounce the circle off the edges of the screen
65 | if circle_x - circle_radius <= 0 or circle_x + circle_radius >= WIDTH:
66 | circle_dx *= -1 # Reverse horizontal direction
67 | if circle_y - circle_radius <= 0 or circle_y + circle_radius >= HEIGHT:
68 | circle_dy *= -1 # Reverse vertical direction
69 |
70 | # Draw a red rectangle at the updated position
71 | pygame.draw.rect(screen, RED, (rect_x, rect_y, rect_width, rect_height))
72 | # Draw a blue circle at the updated position
73 | pygame.draw.circle(screen, BLUE, (circle_x, circle_y), circle_radius)
74 | # Draw a green horizontal line across the screen for reference
75 | pygame.draw.line(screen, GREEN, (0, HEIGHT // 2), (WIDTH, HEIGHT // 2), 2)
76 |
77 | # Refresh the screen with the updated drawings
78 | pygame.display.flip()
79 | # Introduce a small delay to control the frame rate
80 | pygame.time.delay(30)
81 |
82 | # Quit pygame when the loop ends
83 | pygame.quit()
84 | sys.exit()
85 |
--------------------------------------------------------------------------------
/01/demo/03.py:
--------------------------------------------------------------------------------
1 | import pygame
2 | import sys
3 |
4 | # Initialize pygame
5 | pygame.init()
6 |
7 | # Screen dimensions
8 | WIDTH, HEIGHT = 800, 600
9 | # Create the game window
10 | screen = pygame.display.set_mode((WIDTH, HEIGHT))
11 | # Set the title of the window
12 | pygame.display.set_caption("Computer Graphics Basics with Pygame")
13 |
14 | # Define colors using RGB format
15 | WHITE = (255, 255, 255) # Background color
16 | RED = (255, 0, 0) # Rectangle color
17 | BLUE = (0, 0, 255) # Circle color
18 | GREEN = (0, 255, 0) # Line color
19 |
20 | # Circle properties
21 | circle_x, circle_y = WIDTH // 2, HEIGHT // 2 # Initial position of the circle
22 | circle_radius = 30 # Radius of the circle
23 | circle_dx, circle_dy = 4, 4 # Speed and direction of movement
24 |
25 | # Rectangle properties
26 | rect_x, rect_y = 100, 500 # Initial position of the rectangle
27 | rect_width, rect_height = 100, 50 # Dimensions of the rectangle
28 | rect_speed = 5 # Speed of movement for the rectangle
29 |
30 | # Game loop to keep the window open and handle interactions
31 | running = True
32 | while running:
33 | # Fill the screen with white to clear the previous frame
34 | screen.fill(WHITE)
35 |
36 | # Event handling loop to check for user input
37 | for event in pygame.event.get():
38 | if event.type == pygame.QUIT: # If the user clicks the close button, exit the loop
39 | running = False
40 |
41 | # Capture the state of the keyboard
42 | keys = pygame.key.get_pressed()
43 | # Move rectangle based on arrow key presses
44 | if keys[pygame.K_LEFT] and rect_x > 0:
45 | rect_x -= rect_speed # Move left
46 | if keys[pygame.K_RIGHT] and rect_x < WIDTH - rect_width:
47 | rect_x += rect_speed # Move right
48 | if keys[pygame.K_UP] and rect_y > 0:
49 | rect_y -= rect_speed # Move up
50 | if keys[pygame.K_DOWN] and rect_y < HEIGHT - rect_height:
51 | rect_y += rect_speed # Move down
52 |
53 | # Move the circle (simulating a bouncing ball)
54 | circle_x += circle_dx
55 | circle_y += circle_dy
56 |
57 | # Bounce the circle off the edges of the screen
58 | if circle_x - circle_radius <= 0 or circle_x + circle_radius >= WIDTH:
59 | circle_dx *= -1 # Reverse horizontal direction
60 | if circle_y - circle_radius <= 0 or circle_y + circle_radius >= HEIGHT:
61 | circle_dy *= -1 # Reverse vertical direction
62 |
63 | # Check for collision between the ball and the rectangle
64 | if (rect_x < circle_x < rect_x + rect_width) and (rect_y < circle_y + circle_radius < rect_y + rect_height):
65 | circle_dy *= -1 # Reverse the ball's vertical direction
66 |
67 | # Draw a red rectangle at the updated position
68 | pygame.draw.rect(screen, RED, (rect_x, rect_y, rect_width, rect_height))
69 | # Draw a blue circle at the updated position
70 | pygame.draw.circle(screen, BLUE, (circle_x, circle_y), circle_radius)
71 | # Draw a green horizontal line across the screen for reference
72 | pygame.draw.line(screen, GREEN, (0, HEIGHT // 2), (WIDTH, HEIGHT // 2), 2)
73 |
74 | # Refresh the screen with the updated drawings
75 | pygame.display.flip()
76 | # Introduce a small delay to control the frame rate
77 | pygame.time.delay(30)
78 |
79 | # Quit pygame when the loop ends
80 | pygame.quit()
81 | sys.exit()
82 |
--------------------------------------------------------------------------------
/01/demo/04.py:
--------------------------------------------------------------------------------
1 | import pygame
2 | import sys
3 |
4 | # Initialize pygame
5 | pygame.init()
6 |
7 | # Screen dimensions
8 | WIDTH, HEIGHT = 800, 600
9 | # Create the game window
10 | screen = pygame.display.set_mode((WIDTH, HEIGHT))
11 | # Set the title of the window
12 | pygame.display.set_caption("Computer Graphics Basics with Pygame")
13 |
14 | # Define colors using RGB format
15 | WHITE = (255, 255, 255) # Background color
16 | RED = (255, 0, 0) # Rectangle color
17 | BLUE = (0, 0, 255) # Circle color
18 | GREEN = (0, 255, 0) # Line color
19 | BLACK = (0, 0, 0) # Score text color
20 |
21 | # Font for displaying score
22 | font = pygame.font.Font(None, 36)
23 |
24 | # Circle properties
25 | circle_x, circle_y = WIDTH // 2, HEIGHT // 2 # Initial position of the circle
26 | circle_radius = 30 # Radius of the circle
27 | circle_dx, circle_dy = 4, 4 # Speed and direction of movement
28 |
29 | # Rectangle properties
30 | rect_x, rect_y = 100, 500 # Initial position of the rectangle
31 | rect_width, rect_height = 100, 50 # Dimensions of the rectangle
32 | rect_speed = 5 # Speed of movement for the rectangle
33 |
34 | # Score
35 | score = 0
36 |
37 | # Game loop to keep the window open and handle interactions
38 | running = True
39 | while running:
40 | # Fill the screen with white to clear the previous frame
41 | screen.fill(WHITE)
42 |
43 | # Event handling loop to check for user input
44 | for event in pygame.event.get():
45 | if event.type == pygame.QUIT: # If the user clicks the close button, exit the loop
46 | running = False
47 |
48 | # Capture the state of the keyboard
49 | keys = pygame.key.get_pressed()
50 | # Move rectangle based on arrow key presses
51 | if keys[pygame.K_LEFT] and rect_x > 0:
52 | rect_x -= rect_speed # Move left
53 | if keys[pygame.K_RIGHT] and rect_x < WIDTH - rect_width:
54 | rect_x += rect_speed # Move right
55 | if keys[pygame.K_UP] and rect_y > 0:
56 | rect_y -= rect_speed # Move up
57 | if keys[pygame.K_DOWN] and rect_y < HEIGHT - rect_height:
58 | rect_y += rect_speed # Move down
59 |
60 | # Move the circle (simulating a bouncing ball)
61 | circle_x += circle_dx
62 | circle_y += circle_dy
63 |
64 | # Bounce the circle off the edges of the screen
65 | if circle_x - circle_radius <= 0 or circle_x + circle_radius >= WIDTH:
66 | circle_dx *= -1 # Reverse horizontal direction
67 | if circle_y - circle_radius <= 0 or circle_y + circle_radius >= HEIGHT:
68 | circle_dy *= -1 # Reverse vertical direction
69 |
70 | # Check for collision between the ball and the rectangle
71 | if (rect_x < circle_x < rect_x + rect_width) and (rect_y < circle_y + circle_radius < rect_y + rect_height):
72 | circle_dy *= -1 # Reverse the ball's vertical direction
73 | score += 1 # Increase score when collision happens
74 |
75 | # Draw a red rectangle at the updated position
76 | pygame.draw.rect(screen, RED, (rect_x, rect_y, rect_width, rect_height))
77 | # Draw a blue circle at the updated position
78 | pygame.draw.circle(screen, BLUE, (circle_x, circle_y), circle_radius)
79 | # Draw a green horizontal line across the screen for reference
80 | pygame.draw.line(screen, GREEN, (0, HEIGHT // 2), (WIDTH, HEIGHT // 2), 2)
81 |
82 | # Render score text
83 | score_text = font.render(f"Score: {score}", True, BLACK)
84 | screen.blit(score_text, (10, 10)) # Display score at top-left corner
85 |
86 | # Refresh the screen with the updated drawings
87 | pygame.display.flip()
88 | # Introduce a small delay to control the frame rate
89 | pygame.time.delay(30)
90 |
91 | # Quit pygame when the loop ends
92 | pygame.quit()
93 | sys.exit()
94 |
--------------------------------------------------------------------------------
/01/extra/Ch-01-introduction.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helghareeb/GFX/a301172d3d838aa2eeff1bde00741054b87aaff7/01/extra/Ch-01-introduction.docx
--------------------------------------------------------------------------------
/01/extra/chapter-01-introduction.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helghareeb/GFX/a301172d3d838aa2eeff1bde00741054b87aaff7/01/extra/chapter-01-introduction.pptx
--------------------------------------------------------------------------------
/02/02.md:
--------------------------------------------------------------------------------
1 | # بسم الله الرحمن الرحيم
2 | # الحمد لله وحده، والصلاة والسلام على من لا نبي بعده ﷺ
3 |
4 | **Chapter: Color Models, Color Spaces, and Color Theory** 🎨✨🌈
5 |
6 | ## **Introduction to Color** 🎨🖌️🌟
7 | Color is an essential property of objects, influencing both human perception and computational analysis. It serves as a crucial factor in object recognition, visual communication, and artistic representation. The study of color encompasses various models and spaces that standardize its representation, storage, and transmission across multiple platforms. This chapter delves into color theory, explores different color models, and introduces practical applications using Python for computational color processing.
8 |
9 | ### **The Science of Color Perception** 👁️🌈🔬
10 | Color perception results from the interaction between light, objects, and the human visual system. Light, an electromagnetic wave, varies in wavelength, producing different colors within the visible spectrum (approximately 400-700 nm). The human eye contains photoreceptor cells—rods for low-light vision and cones for color perception. These cones are sensitive to three primary wavelengths:
11 | - **Short (S-cones)**: Detect blue (peak sensitivity at ~420 nm).
12 | - **Medium (M-cones)**: Detect green (peak sensitivity at ~534 nm).
13 | - **Long (L-cones)**: Detect red (peak sensitivity at ~564 nm).
14 |
15 | The brain processes signals from these cones to construct the perception of color, which is influenced by surrounding colors, brightness, and viewing conditions.
16 |
17 | ## **Color Models and Color Spaces** 📊🎨💡
18 | ### **What is a Color Model?** 🖍️📏🎭
19 | A color model is a mathematical framework describing how colors are represented as numerical values. A color space is a specific implementation of a color model, defining the range of colors that can be accurately depicted within a given system.
20 |
21 | ### **Common Color Models** 🎨🖥️🖨️
22 | #### **1. RGB (Red-Green-Blue) Model** 🔴🟢🔵
23 | The RGB model is an additive system used in digital displays. Colors are generated by combining different intensities of red, green, and blue light.
24 |
25 | #### **2. CMYK (Cyan-Magenta-Yellow-Black) Model** 🖨️🖌️📄
26 | The CMYK model is subtractive, used primarily in printing. Instead of emitting light, it relies on the absorption and reflection of light from printed surfaces.
27 |
28 | #### **3. HSI/HSV/HSL Models** 🌈🔧🎨
29 | These models are designed to align more closely with human color perception by separating chromatic components from brightness.
30 |
31 | #### **4. YIQ Color Model** 📺🎞️🔵
32 | The YIQ model is optimized for television broadcasting, ensuring compatibility with grayscale displays.
33 |
34 | ### **Color Spaces** 🌍🖍️🎨
35 | A color space defines the range of colors that can be represented within a given model.
36 |
37 | ## **Implementing Color Models in Python** 🐍💻🎨
38 | Python provides powerful tools for manipulating and visualizing color models. Libraries such as OpenCV, Matplotlib, and PIL allow for efficient color space conversion and image processing.
39 |
40 | ### **Using OpenCV for Color Model Conversions** 🖼️🔄📷
41 | ```python
42 | import cv2
43 | import numpy as np
44 |
45 | # Load an image
46 | image = cv2.imread('image.jpg')
47 |
48 | # Convert RGB to different color spaces
49 | hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
50 | yiq_image = cv2.cvtColor(image, cv2.COLOR_BGR2YCrCb)
51 | cmyk_image = 255 - image # Approximate CMYK conversion
52 |
53 | # Display images
54 | cv2.imshow('Original', image)
55 | cv2.imshow('HSV', hsv_image)
56 | cv2.imshow('YIQ', yiq_image)
57 | cv2.waitKey(0)
58 | cv2.destroyAllWindows()
59 | ```
60 |
61 | ### **Visualizing Colors with Matplotlib** 📊🌈📌
62 | ```python
63 | import matplotlib.pyplot as plt
64 |
65 | # Define primary RGB colors
66 | colors = ['red', 'green', 'blue']
67 |
68 | # Create a bar chart
69 | plt.bar(colors, [1, 1, 1], color=colors)
70 | plt.xlabel('Primary Colors')
71 | plt.ylabel('Intensity')
72 | plt.title('RGB Color Model')
73 | plt.show()
74 | ```
75 |
76 | ### **Generating a Color Palette with PIL** 🎨📷🖍️
77 | ```python
78 | from PIL import Image, ImageDraw
79 |
80 | # Create an image with a gradient of colors
81 | img = Image.new('RGB', (300, 100))
82 | draw = ImageDraw.Draw(img)
83 | for i in range(300):
84 | draw.line([(i, 0), (i, 100)], fill=(i, 100, 200))
85 | img.show()
86 | ```
87 |
88 | ## **Conclusion** 🎯📘🎨
89 | A comprehensive understanding of color models and spaces is vital for digital imaging, design, and computational applications. By leveraging Python tools such as OpenCV, Matplotlib, and PIL, professionals can process and visualize color data effectively. Whether for digital display, image processing, or print media, proper color representation ensures consistency and accuracy in visual communication. 🎨✨🔍
90 |
91 |
--------------------------------------------------------------------------------
/02/Qs.md:
--------------------------------------------------------------------------------
1 | # بسم الله الرحمن الرحيم
2 | # الحمد لله وحده، والصلاة والسلام على من لا نبي بعده ﷺ
3 |
4 |
5 | # **📌 Multiple-Choice Questions on Color Models and Color Theory**
6 |
7 | ## **Easy Level (10 Questions)**
8 |
9 | 1. **Which of the following is an additive color model used in digital displays?**
10 | - [ ] CMYK
11 | - [x] RGB
12 | - [ ] YIQ
13 | - [ ] HSL
14 |
15 | 2. **In the RGB color model, what color is produced by mixing red and green at full intensity?**
16 | - [ ] Blue
17 | - [x] Yellow
18 | - [ ] Cyan
19 | - [ ] White
20 |
21 | 3. **Which color model is primarily used for printing?**
22 | - [x] CMYK
23 | - [ ] RGB
24 | - [ ] HSI
25 | - [ ] YIQ
26 |
27 | 4. **What does the 'K' stand for in the CMYK color model?**
28 | - [ ] Cyan
29 | - [ ] Keyline
30 | - [x] Key (Black)
31 | - [ ] Kelvin
32 |
33 | 5. **Which of these models is used for human color perception?**
34 | - [ ] RGB
35 | - [x] HSI
36 | - [ ] CMYK
37 | - [ ] YIQ
38 |
39 | 6. **What is the main purpose of the YIQ color model?**
40 | - [ ] Web design
41 | - [ ] Printing
42 | - [x] Television broadcasting
43 | - [ ] 3D rendering
44 |
45 | 7. **What is the range of wavelengths for visible light in nanometers (nm)?**
46 | - [ ] 300-500 nm
47 | - [x] 400-700 nm
48 | - [ ] 200-600 nm
49 | - [ ] 500-900 nm
50 |
51 | 8. **Which of the following is NOT a primary color in the RGB model?**
52 | - [ ] Red
53 | - [x] Yellow
54 | - [ ] Green
55 | - [ ] Blue
56 |
57 | 9. **What is the main advantage of the HSL and HSV color models?**
58 | - [x] They better align with human perception
59 | - [ ] They use subtractive mixing
60 | - [ ] They are used for printing
61 | - [ ] They have a larger color gamut than RGB
62 |
63 | 10. **What happens when all RGB values are set to 255?**
64 | - [ ] Black
65 | - [x] White
66 | - [ ] Gray
67 | - [ ] Red
68 |
69 | ---
70 |
71 | ## **Medium Level (10 Questions)**
72 |
73 | 11. **Which of the following is NOT a perceptual property of color?**
74 | - [ ] Hue
75 | - [ ] Saturation
76 | - [ ] Brightness
77 | - [x] Luminance
78 |
79 | 12. **In the CIE chromaticity diagram, what does the white point represent?**
80 | - [ ] Maximum intensity
81 | - [x] A neutral color balance reference
82 | - [ ] Fully saturated color
83 | - [ ] The brightest visible color
84 |
85 | 13. **Which color model is based on the opponent-process theory of vision?**
86 | - [ ] RGB
87 | - [ ] CMYK
88 | - [x] YIQ
89 | - [ ] HSV
90 |
91 | 14. **What is the primary reason for using gamma correction in digital displays?**
92 | - [x] To adjust perceived brightness according to human vision
93 | - [ ] To enhance color saturation
94 | - [ ] To increase contrast
95 | - [ ] To make colors more vivid
96 |
97 | 15. **Which of the following Python libraries is commonly used for color manipulation?**
98 | - [ ] TensorFlow
99 | - [ ] Pandas
100 | - [x] OpenCV
101 | - [ ] NumPy
102 |
103 | 16. **Which function in OpenCV is used to convert an image from BGR to HSV?**
104 | - [ ] `cv2.convertColor(img, cv2.COLOR_RGB2HSV)`
105 | - [x] `cv2.cvtColor(img, cv2.COLOR_BGR2HSV)`
106 | - [ ] `cv2.changeColor(img, cv2.COLOR_BGR2HSV)`
107 | - [ ] `cv2.imageTransform(img, cv2.COLOR_BGR2HSV)`
108 |
109 | 17. **Which color model is often used in photography for a wider gamut than sRGB?**
110 | - [ ] HSI
111 | - [x] Adobe RGB
112 | - [ ] YIQ
113 | - [ ] CMYK
114 |
115 | 18. **In a 24-bit RGB image, how many bits are used to store each pixel?**
116 | - [ ] 8 bits
117 | - [ ] 16 bits
118 | - [x] 24 bits
119 | - [ ] 32 bits
120 |
121 | 19. **What is the difference between subtractive and additive color mixing?**
122 | - [ ] Subtractive mixing starts with black, and additive mixing starts with white
123 | - [ ] Additive mixing is used in printing, and subtractive mixing is used in screens
124 | - [x] Additive mixing adds light, while subtractive mixing removes wavelengths
125 | - [ ] There is no difference
126 |
127 | 20. **Which color model represents colors as cylindrical coordinates instead of a cube?**
128 | - [ ] RGB
129 | - [ ] CMYK
130 | - [ ] YIQ
131 | - [x] HSV
132 |
133 | ---
134 |
135 | ## **Hard Level (10 Questions)**
136 |
137 | 21. **Which of the following is NOT a standard primary color in any color model?**
138 | - [ ] Red
139 | - [ ] Green
140 | - [ ] Blue
141 | - [x] Magenta
142 |
143 | 22. **What is the purpose of the `cv2.COLOR_BGR2YCrCb` conversion in OpenCV?**
144 | - [ ] To enhance image resolution
145 | - [x] To convert an image for YCrCb color space processing
146 | - [ ] To convert the image for printing
147 | - [ ] To apply a black-and-white filter
148 |
149 | 23. **Which color space is most commonly used in video compression?**
150 | - [ ] RGB
151 | - [x] YUV
152 | - [ ] CMYK
153 | - [ ] HSV
154 |
155 | 24. **What does the ‘L’ in HSL stand for, and how does it differ from ‘V’ in HSV?**
156 | - [ ] Luminance, which is brightness; V is saturation
157 | - [ ] Lightness, which is average intensity; V is peak intensity
158 | - [x] Lightness, which is a symmetric scale; V represents max RGB component
159 | - [ ] Luminance, which is contrast; V is a color enhancer
160 |
161 | 25. **Which Python library provides the `ImageDraw` module for creating color gradients?**
162 | - [ ] OpenCV
163 | - [x] PIL (Pillow)
164 | - [ ] Matplotlib
165 | - [ ] NumPy
166 |
167 | 26. **Which of the following color models is device-independent?**
168 | - [ ] RGB
169 | - [ ] CMYK
170 | - [x] CIE XYZ
171 | - [ ] HSV
172 |
173 | 27. **Which mathematical operation best describes gamma correction?**
174 | - [ ] Linear transformation
175 | - [ ] Logarithmic transformation
176 | - [ ] Exponential transformation
177 | - [x] Power-law transformation
178 |
179 | 28. **Which type of color contrast is primarily responsible for the illusion that two identical colors appear different based on their surroundings?**
180 | - [x] Simultaneous contrast
181 | - [ ] Brightness contrast
182 | - [ ] Saturation contrast
183 | - [ ] Hue contrast
184 |
185 | 29. **What is the role of chromatic adaptation in color perception?**
186 | - [ ] Enhances visual acuity
187 | - [ ] Reduces eye strain
188 | - [x] Adjusts perceived color based on light source changes
189 | - [ ] Increases saturation
190 |
191 | 30. **Which of the following color spaces provides the best perceptual uniformity?**
192 | - [ ] RGB
193 | - [ ] CMYK
194 | - [x] LAB
195 | - [ ] YUV
196 |
197 |
--------------------------------------------------------------------------------
/02/chapter-02-color theory.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helghareeb/GFX/a301172d3d838aa2eeff1bde00741054b87aaff7/02/chapter-02-color theory.pdf
--------------------------------------------------------------------------------
/02/extra/Ch-02-Color models and color spaces.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helghareeb/GFX/a301172d3d838aa2eeff1bde00741054b87aaff7/02/extra/Ch-02-Color models and color spaces.docx
--------------------------------------------------------------------------------
/02/extra/chapter-03-color theory.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helghareeb/GFX/a301172d3d838aa2eeff1bde00741054b87aaff7/02/extra/chapter-03-color theory.pptx
--------------------------------------------------------------------------------
/03/03.md:
--------------------------------------------------------------------------------
1 | # بسم الله الرحمن الرحيم
2 | # الحمد لله وحده، والصلاة والسلام على من لا نبي بعده ﷺ
3 |
4 | # Chapter 3: Graphics Primitives and Scan Conversion
5 |
6 | ## **Introduction** 🎨📊✨
7 | Graphics primitives serve as the foundational elements for rendering digital images, encompassing **points, lines, circles, polygons, and curves**. To effectively display these primitives on a raster-based display, they must be transformed from their mathematical representations into a **discrete pixel grid**, a process known as **scan conversion**.
8 |
9 | ## **1. Scan Conversion** 🎯📏🔍
10 | ### **Definition**
11 | Scan conversion involves mapping continuous geometric objects onto a pixel-based display. Since screens use a **discrete coordinate system**, smooth curves and lines must be approximated.
12 |
13 | - **Rasterization**: The process of selecting appropriate pixels to represent a shape.
14 | - **Aliasing**: The visual distortion caused by pixel approximation, often appearing as "stair-stepping" along diagonal lines.
15 | - **Frame Buffer**: A dedicated memory space that stores pixel data, determining what is rendered on the screen.
16 |
17 | ## **2. Points and Pixels** 🖌️🖥️🔢
18 | A **pixel** (short for "picture element") is the smallest unit of a digital image. Each pixel is addressed using **(x, y) coordinates**, with the top-left corner typically being (0,0).
19 |
20 | ### **Point Scan Conversion**
21 | When a floating-point coordinate **(x, y)** is given, the nearest pixel is computed using:
22 |
23 | \[ x' = \lfloor x + 0.5 \rfloor, \quad y' = \lfloor y + 0.5 \rfloor \]
24 |
25 | **Example:** Mapping (2.7, 3.2) to a pixel results in **(3,3)**.
26 |
27 | ## **3. Line Scan Conversion** 📏📐📊
28 | A **line** in 2D space is mathematically represented as:
29 | \[ y = mx + b \]
30 | where **m** denotes the slope and **b** is the y-intercept.
31 |
32 | ### **3.1 Direct Line Equation Method**
33 | For each **x** increment, the corresponding **y** is computed:
34 | \[ y = mx + b \]
35 |
36 | **Limitations**:
37 | - Floating-point calculations increase computational cost.
38 | - Pixel rounding introduces aliasing effects.
39 |
40 | ### **3.2 Digital Differential Analyzer (DDA) Algorithm**
41 | An incremental approach that eliminates floating-point multiplication:
42 | - **For |m| ≤ 1**: Increment **x** and compute **y**.
43 | - **For |m| > 1**: Increment **y** and compute **x**.
44 |
45 | #### **Python Implementation:**
46 | ```python
47 | import matplotlib.pyplot as plt
48 |
49 | def dda_line(x1, y1, x2, y2):
50 | dx, dy = x2 - x1, y2 - y1
51 | steps = max(abs(dx), abs(dy))
52 | x_inc, y_inc = dx / steps, dy / steps
53 | x, y = x1, y1
54 | points = [(round(x), round(y)) for _ in range(int(steps) + 1)]
55 | return points
56 |
57 | # Example Usage
58 | plt.scatter(*zip(*dda_line(2, 3, 10, 8)))
59 | plt.show()
60 | ```
61 |
62 | ### **3.3 Bresenham’s Line Algorithm**
63 | A more efficient integer-based method compared to DDA.
64 |
65 | #### **Python Implementation:**
66 | ```python
67 | def bresenham_line(x1, y1, x2, y2):
68 | points = []
69 | dx, dy = abs(x2 - x1), abs(y2 - y1)
70 | sx, sy = (1 if x1 < x2 else -1), (1 if y1 < y2 else -1)
71 | err = dx - dy
72 | while (x1, y1) != (x2, y2):
73 | points.append((x1, y1))
74 | e2 = 2 * err
75 | if e2 > -dy:
76 | err -= dy
77 | x1 += sx
78 | if e2 < dx:
79 | err += dx
80 | y1 += sy
81 | points.append((x2, y2))
82 | return points
83 |
84 | # Example Usage
85 | plt.scatter(*zip(*bresenham_line(2, 3, 10, 8)))
86 | plt.show()
87 | ```
88 |
89 | ## **4. Circle Scan Conversion** 🔵📏🔄
90 | ### **Midpoint Circle Algorithm**
91 | A rasterization method using integer calculations.
92 |
93 | #### **Python Implementation:**
94 | ```python
95 | def midpoint_circle(cx, cy, r):
96 | points = []
97 | x, y, p = r, 0, 1 - r
98 | while x >= y:
99 | for dx, dy in [(x, y), (y, x), (-y, x), (-x, y), (-x, -y), (-y, -x), (y, -x), (x, -y)]:
100 | points.append((cx + dx, cy + dy))
101 | y += 1
102 | p = p + 2 * y + 1 if p <= 0 else p + 2 * (y - x) + 1; x -= 1 if p > 0 else x
103 | return points
104 |
105 | # Example Usage
106 | plt.scatter(*zip(*midpoint_circle(10, 10, 8)))
107 | plt.show()
108 | ```
109 |
110 | ## **5. Polygon Scan Conversion** 🔳📐📊
111 | Polygons are closed shapes defined by a sequence of line segments.
112 |
113 | ### **Scan-Line Algorithm for Polygon Filling**
114 | - Detects active edges.
115 | - Iterates row by row, filling pixels inside the polygon.
116 |
117 | ## **6. Curves and Splines** 📈🎭🔗
118 | Curves are integral to digital modeling and animation.
119 |
120 | - **Bézier Curves**: Defined using control points.
121 | - **B-Splines**: Provide localized curve control.
122 |
123 | #### **Python Example: Bézier Curve**
124 | ```python
125 | import numpy as np
126 |
127 | def bezier_curve(p0, p1, p2, p3, t_values):
128 | return [(pow(1-t, 3) * p0[0] + 3 * pow(1-t, 2) * t * p1[0] + 3 * (1-t) * pow(t, 2) * p2[0] + pow(t, 3) * p3[0],
129 | pow(1-t, 3) * p0[1] + 3 * pow(1-t, 2) * t * p1[1] + 3 * (1-t) * pow(t, 2) * p2[1] + pow(t, 3) * p3[1])
130 | for t in t_values]
131 |
132 | # Example Usage
133 | t_values = np.linspace(0, 1, 100)
134 | plt.plot(*zip(*bezier_curve((1, 1), (2, 3), (4, 3), (5, 1), t_values)))
135 | plt.show()
136 | ```
137 |
138 | ## **Exercises** 📚📝🤓
139 | 1. Implement Bresenham’s algorithm for circles.
140 | 2. Compare the computational efficiency of DDA and Bresenham’s algorithms.
141 | 3. Modify the polygon filling algorithm to handle concave polygons.
142 |
143 | ## **Research Topics** 🔬📖📊
144 | - **Techniques for anti-aliasing in raster graphics.**
145 | - **GPU-based acceleration for scan conversion.**
146 | - **Applications of Bézier curves in CAD and animation.**
147 |
148 |
--------------------------------------------------------------------------------
/03/CGChapterSix.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helghareeb/GFX/a301172d3d838aa2eeff1bde00741054b87aaff7/03/CGChapterSix.pptx
--------------------------------------------------------------------------------
/03/Qs.md:
--------------------------------------------------------------------------------
1 | # بسم الله الرحمن الرحيم
2 | # الحمد لله وحده، والصلاة والسلام على من لا نبي بعده ﷺ
3 |
4 | # **Multiple-Choice Questions: Scan Conversion and Graphics Primitives**
5 |
6 | ## **Easy Questions** 🟢
7 |
8 | ### **1. What is the process of converting geometric objects into pixel representations called?**
9 | - [ ] A) Aliasing
10 | - [ ] B) Rasterization
11 | - [ ] C) Frame buffering
12 | - [ ] D) Vectorization
13 |
14 | ### **2. Which of the following is the smallest addressable unit on a digital display?**
15 | - [ ] A) Bit
16 | - [ ] B) Byte
17 | - [ ] C) Pixel
18 | - [ ] D) Frame
19 |
20 | ### **3. In Bresenham’s Line Algorithm, what type of arithmetic is used?**
21 | - [ ] A) Floating-point arithmetic
22 | - [ ] B) Trigonometric functions
23 | - [ ] C) Integer arithmetic
24 | - [ ] D) Matrix operations
25 |
26 | ### **4. What is the advantage of Bresenham’s algorithm over DDA?**
27 | - [ ] A) Uses floating-point arithmetic
28 | - [ ] B) More accurate but slower
29 | - [ ] C) Uses only integer operations, making it faster
30 | - [ ] D) Requires more memory
31 |
32 | ### **5. Which of the following algorithms is used for circle scan conversion?**
33 | - [ ] A) DDA Algorithm
34 | - [ ] B) Midpoint Circle Algorithm
35 | - [ ] C) Bresenham’s Line Algorithm
36 | - [ ] D) Clipping Algorithm
37 |
38 | ### **6. What is the equation of a line in two-dimensional space?**
39 | - [ ] A) \( y = ax^2 + bx + c \)
40 | - [ ] B) \( y = mx + b \)
41 | - [ ] C) \( x^2 + y^2 = r^2 \)
42 | - [ ] D) \( x = my + b \)
43 |
44 | ### **7. Which term describes the jagged appearance of a rasterized line?**
45 | - [ ] A) Rasterization
46 | - [ ] B) Aliasing
47 | - [ ] C) Quantization
48 | - [ ] D) Dithering
49 |
50 | ### **8. The Midpoint Circle Algorithm is based on which mathematical principle?**
51 | - [ ] A) Trigonometry
52 | - [ ] B) Calculus
53 | - [ ] C) Decision parameters
54 | - [ ] D) Matrix multiplication
55 |
56 | ---
57 |
58 | ## **Medium Questions** 🟡
59 |
60 | ### **9. How does the Digital Differential Analyzer (DDA) algorithm determine the next pixel?**
61 | - [ ] A) Using slope-intercept form
62 | - [ ] B) By rounding the midpoint between two pixels
63 | - [ ] C) By calculating incremental steps
64 | - [ ] D) By comparing absolute differences in x and y coordinates
65 |
66 | ### **10. In raster graphics, what is the primary function of the frame buffer?**
67 | - [ ] A) Store the pixel intensity values
68 | - [ ] B) Control the refresh rate of the screen
69 | - [ ] C) Process 3D transformations
70 | - [ ] D) Store only the black-and-white pixel values
71 |
72 | ### **11. Which of the following statements is true for the Midpoint Circle Algorithm?**
73 | - [ ] A) It uses trigonometric functions to determine pixel positions
74 | - [ ] B) It is slower than the Polynomial Circle Algorithm
75 | - [ ] C) It uses decision parameters for efficiency
76 | - [ ] D) It does not use integer arithmetic
77 |
78 | ### **12. How many octants does the Midpoint Circle Algorithm take advantage of to optimize calculations?**
79 | - [ ] A) 2
80 | - [ ] B) 4
81 | - [ ] C) 6
82 | - [ ] D) 8
83 |
84 | ### **13. Which of the following best describes anti-aliasing in raster graphics?**
85 | - [ ] A) Reducing pixel intensity to increase performance
86 | - [ ] B) A method to smooth edges of primitives by adjusting pixel intensities
87 | - [ ] C) Increasing the number of pixels in a frame buffer
88 | - [ ] D) A compression technique used in image processing
89 |
90 | ### **14. What is a key disadvantage of the DDA algorithm?**
91 | - [ ] A) It cannot be implemented using integer operations
92 | - [ ] B) It is significantly slower than Bresenham’s Algorithm
93 | - [ ] C) It does not work for steep slopes
94 | - [ ] D) It only works with vertical lines
95 |
96 | ### **15. What happens if the decision parameter in the Midpoint Circle Algorithm is negative?**
97 | - [ ] A) The pixel remains unchanged
98 | - [ ] B) The next pixel is chosen in the same horizontal row
99 | - [ ] C) The next pixel is chosen from a lower row
100 | - [ ] D) The next pixel is chosen from the upper row
101 |
102 | ---
103 |
104 | ## **Hard Questions** 🔴
105 |
106 | ### **16. Which of the following algorithms uses the concept of error accumulation?**
107 | - [ ] A) DDA Algorithm
108 | - [ ] B) Midpoint Circle Algorithm
109 | - [ ] C) Bresenham’s Line Algorithm
110 | - [ ] D) Both B and C
111 |
112 | ### **17. What modification must be made to Bresenham’s Line Algorithm for it to handle all quadrants?**
113 | - [ ] A) Change the slope calculation
114 | - [ ] B) Adjust step increments based on sign values of dx and dy
115 | - [ ] C) Use floating-point calculations
116 | - [ ] D) Introduce additional memory buffers
117 |
118 | ### **18. Which of the following is a key challenge in scan conversion of a polygon?**
119 | - [ ] A) Identifying active edges
120 | - [ ] B) Calculating midpoint coordinates
121 | - [ ] C) Finding pixel intensity values
122 | - [ ] D) Converting floating-point values to integers
123 |
124 | ### **19. How is scan conversion different for concave and convex polygons?**
125 | - [ ] A) Concave polygons may require special handling to avoid incorrect filling
126 | - [ ] B) Convex polygons require more processing time
127 | - [ ] C) Concave polygons can only be rendered using midpoint algorithms
128 | - [ ] D) There is no difference in scan conversion
129 |
130 | ### **20. What is the primary purpose of the scan-line algorithm?**
131 | - [ ] A) To fill the interior of a polygon efficiently
132 | - [ ] B) To detect overlapping pixels
133 | - [ ] C) To compute 3D projections
134 | - [ ] D) To remove hidden surfaces
135 |
136 | # **Answers**
137 |
138 | **Easy Questions:**
139 | 1. **B**
140 | 2. **C**
141 | 3. **C**
142 | 4. **C**
143 | 5. **B**
144 | 6. **B**
145 | 7. **B**
146 | 8. **C**
147 |
148 | **Medium Questions:**
149 | 9. **C**
150 | 10. **A**
151 | 11. **C**
152 | 12. **D**
153 | 13. **B**
154 | 14. **A**
155 | 15. **D**
156 |
157 | **Hard Questions:**
158 | 16. **D**
159 | 17. **B**
160 | 18. **A**
161 | 19. **A**
162 | 20. **A**
163 |
164 | 🚀
--------------------------------------------------------------------------------
/03/extra/Ch-03-Graphics primitives.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helghareeb/GFX/a301172d3d838aa2eeff1bde00741054b87aaff7/03/extra/Ch-03-Graphics primitives.docx
--------------------------------------------------------------------------------
/03/extra/chapter-03-Scan conversion.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/helghareeb/GFX/a301172d3d838aa2eeff1bde00741054b87aaff7/03/extra/chapter-03-Scan conversion.pptx
--------------------------------------------------------------------------------
/04/04.md:
--------------------------------------------------------------------------------
1 | # بسم الله الرحمن الرحيم
2 | # الحمد لله وحده، والصلاة والسلام على من لا نبي بعده ﷺ
3 |
4 | ### Chapter 4: HTML5 Canvas and SVG 🎨🖥️✨
5 |
6 | #### Introduction 🚀💡📊
7 | With the advent of HTML5, developers gained access to new tools for creating interactive and visually rich web applications. Two critical technologies, **Canvas** and **SVG**, offer distinct approaches to rendering graphics in web environments. Understanding their functionalities, advantages, and use cases is essential for any web developer working on graphical content.
8 |
9 | ---
10 |
11 | ### HTML5 Canvas 🖌️📜🕹️
12 | The **Canvas API** in HTML5 enables the real-time rendering of 2D graphics using JavaScript. The `