Changed around line 1
+ class StickFigure {
+ constructor(x, y, size, color) {
+ this.x = x;
+ this.y = y;
+ this.size = size;
+ this.color = color;
+ this.animation = 'none';
+ this.frame = 0;
+ }
+
+ draw(ctx) {
+ ctx.save();
+ ctx.strokeStyle = this.color;
+ ctx.lineWidth = 2;
+ ctx.beginPath();
+
+ // Apply animations
+ let headBob = 0;
+ let armWave = 0;
+ let legKick = 0;
+
+ if (this.animation === 'dance') {
+ headBob = Math.sin(this.frame * 0.1) * 5;
+ armWave = Math.sin(this.frame * 0.2) * 30;
+ legKick = Math.sin(this.frame * 0.15) * 20;
+ } else if (this.animation === 'wave') {
+ armWave = Math.sin(this.frame * 0.1) * 45;
+ } else if (this.animation === 'jump') {
+ headBob = Math.abs(Math.sin(this.frame * 0.1)) * -20;
+ }
+
+ // Head
+ ctx.arc(this.x, this.y + headBob, this.size * 0.15, 0, Math.PI * 2);
+
+ // Body
+ ctx.moveTo(this.x, this.y + this.size * 0.3 + headBob);
+ ctx.lineTo(this.x, this.y + this.size * 0.7 + headBob);
+
+ // Arms
+ ctx.moveTo(this.x, this.y + this.size * 0.4 + headBob);
+ ctx.lineTo(this.x - this.size * 0.3, this.y + this.size * 0.5 + armWave + headBob);
+ ctx.moveTo(this.x, this.y + this.size * 0.4 + headBob);
+ ctx.lineTo(this.x + this.size * 0.3, this.y + this.size * 0.5 - armWave + headBob);
+
+ // Legs
+ ctx.moveTo(this.x, this.y + this.size * 0.7 + headBob);
+ ctx.lineTo(this.x - this.size * 0.2, this.y + this.size + legKick + headBob);
+ ctx.moveTo(this.x, this.y + this.size * 0.7 + headBob);
+ ctx.lineTo(this.x + this.size * 0.2, this.y + this.size - legKick + headBob);
+
+ ctx.stroke();
+ ctx.restore();
+
+ this.frame++;
+ }
+ }
+
+ document.addEventListener('DOMContentLoaded', () => {
+ const canvas = document.getElementById('stickCanvas');
+ const ctx = canvas.getContext('2d');
+ const figures = [];
+
+ // Set canvas size
+ function resizeCanvas() {
+ canvas.width = canvas.offsetWidth;
+ canvas.height = canvas.offsetHeight;
+ }
+
+ resizeCanvas();
+ window.addEventListener('resize', resizeCanvas);
+
+ // Controls
+ const addButton = document.getElementById('addFigure');
+ const clearButton = document.getElementById('clear');
+ const sizeInput = document.getElementById('figureSize');
+ const colorInput = document.getElementById('figureColor');
+ const animationSelect = document.getElementById('animation');
+
+ addButton.addEventListener('click', () => {
+ const x = Math.random() * (canvas.width - 100) + 50;
+ const y = Math.random() * (canvas.height - 200) + 50;
+ const figure = new StickFigure(x, y, sizeInput.value, colorInput.value);
+ figure.animation = animationSelect.value;
+ figures.push(figure);
+ });
+
+ clearButton.addEventListener('click', () => {
+ figures.length = 0;
+ });
+
+ // Animation loop
+ function animate() {
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
+ figures.forEach(figure => figure.draw(ctx));
+ requestAnimationFrame(animate);
+ }
+
+ animate();
+ });