mirror of
https://github.com/SamyRai/turash.git
synced 2025-12-26 23:01:33 +00:00
- Remove nested git repository from bugulma/frontend/.git - Add all frontend files to main repository tracking - Convert from separate frontend/backend repos to unified monorepo - Preserve all frontend code and development history as tracked files - Eliminate nested repository complexity for simpler development workflow This creates a proper monorepo structure with frontend and backend coexisting in the same repository for easier development and deployment.
163 lines
3.5 KiB
TypeScript
163 lines
3.5 KiB
TypeScript
/**
|
|
* Pixel Art Library - Shape Helpers
|
|
*
|
|
* Utility functions for creating common pixel art shapes
|
|
*/
|
|
|
|
import type { Point, Rectangle, Circle, Triangle } from '@/lib/pixel-art/types';
|
|
|
|
/**
|
|
* Create a rectangle
|
|
*/
|
|
export function createRect(x: number, y: number, width: number, height: number): Rectangle {
|
|
return { x, y, width, height };
|
|
}
|
|
|
|
/**
|
|
* Create a circle
|
|
*/
|
|
export function createCircle(x: number, y: number, radius: number): Circle {
|
|
return { x, y, radius };
|
|
}
|
|
|
|
/**
|
|
* Create a triangle
|
|
*/
|
|
export function createTriangle(p1: Point, p2: Point, p3: Point): Triangle {
|
|
return { p1, p2, p3 };
|
|
}
|
|
|
|
/**
|
|
* Create an equilateral triangle
|
|
*/
|
|
export function createEquilateralTriangle(
|
|
centerX: number,
|
|
centerY: number,
|
|
size: number
|
|
): Triangle {
|
|
const height = (size * Math.sqrt(3)) / 2;
|
|
return {
|
|
p1: { x: centerX, y: centerY - (height * 2) / 3 },
|
|
p2: { x: centerX - size / 2, y: centerY + height / 3 },
|
|
p3: { x: centerX + size / 2, y: centerY + height / 3 },
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Create a point
|
|
*/
|
|
export function createPoint(x: number, y: number): Point {
|
|
return { x, y };
|
|
}
|
|
|
|
/**
|
|
* Rotate a point around a center
|
|
*/
|
|
export function rotatePoint(point: Point, center: Point, angle: number): Point {
|
|
const cos = Math.cos(angle);
|
|
const sin = Math.sin(angle);
|
|
const dx = point.x - center.x;
|
|
const dy = point.y - center.y;
|
|
return {
|
|
x: center.x + dx * cos - dy * sin,
|
|
y: center.y + dx * sin + dy * cos,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Scale a point
|
|
*/
|
|
export function scalePoint(point: Point, scaleX: number, scaleY: number = scaleX): Point {
|
|
return {
|
|
x: point.x * scaleX,
|
|
y: point.y * scaleY,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Translate a point
|
|
*/
|
|
export function translatePoint(point: Point, dx: number, dy: number): Point {
|
|
return {
|
|
x: point.x + dx,
|
|
y: point.y + dy,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Get distance between two points
|
|
*/
|
|
export function distance(p1: Point, p2: Point): number {
|
|
const dx = p2.x - p1.x;
|
|
const dy = p2.y - p1.y;
|
|
return Math.sqrt(dx * dx + dy * dy);
|
|
}
|
|
|
|
/**
|
|
* Create a polygon from points
|
|
*/
|
|
export function createPolygon(points: Point[]): Point[] {
|
|
return points;
|
|
}
|
|
|
|
/**
|
|
* Create a star shape
|
|
*/
|
|
export function createStar(
|
|
centerX: number,
|
|
centerY: number,
|
|
outerRadius: number,
|
|
innerRadius: number,
|
|
points: number = 5
|
|
): Point[] {
|
|
const star: Point[] = [];
|
|
const angleStep = (Math.PI * 2) / (points * 2);
|
|
|
|
for (let i = 0; i < points * 2; i++) {
|
|
const angle = i * angleStep - Math.PI / 2;
|
|
const radius = i % 2 === 0 ? outerRadius : innerRadius;
|
|
star.push({
|
|
x: centerX + Math.cos(angle) * radius,
|
|
y: centerY + Math.sin(angle) * radius,
|
|
});
|
|
}
|
|
|
|
return star;
|
|
}
|
|
|
|
/**
|
|
* Create a heart shape
|
|
*/
|
|
export function createHeart(centerX: number, centerY: number, size: number): Point[] {
|
|
const points: Point[] = [];
|
|
const steps = 20;
|
|
|
|
for (let i = 0; i <= steps; i++) {
|
|
const t = (i / steps) * Math.PI * 2;
|
|
const x = centerX + size * 16 * Math.pow(Math.sin(t), 3);
|
|
const y =
|
|
centerY -
|
|
size * (13 * Math.cos(t) - 5 * Math.cos(2 * t) - 2 * Math.cos(3 * t) - Math.cos(4 * t));
|
|
points.push({ x, y });
|
|
}
|
|
|
|
return points;
|
|
}
|
|
|
|
/**
|
|
* Create a diamond shape
|
|
*/
|
|
export function createDiamond(
|
|
centerX: number,
|
|
centerY: number,
|
|
width: number,
|
|
height: number
|
|
): Point[] {
|
|
return [
|
|
{ x: centerX, y: centerY - height / 2 }, // Top
|
|
{ x: centerX + width / 2, y: centerY }, // Right
|
|
{ x: centerX, y: centerY + height / 2 }, // Bottom
|
|
{ x: centerX - width / 2, y: centerY }, // Left
|
|
];
|
|
}
|