Documentation Index
Fetch the complete documentation index at: https://mintlify.com/ayushpai/AI-Math-Notes/llms.txt
Use this file to discover all available pages before exploring further.
Overview
AI Math Notes is built around a singleDrawingApp class that manages the Tkinter-based canvas interface, PIL image processing, and OpenAI API integration. The architecture follows a monolithic design pattern with event-driven user interactions.
DrawingApp Class
TheDrawingApp class (main.py:8) is the core component that handles all application functionality.
Initialization
The Tkinter root window instance
- A 1200x800 black canvas for drawing
- A PIL Image instance for image processing
- An ImageDraw object for rendering
- Event bindings for mouse and keyboard interactions
- Action history for undo functionality
- OpenAI client for API calls
Canvas System
The application uses a dual-rendering approach:- Tkinter Canvas (
main.py:16) - Provides real-time visual feedback - PIL Image (
main.py:19-20) - Creates the actual image sent to the API
Event Bindings
The application binds several events (main.py:22-26):
Core Methods
Drawing Methods
start_draw()
Mouse click event containing x, y coordinates
main.py:45-47).
paint()
Mouse motion event with current cursor position
main.py:49-55).
reset()
Mouse release event
main.py:57-60).
Action Management
undo()
Reverts the last drawing action by removing lines from both canvas and image (main.py:68-73).
redraw_all()
Recreates the entire canvas and PIL image from the action history (main.py:78-85).
clear()
Clears the entire canvas and resets all state (main.py:62-66).
PIL Integration
The application uses Pillow (PIL) for image processing:- Image Creation: Creates a blank RGB image matching canvas dimensions
- Drawing: Uses
ImageDrawto render white lines (width=5) on black background - Font Rendering: Loads default font at size 100 for displaying answers
- Export: Converts images to PNG format for base64 encoding
Image Flow
- User draws on Tkinter canvas
- Each stroke is simultaneously drawn on PIL Image
- Image is encoded to base64 PNG (
main.py:88-91) - Base64 string is sent to OpenAI API
- Answer is rendered back onto both canvas and image
Answer Display
Thedraw_answer() method (main.py:119-138) positions the calculated result:
Dependencies
Fromrequirements.txt:
- pillow==10.2.0: Image processing and rendering
- openai==1.14.2: GPT-4o API client
- tkinter: GUI framework (built into Python)