diff --git a/src/config.ts b/src/config.ts index e357ba0..3395121 100644 --- a/src/config.ts +++ b/src/config.ts @@ -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; diff --git a/src/index.ts b/src/index.ts index 6c7bfc1..0fdc4bc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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]: Function; -} = { - square: squareEyeFrame, - circle: circleEyeFrame, - rounded: roundedEyeFrame, -}; - -const eyeballFunction: { - [key in Exclude]: Function; -} = { - square: squareEyeball, - circle: circleEyeball, -}; - export const generateSVGString = (config: Config) => { const matrix = generateMatrix(config.value || "https://intosoft.com", "L"); diff --git a/src/path/index.ts b/src/path/index.ts index 604dd9c..3249065 100644 --- a/src/path/index.ts +++ b/src/path/index.ts @@ -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") { @@ -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, @@ -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; + } } } }); diff --git a/web/src/pages/Home/config.ts b/web/src/pages/Home/config.ts index 1d4e097..c1ebffd 100644 --- a/web/src/pages/Home/config.ts +++ b/web/src/pages/Home/config.ts @@ -19,6 +19,8 @@ export const config: { body: [ ["circle", circleBody], ["square", squareBody], + ["rounded-horizontal", squareBody], + ["rounded-vertical", squareBody], ], eyeball: [ ["circle", circleEyeball],