export function calculateLevel(pixelsPainted: number): number {
	return Math.floor(Math.sqrt(pixelsPainted / 100)) + 1;
}

export function getPixelsForLevel(level: number): number {
	return ((level - 1) ** 2) * 100;
}

export function getPixelsForNextLevel(currentLevel: number): number {
	return (currentLevel ** 2) * 100;
}

export function getLevelProgress(pixelsPainted: number): number {
	const currentLevel = calculateLevel(pixelsPainted);
	const pixelsForCurrentLevel = getPixelsForLevel(currentLevel);
	const pixelsForNextLevel = getPixelsForNextLevel(currentLevel);
	const pixelsInCurrentLevel = pixelsPainted - pixelsForCurrentLevel;
	const pixelsNeededForLevel = pixelsForNextLevel - pixelsForCurrentLevel;

	if (pixelsNeededForLevel === 0) return 0;
	return (pixelsInCurrentLevel / pixelsNeededForLevel) * 100;
}
