Skip to content

sahalpk007/InertiaPhysicsLab

Repository files navigation

🚀 Inertia Physics Lab (Prokon v1)

An interactive web-based physics simulation that teaches Newton's First Law of Motion through hands-on experimentation. Students can launch objects in different environments and observe how inertia affects motion in real-time.

Physics Lab Demo React TypeScript Vite

📋 Table of Contents

🎯 Overview

The Inertia Physics Lab is an educational web application designed to make physics concepts accessible and engaging through interactive visualization. Students can experiment with object motion across four different environments, each demonstrating different aspects of Newton's First Law of Motion.

Key Learning Outcomes

  • Understanding of inertia and Newton's First Law
  • Effect of friction on moving objects
  • Impact of gravity on object trajectories
  • Relationship between force, motion, and external influences

✨ Features

🎮 Interactive Gameplay

  • Click-and-drag launching system - Intuitive object launching mechanism
  • Real-time physics simulation - Accurate physics calculations running at 60 FPS
  • Visual feedback system - Motion trails and velocity vectors for clear visualization
  • Four progressive levels - Each with unique physics parameters

📊 Educational Tools

  • Motion trails - Colored paths showing object movement history
  • Velocity vectors - Yellow arrows indicating speed and direction
  • Physics parameter controls - Adjustable friction and gravity settings
  • Performance metrics - Energy scores and launch statistics

🎨 User Experience

  • Responsive design - Works on desktop, tablet, and mobile devices
  • Space-themed interface - Engaging cosmic visual design
  • Smooth animations - Optimized rendering for fluid motion
  • Contextual instructions - Built-in tutorial and guidance system

🎓 Educational Objectives

Primary Learning Goals

  1. Newton's First Law Mastery - "Objects in motion stay in motion unless acted upon by an external force"
  2. Force and Motion Relationships - Understanding how external forces affect object behavior
  3. Friction Understanding - Observing how resistance forces slow down objects
  4. Gravity Effects - Seeing how gravitational force changes motion paths

Target Audience

  • Middle School Students (Ages 11-14) - Introduction to physics concepts
  • High School Students (Ages 14-18) - Reinforcement of mechanics principles
  • Physics Teachers - Interactive demonstration tool for classroom use
  • Self-learners - Anyone interested in understanding basic physics

🛠 Technology Stack

Frontend Framework

  • React 18.3.1 - Component-based UI framework
  • TypeScript 5.5.3 - Type-safe JavaScript for better development experience
  • Vite 5.4.2 - Fast build tool and development server

Styling & UI

  • Tailwind CSS 3.4.1 - Utility-first CSS framework for rapid styling
  • Lucide React 0.344.0 - Beautiful icon library for UI elements

Development Tools

  • ESLint - Code linting and quality enforcement
  • PostCSS - CSS processing and optimization
  • Autoprefixer - Automatic vendor prefix handling

Browser Technologies

  • HTML5 Canvas - High-performance 2D graphics rendering
  • RequestAnimationFrame - Smooth 60 FPS animations
  • ES6+ Features - Modern JavaScript for clean, efficient code

🚀 Installation

Prerequisites

  • Node.js (version 18 or higher)
  • npm or yarn package manager
  • Modern web browser with Canvas support

Quick Start

# Clone the repository
git clone https://github.com/sahalpk007/InertiaPhysicsLab.git

# Navigate to project directory
cd InertiaPhysicsLab

# Install dependencies
npm install

# Start development server
npm run dev

# Open browser to http://localhost:5173

Production Build

# Create optimized production build
npm run build

# Preview production build locally
npm run preview

📖 Usage

Getting Started

  1. Launch the application in your web browser
  2. Read the instructions - Click the info button for detailed gameplay guide
  3. Start with Level 1 - "Frictionless Space" to understand basic inertia
  4. Launch objects - Click and drag on the canvas to launch colored objects
  5. Observe physics - Watch motion trails and velocity vectors
  6. Progress through levels - Each level introduces new physics concepts

Level Progression

Level 1: Frictionless Space

  • Environment: No friction, no gravity
  • Learning Goal: Objects continue moving indefinitely
  • Key Observation: Perfect demonstration of inertia

Level 2: Air Resistance

  • Environment: Friction enabled, no gravity
  • Learning Goal: External forces slow down objects
  • Key Observation: Gradual deceleration due to friction

Level 3: Gravity Field

  • Environment: Low friction, gravity enabled
  • Learning Goal: Gravitational force affects motion paths
  • Key Observation: Curved trajectories and acceleration

Level 4: Real World

  • Environment: Full friction and gravity
  • Learning Goal: Combined effects in realistic conditions
  • Key Observation: Complex motion patterns

Controls

  • Mouse Click + Drag: Launch objects with variable force
  • Friction Slider: Adjust air resistance (0-10%)
  • Gravity Checkbox: Toggle gravitational force
  • Reset Button: Clear all objects from simulation
  • Next Level: Progress to more complex physics scenarios

⚙️ Game Mechanics

Physics Simulation

// Core physics update loop
const updatePhysics = () => {
  objects.forEach(object => {
    // Apply gravity (downward acceleration)
    if (gravity) object.vy += 0.3;
    
    // Apply friction (velocity reduction)
    if (friction > 0) {
      object.vx *= (1 - friction);
      object.vy *= (1 - friction);
    }
    
    // Update position based on velocity
    object.x += object.vx;
    object.y += object.vy;
    
    // Handle wall collisions with energy loss
    if (wallCollision) {
      velocity *= -0.8; // 20% energy loss on bounce
    }
  });
};

Object Properties

  • Position (x, y) - Current location in pixels
  • Velocity (vx, vy) - Speed and direction vectors
  • Mass - Currently uniform (future enhancement opportunity)
  • Size - Visual radius for rendering and collision detection
  • Color - Randomly assigned from predefined palette
  • Trail - Historical position data for motion visualization

Scoring System

  • Energy Score - Based on launch velocity magnitude
  • Object Count - Total number of launched objects
  • Level Progress - Current stage completion

🔬 Physics Implementation

Newton's First Law Demonstration

The simulation accurately represents the principle that "an object in motion stays in motion unless acted upon by an external force" through:

  1. Inertial Motion - Objects maintain constant velocity in frictionless space
  2. External Forces - Friction and gravity modify object trajectories
  3. Force Visualization - Velocity vectors show current motion state
  4. Energy Conservation - Realistic energy loss during collisions

Mathematical Models

// Friction force calculation
newVelocity = currentVelocity * (1 - frictionCoefficient);

// Gravitational acceleration
velocityY += gravitationalConstant * timeStep;

// Position integration
newPosition = currentPosition + velocity * timeStep;

// Collision response with energy loss
velocityAfterCollision = velocityBeforeCollision * restitutionCoefficient;

📁 Project Structure

InertiaPhysicsLab/
├── public/                     # Static assets
├── src/
│   ├── components/
│   │   └── InertiaGame.tsx    # Main game component
│   ├── App.tsx                # Root application component
│   ├── main.tsx              # Application entry point
│   ├── index.css             # Global styles
│   └── vite-env.d.ts         # TypeScript environment definitions
├── package.json              # Project dependencies and scripts
├── vite.config.ts           # Vite build configuration
├── tailwind.config.js       # Tailwind CSS configuration
├── tsconfig.json            # TypeScript configuration
├── eslint.config.js         # ESLint linting rules
└── README.md                # Project documentation

Key Components

InertiaGame.tsx (Main Component)

  • Canvas Management - HTML5 Canvas setup and event handling
  • Physics Engine - Real-time simulation calculations
  • UI Controls - Level selection, physics parameters, game controls
  • Rendering System - Object drawing, trails, and visual effects
  • Game State Management - Level progression and scoring

Responsive Design

  • Mobile-first approach - Optimized for touch devices
  • Flexible canvas sizing - Adapts to different screen sizes
  • Touch-friendly controls - Large buttons and intuitive gestures

💻 Development

Development Workflow

# Start development server with hot reload
npm run dev

# Run linting checks
npm run lint

# Build for production
npm run build

Code Quality

  • TypeScript - Full type safety for better maintainability
  • ESLint - Consistent code style and error detection
  • React Hooks - Modern React patterns for state management
  • Performance Optimization - Memoization and efficient rendering

Browser Developer Tools

  • Physics Debugging - Console logging for velocity and position data
  • Performance Monitoring - Frame rate and memory usage tracking
  • Canvas Inspection - Visual debugging of game objects

📚 Educational Content

Curriculum Alignment

  • NGSS Standards - Next Generation Science Standards compliance
  • Physics Concepts - Mechanics, forces, and motion
  • Mathematical Skills - Vector mathematics and graphical analysis

Teaching Resources

  • Lesson Plans - Structured activities for classroom use
  • Discussion Questions - Critical thinking prompts
  • Assessment Ideas - Evaluation methods for student understanding

Extension Activities

  1. Experiment Design - Students create their own physics scenarios
  2. Data Collection - Recording and analyzing motion data
  3. Real-world Connections - Relating simulation to everyday physics
  4. Mathematical Modeling - Calculating trajectories and velocities

🌐 Browser Compatibility

Supported Browsers

  • Chrome 88+ (Recommended for best performance)
  • Firefox 85+
  • Safari 14+
  • Edge 88+

Required Features

  • HTML5 Canvas - 2D graphics rendering
  • ES6+ JavaScript - Modern language features
  • CSS Grid & Flexbox - Layout technologies
  • Mouse and Touch Events - User interaction handling

Performance Considerations

  • 60 FPS Target - Smooth animation on modern devices
  • Memory Management - Efficient object lifecycle handling
  • Canvas Optimization - Minimal redraw operations

🤝 Contributing

Getting Involved

We welcome contributions from educators, developers, and physics enthusiasts!

Ways to Contribute

  1. Bug Reports - Help us identify and fix issues
  2. Feature Requests - Suggest new educational tools
  3. Code Contributions - Implement improvements and new features
  4. Educational Content - Create lesson plans and activities
  5. Testing - Validate functionality across different devices

Development Setup

# Fork the repository
git fork https://github.com/sahalpk007/InertiaPhysicsLab.git

# Create feature branch
git checkout -b feature/your-feature-name

# Make changes and commit
git commit -m "Add your feature description"

# Push and create pull request
git push origin feature/your-feature-name

Code Guidelines

  • TypeScript - All new code should be properly typed
  • React Best Practices - Use hooks and functional components
  • Performance - Consider impact on simulation framerate
  • Educational Value - Ensure changes enhance learning outcomes

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

Attribution

  • Physics Concepts - Based on Newtonian mechanics principles
  • Educational Design - Influenced by constructivist learning theory
  • Icon Library - Lucide React for beautiful, consistent icons

🔗 Links

📞 Contact

Project Owner: Muhammed Sahal P K
GitHub: @sahalpk007

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published