diff --git a/astro.config.mjs b/astro.config.mjs index 0106689..4436ed4 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -4,4 +4,5 @@ import { defineConfig } from 'astro/config'; export default defineConfig({ site: 'https://harry-whorlow.github.io', base: '/portfolio', + server: { port: 1234, host: true }, }); diff --git a/src/components/Logo/Logo.astro b/src/components/Logo/Logo.astro index 99e48a7..ef7e27f 100644 --- a/src/components/Logo/Logo.astro +++ b/src/components/Logo/Logo.astro @@ -375,6 +375,7 @@ #cell-15-1 { width: 65px; left: 10px; + background-color: var(--accent-pink); } #cell-15-2 { @@ -417,25 +418,23 @@ diff --git a/src/components/Logo/utils/getRandomAnimationTime.ts b/src/components/Logo/utils/getRandomAnimationTime.ts new file mode 100644 index 0000000..5ce28ed --- /dev/null +++ b/src/components/Logo/utils/getRandomAnimationTime.ts @@ -0,0 +1,3 @@ +export const getRandomAnimationTime = (max: number, min: number) => { + return Math.random() * (max - min + 1) + min; +}; diff --git a/src/components/Logo/utils/getRandomStartPosition.ts b/src/components/Logo/utils/getRandomStartPosition.ts new file mode 100644 index 0000000..ced4ed3 --- /dev/null +++ b/src/components/Logo/utils/getRandomStartPosition.ts @@ -0,0 +1,56 @@ +type PositionType = [number, number]; + +export interface LocationMap { + [key: string]: PositionType[]; +} + +const isBetween = ({ largerEl, smallerEl }: { largerEl: [number, number]; smallerEl: [number, number] }) => { + const leftBound = smallerEl[0] >= largerEl[0] && smallerEl[0] <= largerEl[1]; + const rightBound = smallerEl[1] >= largerEl[0] && smallerEl[1] <= largerEl[1]; + + return leftBound || rightBound; +}; + +const checkCellBounds = (newElement: [number, number], existingElement: [number, number]) => { + if (newElement[1] - newElement[0] > existingElement[1] - existingElement[0]) { + // if new element if smaller than old element + + return isBetween({ largerEl: newElement, smallerEl: existingElement }); + } else { + // re-ordered so that were comparing the smaller span to larger to save on more maths + + return isBetween({ largerEl: existingElement, smallerEl: newElement }); + } +}; + +export const getRandomStartPosInt = (element: HTMLElement, locationMap: LocationMap): number => { + const [, row] = element.id.split('-'); + + const { left: elementLeftPoint, width: elementWidth } = element.getBoundingClientRect(); + + let randomPoint = (window.screen.width - elementWidth - 20) * Math.random(); + let startVector: number; + + if (randomPoint > elementLeftPoint) { + startVector = randomPoint - elementLeftPoint; + } else { + startVector = (elementLeftPoint - randomPoint) * -1; + } + + const newRandomPosition: PositionType = [randomPoint - 5, randomPoint + elementWidth]; + + switch (true) { + case locationMap[row] == undefined: + locationMap[row] = [newRandomPosition]; + break; + + case locationMap[row].some((existingPosition) => checkCellBounds(newRandomPosition, existingPosition)): + startVector = getRandomStartPosInt(element, locationMap); + break; + + default: + locationMap[row] = [...locationMap[row], ...[newRandomPosition]]; + } + + return startVector; +}; diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index abeea73..3d91af1 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -12,7 +12,7 @@ const { title } = Astro.props; - + {title} diff --git a/src/pages/index.astro b/src/pages/index.astro index 0e9dbfd..d16ad42 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -18,8 +18,6 @@ import CustomCursor from '../components/CustomCursor/CustomCursor.astro'; height: 1000px; width: 100%; - overflow: hidden; - display: flex; flex-direction: column; align-items: center;