Skip to content

AshisChetia/Graphics_visualizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

React Vite Express MySQL Node.js

🎨 Graphics Visualizer

An interactive computer graphics algorithm visualization platform for students and educators.

Visualize DDA, Bresenham, circle drawing, polygon filling, and line/polygon clipping β€” pixel by pixel on a 60Γ—60 interactive grid.

Features β€’ Algorithms β€’ Tech Stack β€’ Structure β€’ Setup β€’ Usage


✨ Features

πŸ–ΌοΈ Interactive 60Γ—60 Pixel Grid Canvas

  • Precise pixel-level rendering with coordinate tooltips
  • Zoom, pan, and color-coded visual legends
  • Real-time canvas updates as algorithms execute

⏯️ Step-by-Step Playback

  • Play / Pause / Step controls for algorithm animation
  • Adjustable speed slider for playback rate
  • Decision-point highlighting at each algorithmic step

πŸ§‘β€πŸ’» Monaco Code Editor

  • Full-featured code editor powered by Monaco (same engine as VS Code)
  • Write custom rendering code using the fillPixel(x, y, color) API
  • Syntax highlighting, auto-completion, and dark theme

πŸ‘₯ Role-Based Access

Role Capabilities
Student Access shared lessons, step through visualizations, run code in Monaco Editor
Educator Create algorithm presets or code lessons, preview output, share via link, track views

πŸ”— Lesson Sharing System

  • Educators create lessons (algorithm presets or custom code)
  • Each lesson generates a unique shareable link (/lesson/:uuid)
  • Students open the link and see the algorithm or code visualized instantly
  • View count tracking for each lesson

πŸ” Authentication & Security

  • JWT-based authentication with secure password hashing (bcrypt)
  • Protected routes with role-based access control
  • Persistent login via localStorage

πŸ“ Supported Algorithms

Category Algorithm Description
🟣 Line Drawing DDA Line Algorithm Digital Differential Analyzer for line rasterization
Bresenham's Line Algorithm Integer-only efficient line drawing
πŸ”΅ Circle Midpoint Circle Algorithm Efficient circle rasterization using midpoint decisions
🟑 Polygon Fill Scanline Fill Edge-table-based polygon fill using horizontal scanlines
Flood Fill (BFS) Breadth-first region fill from a seed point
Boundary Fill Recursive boundary-constrained fill algorithm
🟒 Clipping Cohen-Sutherland Region-code-based line clipping
Liang-Barsky Parametric line clipping algorithm
Sutherland-Hodgman Polygon clipping against a rectangular window

πŸ› οΈ Tech Stack

Frontend

Technology Purpose
React 19 UI component framework
Vite 7 Fast dev server & build tool
React Router 7 Client-side routing
Axios HTTP client for API calls
Monaco Editor In-browser code editor
Zustand Lightweight state management
Tailwind CSS 4 Utility-first CSS framework

Backend

Technology Purpose
Express 5 HTTP server framework
MySQL 2 Relational database driver
JSON Web Tokens Stateless authentication
bcryptjs Password hashing
UUID Unique lesson identifiers
dotenv Environment configuration
Nodemon Dev auto-restart

πŸ“ Project Structure

Graphics Visualizer/
β”œβ”€β”€ Client/                          # React frontend (Vite)
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ algorithms/              # 9 CG algorithm implementations
β”‚   β”‚   β”‚   β”œβ”€β”€ dda.js               #   DDA Line
β”‚   β”‚   β”‚   β”œβ”€β”€ bresenham.js          #   Bresenham Line
β”‚   β”‚   β”‚   β”œβ”€β”€ midpointCircle.js     #   Midpoint Circle
β”‚   β”‚   β”‚   β”œβ”€β”€ scanlineFill.js       #   Scanline Polygon Fill
β”‚   β”‚   β”‚   β”œβ”€β”€ floodFill.js          #   Flood Fill (BFS)
β”‚   β”‚   β”‚   β”œβ”€β”€ boundaryFill.js       #   Boundary Fill
β”‚   β”‚   β”‚   β”œβ”€β”€ cohenSutherland.js    #   Cohen-Sutherland Clipping
β”‚   β”‚   β”‚   β”œβ”€β”€ liangBarsky.js        #   Liang-Barsky Clipping
β”‚   β”‚   β”‚   └── sutherlandHodgman.js  #   Sutherland-Hodgman Clipping
β”‚   β”‚   β”œβ”€β”€ api/                      # API client layer
β”‚   β”‚   β”‚   β”œβ”€β”€ axiosClient.js        #   Configured Axios instance
β”‚   β”‚   β”‚   β”œβ”€β”€ authApi.js            #   Auth endpoints (signup/login)
β”‚   β”‚   β”‚   └── lessonApi.js          #   Lesson CRUD endpoints
β”‚   β”‚   β”œβ”€β”€ components/               # Reusable UI components
β”‚   β”‚   β”‚   β”œβ”€β”€ CanvasGrid.jsx        #   60Γ—60 pixel grid canvas
β”‚   β”‚   β”‚   β”œβ”€β”€ CodeEditor.jsx        #   Monaco code editor wrapper
β”‚   β”‚   β”‚   β”œβ”€β”€ ControlPanel.jsx      #   Algorithm controls & playback
β”‚   β”‚   β”‚   β”œβ”€β”€ ProtectedRoute.jsx    #   Role-based route guard
β”‚   β”‚   β”‚   └── nav/                  #   Navigation bars
β”‚   β”‚   β”œβ”€β”€ pages/                    # Page-level components
β”‚   β”‚   β”‚   β”œβ”€β”€ LandingPage.jsx       #   Public landing page
β”‚   β”‚   β”‚   β”œβ”€β”€ LoginPage.jsx         #   Login form
β”‚   β”‚   β”‚   β”œβ”€β”€ SignupPage.jsx        #   Signup form with role select
β”‚   β”‚   β”‚   β”œβ”€β”€ Home.jsx              #   Student visualizer page
β”‚   β”‚   β”‚   └── Dashboard.jsx         #   Educator lesson dashboard
β”‚   β”‚   β”œβ”€β”€ App.jsx                   # Router configuration
β”‚   β”‚   β”œβ”€β”€ main.jsx                  # App entry point
β”‚   β”‚   └── index.css                 # Global styles & design tokens
β”‚   └── package.json
β”‚
β”œβ”€β”€ Server/                          # Express backend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ config/
β”‚   β”‚   β”‚   └── db.js                 # MySQL connection pool
β”‚   β”‚   β”œβ”€β”€ controllers/
β”‚   β”‚   β”‚   β”œβ”€β”€ auth.controller.js    # Signup & login logic
β”‚   β”‚   β”‚   └── lesson.controller.js  # Lesson CRUD logic
β”‚   β”‚   └── routes/
β”‚   β”‚       β”œβ”€β”€ auth.routes.js        # /api/auth/* routes
β”‚   β”‚       └── lesson.routes.js      # /api/lessons/* routes
β”‚   β”œβ”€β”€ server.js                     # Express app entry point
β”‚   β”œβ”€β”€ .env                          # Environment variables
β”‚   └── package.json
β”‚
└── .gitignore

πŸš€ Getting Started

Prerequisites

  • Node.js β‰₯ 18
  • MySQL β‰₯ 8.0
  • npm or yarn

1. Clone the Repository

git clone https://github.com/AshisChetia/Graphics_visualizer.git
cd Graphics_visualizer

2. Set Up the Database

Open MySQL and create the database and tables:

CREATE DATABASE IF NOT EXISTS graphics_visualizer;
USE graphics_visualizer;

-- Users table
CREATE TABLE users (
    id INT AUTO_INCREMENT PRIMARY KEY,
    username VARCHAR(255) NOT NULL,
    email VARCHAR(255) NOT NULL UNIQUE,
    password VARCHAR(255) NOT NULL,
    role ENUM('student', 'educator') DEFAULT 'student',
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- Lessons table
CREATE TABLE lessons (
    id VARCHAR(36) PRIMARY KEY,
    type VARCHAR(50) NOT NULL DEFAULT 'algorithm',
    algorithm VARCHAR(100),
    params JSON,
    code TEXT,
    title VARCHAR(255),
    created_by VARCHAR(255),
    view_count INT DEFAULT 0,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

3. Configure Environment Variables

Create a .env file inside the Server/ directory:

PORT=5000
JWT_SECRET=your_jwt_secret_key_here

# Database
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=your_mysql_password
DB_NAME=graphics_visualizer

4. Install Dependencies

# Install server dependencies
cd Server
npm install

# Install client dependencies
cd ../Client
npm install

5. Run the Application

Open two terminals:

# Terminal 1 β€” Start the backend
cd Server
npm run dev
# Terminal 2 β€” Start the frontend
cd Client
npm run dev

The app will be running at:


πŸ’‘ Usage

As a Student

  1. Sign up with the "Student" role
  2. Navigate to the Visualizer page
  3. Select an algorithm, configure parameters, and click Generate
  4. Use Play, Pause, Step, and Reset controls to animate
  5. Switch to the Code Editor tab to write custom pixel code
  6. Open shared lesson links from your educator to explore pre-made demos

As an Educator

  1. Sign up with the "Educator" role
  2. Navigate to the Dashboard
  3. Create a new lesson:
    • Choose Algorithm Preset β†’ select algorithm + parameters
    • Or choose Code Lesson β†’ write custom fillPixel() code
  4. Click Preview to see the output before sharing
  5. Click Create & Get Shareable Link
  6. Copy the generated link and share it with students

πŸ”Œ API Endpoints

Authentication

Method Endpoint Description
POST /api/auth/signup Register a new user
POST /api/auth/login Authenticate and get JWT token

Lessons

Method Endpoint Description
GET /api/lessons Get all lessons
POST /api/lessons Create a new lesson
GET /api/lessons/:uuid Get a specific lesson by UUID
DELETE /api/lessons/:uuid Delete a lesson

Health Check

Method Endpoint Description
GET /api/health Check database connectivity

πŸ“œ License

This project is licensed under the ISC License.


Made with ❀️ by Ashis Chetia

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors