Skip to content

Commit

Permalink
Merge pull request #7 from Intosoft/feat/web
Browse files Browse the repository at this point in the history
feat: rounded vertical path
  • Loading branch information
sakul-budhathoki authored Mar 2, 2024
2 parents 90ccdcf + 2da6c7b commit 95d4c25
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 36 deletions.
6 changes: 5 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
export type EyeFrameShape = "square" | "circle" | "rounded" | "circle-item";
export type EyeballShape = "square" | "circle" | "circle-item";
export type BodyShape = "square" | "circle" | "rounded-horizontal";
export type BodyShape =
| "square"
| "circle"
| "rounded-horizontal"
| "rounded-vertical";

export interface Config {
length: number;
Expand Down
30 changes: 3 additions & 27 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,14 @@ import {
generateLinearGradientByConfig,
isGradientColor,
} from "./utils/gradient";
import { Config, EyeFrameShape, EyeballShape } from "./config";
import {
circleEyeball,
generateEyeballSVGFromConfig,
squareEyeball,
} from "./eyeball";
import {
circleEyeFrame,
generateEyeFrameSVGFromConfig,
roundedEyeFrame,
squareEyeFrame,
} from "./eyeframes";
import { Config } from "./config";
import { generateEyeballSVGFromConfig } from "./eyeball";
import { generateEyeFrameSVGFromConfig } from "./eyeframes";
import { generatePath } from "./path";
import { generateMatrix, renderLogoFromConfig } from "./utils";

const quietZone = 0;

const eyeFrameFunction: {
[key in Exclude<EyeFrameShape, "circle-item">]: Function;
} = {
square: squareEyeFrame,
circle: circleEyeFrame,
rounded: roundedEyeFrame,
};

const eyeballFunction: {
[key in Exclude<EyeballShape, "circle-item">]: Function;
} = {
square: squareEyeball,
circle: circleEyeball,
};

export const generateSVGString = (config: Config) => {
const matrix = generateMatrix(config.value || "https://intosoft.com", "L");

Expand Down
58 changes: 50 additions & 8 deletions src/path/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ export const generatePath = ({ size, matrix, config }: GeneratePathProps) => {
matrix.forEach((row, i) => {
row.forEach((column, j) => {
if (column) {
const neighbors = checkNeighbors({ matrix, i, j });

const isXLast = j == matrix.length - 1;
const isXFirst = j == 0;

const isYLast = i == matrix.length - 1;
const isYFirst = i == 0;

for (let pos of eyeFramePositions) {
if (pos[0] === i && pos[1] === j) {
if (config.shapes.eyeFrame === "circle-item") {
Expand Down Expand Up @@ -47,14 +55,6 @@ export const generatePath = ({ size, matrix, config }: GeneratePathProps) => {
} else if (config.shapes.body === "circle") {
path += generateCirclePath({ i, j, cellSize });
} else if (config.shapes.body === "rounded-horizontal") {
const neighbors = checkNeighbors({ matrix, i, j });

const isXLast = j == matrix.length - 1;
const isXFirst = j == 0;

const isYLast = i == matrix.length - 1;
const isYFirst = i == 0;

if (!neighbors.left && !neighbors.right) {
path += generateCirclePath({
i,
Expand Down Expand Up @@ -97,6 +97,48 @@ export const generatePath = ({ size, matrix, config }: GeneratePathProps) => {
});
return;
}
} else if (config.shapes.body === "rounded-vertical") {
if (!neighbors.top && !neighbors.bottom) {
path += generateCirclePath({
i,
j,
cellSize,
diameter: cellSize - 1,
});
return;
}

if (neighbors.top && neighbors.bottom) {
path += generateSquarePath({
i,
j,
cellSize,
width: cellSize - 1,
});
return;
}

if (!neighbors.top || (neighbors.bottom && isXFirst)) {
path += generateRoundedPath({
i,
j,
cellSize,
roundedSide: "top",
width: cellSize - 1,
});
return;
}

if (!neighbors.bottom || (neighbors.top && isXLast)) {
path += generateRoundedPath({
i,
j,
cellSize,
roundedSide: "bottom",
width: cellSize - 1,
});
return;
}
}
}
});
Expand Down
2 changes: 2 additions & 0 deletions web/src/pages/Home/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export const config: {
body: [
["circle", circleBody],
["square", squareBody],
["rounded-horizontal", squareBody],
["rounded-vertical", squareBody],
],
eyeball: [
["circle", circleEyeball],
Expand Down

0 comments on commit 95d4c25

Please sign in to comment.