Initial commit

This commit is contained in:
Zhongwei Li
2025-11-29 18:48:55 +08:00
commit f28999f19c
127 changed files with 62038 additions and 0 deletions

View File

@@ -0,0 +1,386 @@
#!/bin/bash
# Math Teacher - Game Generator
# Creates gamified math challenges with scoring and achievements
set -e
# Colors
GREEN='\033[0;32m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
NC='\033[0m'
print_success() { echo -e "${GREEN}$1${NC}"; }
print_info() { echo -e "${BLUE} $1${NC}"; }
prompt_select() {
local prompt="$1"
local var_name="$2"
shift 2
local options=("$@")
echo -e "${BLUE}${prompt}${NC}"
PS3="Select (1-${#options[@]}): "
select opt in "${options[@]}"; do
if [ -n "$opt" ]; then
eval "$var_name='$opt'"
break
fi
done
}
echo ""
echo "╔════════════════════════════════════════════════════════════╗"
echo "║ Math Teacher - Game Generator 🎮 ║"
echo "╚════════════════════════════════════════════════════════════╝"
echo ""
print_info "Step 1/3: Game Type"
prompt_select "What type of game?" GAME_TYPE \
"Speed Challenge (Time Attack)" \
"Accuracy Mode (No Mistakes)" \
"Endless Practice (Streak Building)" \
"Boss Battle (Progressive Difficulty)"
print_info "Step 2/3: Math Topic"
prompt_select "Which topic?" TOPIC \
"Mental Math" \
"Fractions" \
"Algebra" \
"Geometry" \
"Mixed Topics"
print_info "Step 3/3: Output"
read -p "Game name (e.g., speed-math-game.html): " OUTPUT_FILE
OUTPUT_DIR="./math-games"
mkdir -p "$OUTPUT_DIR"
OUTPUT_PATH="$OUTPUT_DIR/$OUTPUT_FILE"
print_info "🎮 Generating your math game..."
cat > "$OUTPUT_PATH" << 'GAMEEOF'
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Math Game Challenge</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: 'Arial Black', sans-serif;
background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
color: white;
}
.game-container {
background: rgba(255,255,255,0.1);
backdrop-filter: blur(10px);
padding: 40px;
border-radius: 30px;
box-shadow: 0 20px 60px rgba(0,0,0,0.5);
max-width: 600px;
width: 90%;
text-align: center;
}
h1 { font-size: 3em; margin-bottom: 10px; text-shadow: 3px 3px 6px rgba(0,0,0,0.5); }
.stats {
display: flex;
justify-content: space-around;
margin: 30px 0;
font-size: 1.5em;
}
.stat-box {
background: rgba(255,255,255,0.2);
padding: 15px 25px;
border-radius: 15px;
}
.problem {
font-size: 4em;
margin: 40px 0;
font-weight: bold;
text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}
.answer-input {
font-size: 2em;
padding: 20px;
border: none;
border-radius: 15px;
text-align: center;
width: 100%;
margin: 20px 0;
background: white;
color: #333;
font-weight: bold;
}
.button {
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
color: white;
border: none;
padding: 20px 40px;
font-size: 1.5em;
border-radius: 15px;
cursor: pointer;
margin: 10px;
transition: transform 0.2s;
font-weight: bold;
}
.button:hover { transform: scale(1.05); }
.button:active { transform: scale(0.95); }
.feedback {
font-size: 2em;
margin: 20px 0;
min-height: 60px;
display: flex;
align-items: center;
justify-content: center;
}
.correct { color: #4CAF50; }
.incorrect { color: #FF6347; }
.timer {
font-size: 3em;
color: #FFD700;
font-weight: bold;
margin: 20px 0;
}
.progress-bar {
width: 100%;
height: 20px;
background: rgba(255,255,255,0.2);
border-radius: 10px;
overflow: hidden;
margin: 20px 0;
}
.progress-fill {
height: 100%;
background: linear-gradient(90deg, #4CAF50, #8BC34A);
transition: width 0.3s ease;
}
.achievement-popup {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) scale(0);
background: linear-gradient(135deg, #FFD700, #FFA500);
color: #333;
padding: 40px;
border-radius: 20px;
font-size: 2em;
font-weight: bold;
box-shadow: 0 20px 60px rgba(0,0,0,0.5);
animation: popIn 0.5s ease forwards;
z-index: 1000;
}
@keyframes popIn {
to { transform: translate(-50%, -50%) scale(1); }
}
.game-over {
display: none;
flex-direction: column;
gap: 20px;
}
.final-score { font-size: 4em; color: #FFD700; }
</style>
</head>
<body>
<div class="game-container">
<h1>🎯 Math Challenge</h1>
<div class="stats">
<div class="stat-box">
<div>Score</div>
<div id="score">0</div>
</div>
<div class="stat-box">
<div>Streak</div>
<div id="streak">0</div>
</div>
<div class="stat-box">
<div>Level</div>
<div id="level">1</div>
</div>
</div>
<div id="game-area">
<div class="timer" id="timer">60</div>
<div class="progress-bar">
<div class="progress-fill" id="progress"></div>
</div>
<div class="problem" id="problem">5 + 3 = ?</div>
<input type="number" class="answer-input" id="answer" placeholder="Your answer...">
<button class="button" onclick="checkAnswer()">Submit ✓</button>
<div class="feedback" id="feedback"></div>
</div>
<div class="game-over" id="gameOver">
<h2>🎉 Game Over!</h2>
<div class="final-score" id="finalScore">0</div>
<p id="rating"></p>
<button class="button" onclick="restartGame()">Play Again 🔄</button>
</div>
</div>
<script>
let score = 0;
let streak = 0;
let level = 1;
let currentProblem = {};
let timeRemaining = 60;
let gameActive = true;
let timerInterval;
const operators = ['+', '-', '×', '÷'];
function generateProblem() {
const difficulty = Math.min(level, 10);
const range = 10 * difficulty;
const op = operators[Math.floor(Math.random() * operators.length)];
let num1 = Math.floor(Math.random() * range) + 1;
let num2 = Math.floor(Math.random() * range) + 1;
// Ensure num1 >= num2 for subtraction
if (op === '-' && num1 < num2) [num1, num2] = [num2, num1];
// Make division result integer
if (op === '÷') {
num1 = num2 * (Math.floor(Math.random() * 10) + 1);
}
let answer;
switch(op) {
case '+': answer = num1 + num2; break;
case '-': answer = num1 - num2; break;
case '×': answer = num1 * num2; break;
case '÷': answer = num1 / num2; break;
}
currentProblem = { num1, num2, op, answer };
document.getElementById('problem').textContent = `${num1} ${op} ${num2} = ?`;
document.getElementById('answer').value = '';
document.getElementById('answer').focus();
}
function checkAnswer() {
if (!gameActive) return;
const userAnswer = parseFloat(document.getElementById('answer').value);
const feedback = document.getElementById('feedback');
if (userAnswer === currentProblem.answer) {
streak++;
const points = 10 * (1 + streak * 0.1);
score += Math.floor(points);
feedback.innerHTML = `<span class="correct">✓ Correct! +${Math.floor(points)} points</span>`;
if (streak % 5 === 0) {
showAchievement(`🔥 ${streak} Streak!`);
level++;
document.getElementById('level').textContent = level;
}
updateStats();
setTimeout(generateProblem, 500);
} else {
streak = 0;
feedback.innerHTML = `<span class="incorrect">✗ Incorrect! Answer: ${currentProblem.answer}</span>`;
updateStats();
setTimeout(() => {
feedback.innerHTML = '';
generateProblem();
}, 1500);
}
}
function updateStats() {
document.getElementById('score').textContent = score;
document.getElementById('streak').textContent = streak;
document.getElementById('progress').style.width = `${(score % 100)}%`;
}
function startTimer() {
timerInterval = setInterval(() => {
timeRemaining--;
document.getElementById('timer').textContent = timeRemaining;
if (timeRemaining <= 10) {
document.getElementById('timer').style.color = '#FF6347';
}
if (timeRemaining <= 0) {
endGame();
}
}, 1000);
}
function endGame() {
gameActive = false;
clearInterval(timerInterval);
document.getElementById('game-area').style.display = 'none';
document.getElementById('gameOver').style.display = 'flex';
document.getElementById('finalScore').textContent = score;
let rating;
if (score >= 500) rating = '🏆 Math Master!';
else if (score >= 300) rating = '⭐ Excellent!';
else if (score >= 200) rating = '👍 Great job!';
else if (score >= 100) rating = '✓ Good effort!';
else rating = '💪 Keep practicing!';
document.getElementById('rating').textContent = rating;
}
function restartGame() {
score = 0;
streak = 0;
level = 1;
timeRemaining = 60;
gameActive = true;
document.getElementById('game-area').style.display = 'block';
document.getElementById('gameOver').style.display = 'none';
document.getElementById('timer').style.color = '#FFD700';
updateStats();
generateProblem();
startTimer();
}
function showAchievement(text) {
const popup = document.createElement('div');
popup.className = 'achievement-popup';
popup.textContent = text;
document.body.appendChild(popup);
setTimeout(() => popup.remove(), 2000);
}
// Enter key submits answer
document.getElementById('answer').addEventListener('keypress', (e) => {
if (e.key === 'Enter') checkAnswer();
});
// Initialize
generateProblem();
startTimer();
</script>
</body>
</html>
GAMEEOF
echo ""
print_success "Game created: $OUTPUT_PATH"
echo ""
print_info "Game features:"
echo " ✓ 60-second time challenge"
echo " ✓ Progressive difficulty"
echo " ✓ Streak bonuses"
echo " ✓ Achievement system"
echo " ✓ Final score rating"
echo ""
print_info "🚀 Opening game in browser..."
open "$OUTPUT_PATH"

View File

@@ -0,0 +1,458 @@
#!/bin/bash
# Math Teacher - Interactive Playground Generator
# Creates instant, interactive math learning experiences
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
NC='\033[0m'
# Helper functions
print_success() {
echo -e "${GREEN}$1${NC}"
}
print_error() {
echo -e "${RED}$1${NC}"
}
print_info() {
echo -e "${BLUE} $1${NC}"
}
print_warning() {
echo -e "${YELLOW}$1${NC}"
}
prompt_input() {
local prompt="$1"
local var_name="$2"
local required="${3:-false}"
while true; do
echo -e "${BLUE}${prompt}${NC}"
read -r input
if [ -z "$input" ] && [ "$required" = true ]; then
print_error "This field is required."
continue
fi
eval "$var_name='$input'"
break
done
}
prompt_select() {
local prompt="$1"
local var_name="$2"
shift 2
local options=("$@")
echo -e "${BLUE}${prompt}${NC}"
PS3="Select (1-${#options[@]}): "
select opt in "${options[@]}"; do
if [ -n "$opt" ]; then
eval "$var_name='$opt'"
break
else
print_error "Invalid selection. Try again."
fi
done
}
# Banner
echo ""
echo "╔════════════════════════════════════════════════════════════╗"
echo "║ ║"
echo "║ Math Teacher - Playground Generator 🎮 ║"
echo "║ ║"
echo "╚════════════════════════════════════════════════════════════╝"
echo ""
# Step 1: Math Topic Level
print_info "Step 1/5: Choose Math Level"
prompt_select "What level?" LEVEL \
"Elementary (Ages 6-12)" \
"Middle School (Ages 12-15)" \
"High School (Ages 15-18)" \
"Advanced (College+)"
# Step 2: Specific Topic
print_info "Step 2/5: Choose Topic"
case $LEVEL in
"Elementary (Ages 6-12)")
prompt_select "Which topic?" TOPIC \
"Fractions" \
"Multiplication Table" \
"Geometry Shapes" \
"Number Patterns" \
"Time & Clock" \
"Money & Change"
;;
"Middle School (Ages 12-15)")
prompt_select "Which topic?" TOPIC \
"Linear Equations" \
"Ratios & Proportions" \
"Percentages" \
"Basic Statistics" \
"Pythagorean Theorem" \
"Order of Operations"
;;
"High School (Ages 15-18)")
prompt_select "Which topic?" TOPIC \
"Quadratic Functions" \
"Trigonometry" \
"Exponential Functions" \
"Logarithms" \
"Polynomial Graphs" \
"Systems of Equations"
;;
"Advanced (College+)")
prompt_select "Which topic?" TOPIC \
"Derivatives" \
"Integrals" \
"Limits" \
"Optimization" \
"Series & Sequences" \
"Differential Equations"
;;
esac
# Step 3: Interaction Type
print_info "Step 3/5: Type of Experience"
prompt_select "What kind of playground?" INTERACTION_TYPE \
"Visual Explorer (Manipulate and see changes)" \
"Practice Problems (Randomized with hints)" \
"Challenge Game (Timed with scoring)" \
"Concept Demo (Animated explanation)" \
"Sandbox (Open exploration)"
# Step 4: Difficulty
print_info "Step 4/5: Difficulty Level"
prompt_select "Difficulty?" DIFFICULTY \
"Easy" \
"Medium" \
"Hard"
# Step 5: Output Location
print_info "Step 5/5: Save Location"
prompt_input "Output file name (e.g., fractions-playground.html):" OUTPUT_FILE true
OUTPUT_DIR="./math-playgrounds"
mkdir -p "$OUTPUT_DIR"
OUTPUT_PATH="$OUTPUT_DIR/$OUTPUT_FILE"
# Generate the playground HTML
echo ""
print_info "🎨 Generating your interactive math playground..."
echo ""
# Create the HTML file based on topic
case $TOPIC in
"Fractions")
generate_fractions_playground
;;
"Quadratic Functions")
generate_quadratic_playground
;;
"Derivatives")
generate_derivatives_playground
;;
*)
generate_generic_playground
;;
esac
# Success message
echo ""
echo "╔════════════════════════════════════════════════════════════╗"
echo "║ 🎉 Success! ║"
echo "╚════════════════════════════════════════════════════════════╝"
echo ""
print_success "Playground created: $OUTPUT_PATH"
print_success "Topic: $TOPIC"
print_success "Level: $LEVEL"
print_success "Type: $INTERACTION_TYPE"
echo ""
print_info "🚀 Opening playground in browser..."
open "$OUTPUT_PATH"
echo ""
print_info "💡 Playground tips:"
echo " 2. Or double-click the file"
echo " 3. Start learning by playing!"
echo ""
print_info "💡 The playground includes:"
echo " ✓ Interactive visualizations"
echo " ✓ Real-time feedback"
echo " ✓ Gamification (points & achievements)"
echo " ✓ Hints and explanations"
echo " ✓ Mobile-friendly design"
echo ""
# Function implementations would go here
# For brevity, showing one example:
generate_generic_playground() {
cat > "$OUTPUT_PATH" << 'EOF'
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Math Playground - TOPIC_NAME</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
color: white;
}
.header {
text-align: center;
margin-bottom: 30px;
}
h1 { font-size: 3em; margin-bottom: 10px; text-shadow: 2px 2px 4px rgba(0,0,0,0.3); }
.score-board {
background: rgba(255,255,255,0.2);
padding: 15px 30px;
border-radius: 20px;
font-size: 1.5em;
display: inline-block;
backdrop-filter: blur(10px);
}
.main-content {
background: white;
padding: 40px;
border-radius: 20px;
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
color: #333;
max-width: 900px;
width: 100%;
}
.visualization {
width: 100%;
height: 400px;
border: 3px solid #667eea;
border-radius: 15px;
margin: 20px 0;
background: #f9f9f9;
}
.controls {
display: grid;
gap: 20px;
margin: 20px 0;
}
.control-group {
display: flex;
flex-direction: column;
gap: 10px;
}
label {
font-weight: bold;
font-size: 1.1em;
color: #667eea;
}
input[type="range"] {
width: 100%;
height: 10px;
border-radius: 5px;
background: #ddd;
outline: none;
cursor: pointer;
}
input[type="number"], input[type="text"] {
padding: 12px;
font-size: 1.1em;
border: 2px solid #667eea;
border-radius: 10px;
width: 100%;
}
button {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
padding: 15px 30px;
font-size: 1.2em;
border-radius: 10px;
cursor: pointer;
transition: transform 0.2s, box-shadow 0.2s;
font-weight: bold;
}
button:hover {
transform: translateY(-2px);
box-shadow: 0 10px 20px rgba(0,0,0,0.2);
}
button:active { transform: translateY(0); }
.explanation {
background: #f0f7ff;
padding: 20px;
border-radius: 10px;
margin: 20px 0;
border-left: 5px solid #667eea;
line-height: 1.8;
}
.achievement {
position: fixed;
top: 20px;
right: 20px;
background: gold;
color: #333;
padding: 20px 30px;
border-radius: 15px;
font-weight: bold;
font-size: 1.2em;
animation: slideIn 0.5s ease;
box-shadow: 0 10px 30px rgba(0,0,0,0.3);
z-index: 1000;
}
@keyframes slideIn {
from { transform: translateX(400px); opacity: 0; }
to { transform: translateX(0); opacity: 1; }
}
@media (max-width: 768px) {
h1 { font-size: 2em; }
.main-content { padding: 20px; }
}
</style>
</head>
<body>
<div class="header">
<h1>🎯 TOPIC_NAME Playground</h1>
<div class="score-board">
Points: <span id="points">0</span> 🌟 | Streak: <span id="streak">0</span> 🔥
</div>
</div>
<div class="main-content">
<canvas id="canvas" class="visualization"></canvas>
<div class="controls">
<div class="control-group">
<label for="input1">Parameter 1:</label>
<input type="range" id="input1" min="0" max="10" value="5" step="0.1">
<span id="value1">5</span>
</div>
<div class="control-group">
<label for="input2">Parameter 2:</label>
<input type="range" id="input2" min="0" max="10" value="3" step="0.1">
<span id="value2">3</span>
</div>
<button onclick="newProblem()">New Challenge 🎲</button>
<button onclick="showHint()">Get Hint 💡</button>
</div>
<div class="explanation" id="explanation">
Welcome to your interactive math playground! Adjust the sliders above to explore and learn.
</div>
</div>
<script>
let points = 0;
let streak = 0;
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
// Set canvas size
canvas.width = canvas.offsetWidth;
canvas.height = canvas.offsetHeight;
// Event listeners
document.getElementById('input1').addEventListener('input', update);
document.getElementById('input2').addEventListener('input', update);
function update() {
const val1 = parseFloat(document.getElementById('input1').value);
const val2 = parseFloat(document.getElementById('input2').value);
document.getElementById('value1').textContent = val1.toFixed(1);
document.getElementById('value2').textContent = val2.toFixed(1);
visualize(val1, val2);
updateExplanation(val1, val2);
}
function visualize(val1, val2) {
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Example visualization - customize based on topic
const centerX = canvas.width / 2;
const centerY = canvas.height / 2;
// Draw based on parameters
ctx.fillStyle = '#667eea';
ctx.beginPath();
ctx.arc(centerX, centerY, val1 * 20, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = '#FF6347';
ctx.beginPath();
ctx.arc(centerX + val2 * 30, centerY, 30, 0, Math.PI * 2);
ctx.fill();
}
function updateExplanation(val1, val2) {
const result = val1 + val2;
document.getElementById('explanation').innerHTML = `
<strong>Current Values:</strong><br>
Parameter 1: ${val1.toFixed(2)}<br>
Parameter 2: ${val2.toFixed(2)}<br>
<strong>Result: ${result.toFixed(2)}</strong>
`;
}
function newProblem() {
awardPoints(5);
document.getElementById('input1').value = Math.random() * 10;
document.getElementById('input2').value = Math.random() * 10;
update();
}
function showHint() {
showAchievement('💡 Try different values and see what happens!');
}
function awardPoints(amount) {
points += amount;
streak++;
document.getElementById('points').textContent = points;
document.getElementById('streak').textContent = streak;
if (streak % 5 === 0) {
showAchievement(`🔥 ${streak} streak! Awesome!`);
}
}
function showAchievement(text) {
const achievement = document.createElement('div');
achievement.className = 'achievement';
achievement.textContent = text;
document.body.appendChild(achievement);
setTimeout(() => achievement.remove(), 3000);
}
// Initialize
update();
</script>
</body>
</html>
EOF
# Replace placeholders
sed -i "s/TOPIC_NAME/$TOPIC/g" "$OUTPUT_PATH"
}
print_info "🎓 Happy learning!"