-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from harry-whorlow/logo-v2
feat(logo animation): second iteration of logo animation
- Loading branch information
Showing
7 changed files
with
80 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const getRandomAnimationTime = (max: number, min: number) => { | ||
return Math.random() * (max - min + 1) + min; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; |
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters