@@ -20,6 +20,7 @@ int main() {
2020```
2121
2222Compile and run:
23+
2324```bash
2425g++ -std=c++20 -Iinclude -o draw my_draw.cpp
2526./draw
@@ -29,24 +30,24 @@ g++ -std=c++20 -Iinclude -o draw my_draw.cpp
2930
3031## 🎮 Keyboard Controls
3132
32- | Key | Action |
33- | -----| --------|
34- | ` p ` | ** Pen tool** - Freehand drawing |
35- | ` l ` | ** Line tool** - Draw straight lines |
36- | ` c ` | ** Circle tool** - Draw circles |
37- | ` x ` | ** Rectangle tool** - Draw rectangles |
38- | ` f ` | ** Fill tool** - Flood fill an area |
39- | ` e ` | ** Eraser** - Erase to background |
40- | ` r ` | Select ** R** ed channel |
41- | ` g ` | Select ** G** reen channel |
42- | ` b ` | Select ** B** lue channel |
43- | ` a ` | Select ** A** lpha channel |
44- | ` 0-9 ` | Set channel value (0-255) |
45- | ` + ` / ` - ` | Increase/decrease brush size |
46- | ` u ` | ** Undo** last action |
47- | ` y ` | ** Redo** undone action |
48- | ` s ` | ** Save** to file |
49- | ` q ` | ** Quit** |
33+ | Key | Action |
34+ | --------- | ------------------------------------ |
35+ | ` p ` | ** Pen tool** - Freehand drawing |
36+ | ` l ` | ** Line tool** - Draw straight lines |
37+ | ` c ` | ** Circle tool** - Draw circles |
38+ | ` x ` | ** Rectangle tool** - Draw rectangles |
39+ | ` f ` | ** Fill tool** - Flood fill an area |
40+ | ` e ` | ** Eraser** - Erase to background |
41+ | ` r ` | Select ** R** ed channel |
42+ | ` g ` | Select ** G** reen channel |
43+ | ` b ` | Select ** B** lue channel |
44+ | ` a ` | Select ** A** lpha channel |
45+ | ` 0-9 ` | Set channel value (0-255) |
46+ | ` + ` / ` - ` | Increase/decrease brush size |
47+ | ` u ` | ** Undo** last action |
48+ | ` y ` | ** Redo** undone action |
49+ | ` s ` | ** Save** to file |
50+ | ` q ` | ** Quit** |
5051
5152---
5253
@@ -85,11 +86,13 @@ struct RGBA
8586```
8687
8788** What this does:**
89+
8890- Stores red, green, blue, and alpha (transparency) values
8991- Default color is opaque white (255, 255, 255, 255)
9092- The ` blend_over() ` method combines two colors using alpha compositing
9193
9294** Visual example of alpha blending:**
95+
9396```
9497Semi-transparent red (255, 0, 0, 128) over blue (0, 0, 255, 255)
9598Result: Purple-ish color where both contribute
@@ -113,14 +116,14 @@ enum class Tool
113116
114117Each tool behaves differently when you click and drag:
115118
116- | Tool | Click | Drag | Release |
117- | ------| -------| ------| ---------|
118- | Pen | Start drawing | Draw along path | Stop |
119- | Line | Set start point | Preview line | Draw final line |
120- | Circle | Set center | Preview radius | Draw final circle |
121- | Rectangle | Set corner | Preview size | Draw final rectangle |
122- | Fill | Fill area | (no effect) | (no effect) |
123- | Eraser | Start erasing | Erase along path | Stop |
119+ | Tool | Click | Drag | Release |
120+ | --------- | --------------- | ---------------- | -------------------- |
121+ | Pen | Start drawing | Draw along path | Stop |
122+ | Line | Set start point | Preview line | Draw final line |
123+ | Circle | Set center | Preview radius | Draw final circle |
124+ | Rectangle | Set corner | Preview size | Draw final rectangle |
125+ | Fill | Fill area | (no effect) | (no effect) |
126+ | Eraser | Start erasing | Erase along path | Stop |
124127
125128---
126129
@@ -149,6 +152,7 @@ ESC [ < Cb ; Cx ; Cy m (for release)
149152```
150153
151154Where:
155+
152156- ` Cb ` = button code (with modifier bits)
153157- ` Cx ` , ` Cy ` = 1-based cell coordinates
154158
@@ -164,14 +168,14 @@ private:
164168 size_t _ char_height; // Height in terminal characters
165169 size_t _ pixel_width; // Actual pixel width
166170 size_t _ pixel_height; // Actual pixel height
167-
171+
168172 std::vector<std::vector<RGBA>> _pixels; // The drawing buffer
169-
173+
170174 Tool _current_tool;
171175 RGBA _foreground; // Current drawing color
172176 RGBA _background; // Background/eraser color
173177 uint8_t _brush_size; // Brush radius
174-
178+
175179 std::stack<CanvasState> _undo_stack; // For undo
176180 std::stack<CanvasState> _redo_stack; // For redo
177181```
@@ -209,13 +213,13 @@ void enable_raw_mode()
209213
210214** What each flag does:**
211215
212- | Flag | Effect when disabled |
213- | ------| ---------------------|
216+ | Flag | Effect when disabled |
217+ | -------- | ------------------------------------------------------ |
214218| ` ICANON ` | Don't wait for Enter - read each keystroke immediately |
215- | ` ECHO ` | Don't echo typed characters |
216- | ` ISIG ` | Don't generate signals on Ctrl+C/Z |
217- | ` IXON ` | Don't interpret Ctrl+S/Q as flow control |
218- | ` ICRNL ` | Don't convert carriage return to newline |
219+ | ` ECHO ` | Don't echo typed characters |
220+ | ` ISIG ` | Don't generate signals on Ctrl+C/Z |
221+ | ` IXON ` | Don't interpret Ctrl+S/Q as flow control |
222+ | ` ICRNL ` | Don't convert carriage return to newline |
219223
220224---
221225
@@ -258,9 +262,9 @@ void draw_line(int x0, int y0, int x1, int y1, const RGBA &color)
258262
259263 while (true) {
260264 draw_brush(x0, y0, color); // Draw at current point
261-
265+
262266 if (x0 == x1 && y0 == y1) break;
263-
267+
264268 int e2 = 2 * err;
265269 if (e2 > -dy) { err -= dy; x0 += sx; }
266270 if (e2 < dx) { err += dx; y0 += sy; }
@@ -382,7 +386,7 @@ void save_state_for_undo()
382386{
383387 _undo_stack.push(CanvasState(_pixels));
384388 _redo_stack = std::stack<CanvasState>(); // Clear redo
385-
389+
386390 // Limit undo history
387391 while (_undo_stack.size() > MAX_UNDO) {
388392 // Remove oldest...
@@ -424,13 +428,14 @@ void save(const std::string &filename)
424428 rgb_data.push_back(pixel.b);
425429 }
426430 }
427-
431+
428432 // Save using pythonicMedia's RLE compression
429433 pythonic::media::save_pi(filename, rgb_data, _pixel_width, _pixel_height);
430434}
431435```
432436
433437The `.pi` format uses:
438+
434439- Run-Length Encoding (RLE) compression
435440- XOR encryption for obfuscation
436441- Header with original dimensions
@@ -459,6 +464,7 @@ canvas.run();
459464## 🔧 Terminal Compatibility
460465
461466Works on:
467+
462468- ✅ Linux terminals (gnome-terminal, konsole, xterm)
463469- ✅ macOS Terminal, iTerm2
464470- ✅ Windows Terminal
@@ -472,4 +478,3 @@ Works on:
472478- [pythonicDraw.hpp Tutorial](pythonicDraw_tutorial.md) - Learn the underlying drawing primitives
473479- [pythonicMedia.hpp Tutorial](../Media/pythonicMedia_tutorial.md) - Understand the file format
474480- [Plot Tutorial](../Plot/plot.md) - Create data visualizations
475-
0 commit comments