-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
880560f
commit e8b387a
Showing
6 changed files
with
321 additions
and
5 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,100 @@ | ||
import '../styles/ghost.scss'; | ||
import React from 'react'; | ||
|
||
type polyPoint = number[][]; | ||
|
||
function Polygon(props: { points: polyPoint; scale?: number }) { | ||
const scale = props.scale; | ||
|
||
const s = props.points.map((point: number[]) => { | ||
return point | ||
.map(x => { | ||
if (scale) { | ||
return x / scale; | ||
} | ||
return x; | ||
}) | ||
.join(' '); | ||
}); | ||
|
||
return <polygon points={s.join(', ')} />; | ||
} | ||
|
||
export default function PacmanGhost() { | ||
return ( | ||
<div className="ghost inky mt-4"> | ||
<div className="ghost__body"> | ||
<svg> | ||
<Polygon | ||
scale={2} | ||
points={[ | ||
[0, 24], | ||
[4, 24], | ||
[4, 12], | ||
[8, 12], | ||
[8, 8], | ||
[12, 8], | ||
[12, 4], | ||
[20, 4], | ||
[20, 0], | ||
[36, 0], | ||
[36, 4], | ||
[44, 4], | ||
[44, 8], | ||
[48, 8], | ||
[48, 12], | ||
[52, 12], | ||
[52, 24], | ||
[56, 24], | ||
[56, 48], | ||
[0, 48] | ||
]} | ||
/> | ||
</svg> | ||
</div> | ||
<div className="ghost__eye--left"> | ||
<svg> | ||
<Polygon | ||
scale={2} | ||
points={[ | ||
[4, 0], | ||
[12, 0], | ||
[12, 4], | ||
[16, 4], | ||
[16, 16], | ||
[12, 16], | ||
[12, 20], | ||
[4, 20], | ||
[4, 16], | ||
[0, 16], | ||
[0, 4], | ||
[4, 4] | ||
]} | ||
/> | ||
</svg> | ||
</div> | ||
<div className="ghost__eye--right"> | ||
<svg> | ||
<Polygon | ||
scale={2} | ||
points={[ | ||
[4, 0], | ||
[12, 0], | ||
[12, 4], | ||
[16, 4], | ||
[16, 16], | ||
[12, 16], | ||
[12, 20], | ||
[4, 20], | ||
[4, 16], | ||
[0, 16], | ||
[0, 4], | ||
[4, 4] | ||
]} | ||
/> | ||
</svg> | ||
</div> | ||
<div className="ghost__feet" /> | ||
</div> | ||
); | ||
} |
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,207 @@ | ||
$ghost-color: orange; | ||
$ghosts: blinky, pinky, clyde, inky ; | ||
$colors: red, pink, orange, cyan ; | ||
$ghosts-colors: zip($ghosts, $colors); | ||
$duration: 6s; | ||
$scale: 2; | ||
|
||
@keyframes eyes { | ||
0% { | ||
top: (14px / $scale); | ||
} | ||
10% { | ||
top: (16px / $scale); | ||
} | ||
50% { | ||
top: (14px / $scale); | ||
} | ||
70% { | ||
top: (16px / $scale); | ||
} | ||
100% { | ||
top: (14px / $scale); | ||
} | ||
} | ||
@keyframes eyesballs { | ||
0% { | ||
top: 0; | ||
left: (4px / $scale); | ||
} | ||
10% { | ||
top: (8px / $scale); | ||
left: 0; | ||
} | ||
20% { | ||
left: (4px / $scale); | ||
top: (12px / $scale); | ||
} | ||
40% { | ||
top: (8px / $scale); | ||
left: 0; | ||
} | ||
50% { | ||
top: 0; | ||
left: (4px / $scale); | ||
} | ||
70% { | ||
top: (8px / $scale); | ||
left: (8px / $scale); | ||
} | ||
90% { | ||
left: (4px / $scale); | ||
top: (12px / $scale); | ||
} | ||
100% { | ||
top: 0; | ||
left: (4px / $scale); | ||
} | ||
} | ||
|
||
@keyframes feet { | ||
0% { | ||
box-shadow: | ||
(4px / $scale) 0 $ghost-color, | ||
(8px / $scale) 0 $ghost-color, | ||
(12px / $scale) 0 $ghost-color, | ||
|
||
(4px / $scale) (4px / $scale) $ghost-color, | ||
(8px / $scale) (4px / $scale) $ghost-color, | ||
|
||
(20px / $scale) 0 $ghost-color, | ||
(24px / $scale) 0 $ghost-color, | ||
(28px / $scale) 0 $ghost-color, | ||
(32px / $scale) 0 $ghost-color, | ||
|
||
(24px / $scale) (4px / $scale) $ghost-color, | ||
(28px / $scale) (4px / $scale) $ghost-color, | ||
|
||
(40px / $scale) 0 $ghost-color, | ||
(44px / $scale) 0 $ghost-color, | ||
(48px / $scale) 0 $ghost-color, | ||
(52px / $scale) 0 $ghost-color, | ||
|
||
(44px / $scale) (4px / $scale) $ghost-color, | ||
(48px / $scale) (4px / $scale) $ghost-color | ||
; | ||
} | ||
50% { | ||
box-shadow: | ||
0 (4px / $scale) $ghost-color, | ||
(4px / $scale) 0 $ghost-color, | ||
|
||
(12px / $scale) 0 $ghost-color, | ||
(16px / $scale) 0 $ghost-color, | ||
(20px / $scale) 0 $ghost-color, | ||
(16px / $scale) (4px / $scale) $ghost-color, | ||
(20px / $scale) (4px / $scale) $ghost-color, | ||
|
||
(32px / $scale) 0 $ghost-color, | ||
(36px / $scale) 0 $ghost-color, | ||
(40px / $scale) 0 $ghost-color, | ||
(32px / $scale) (4px / $scale) $ghost-color, | ||
(36px / $scale) (4px / $scale) $ghost-color, | ||
|
||
(48px / $scale) 0 $ghost-color, | ||
(52px / $scale) 0 $ghost-color, | ||
(52px / $scale) (4px / $scale) $ghost-color | ||
; | ||
} | ||
100% { | ||
box-shadow: | ||
(4px / $scale) 0 $ghost-color, | ||
(8px / $scale) 0 $ghost-color, | ||
(12px / $scale) 0 $ghost-color, | ||
|
||
(4px / $scale) (4px / $scale) $ghost-color, | ||
(8px / $scale) (4px / $scale) $ghost-color, | ||
|
||
(20px / $scale) 0 $ghost-color, | ||
(24px / $scale) 0 $ghost-color, | ||
(28px / $scale) 0 $ghost-color, | ||
(32px / $scale) 0 $ghost-color, | ||
|
||
(24px / $scale) (4px / $scale) $ghost-color, | ||
(28px / $scale) (4px / $scale) $ghost-color, | ||
|
||
(40px / $scale) 0 $ghost-color, | ||
(44px / $scale) 0 $ghost-color, | ||
(48px / $scale) 0 $ghost-color, | ||
(52px / $scale) 0 $ghost-color, | ||
|
||
(44px / $scale) (4px / $scale) $ghost-color, | ||
(48px / $scale) (4px / $scale) $ghost-color | ||
; | ||
} | ||
} | ||
|
||
.ghost { | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
width: (56px / $scale); | ||
height: (56px / $scale); | ||
|
||
animation-name: move; | ||
animation-duration: $duration; | ||
animation-timing-function: linear; | ||
animation-fill-mode: forwards; | ||
animation-iteration-count: infinite; | ||
} | ||
.ghost__feet { | ||
animation-name: feet; | ||
animation-duration: .4s; | ||
animation-fill-mode: forwards; | ||
animation-timing-function: steps(1); | ||
animation-iteration-count: infinite; | ||
|
||
background: $ghost-color; | ||
content: ''; | ||
display: block; | ||
position: absolute; | ||
top: (48px / $scale); | ||
left: 0; | ||
width: (4px / $scale); | ||
height: (4px / $scale); | ||
z-index: 1; | ||
} | ||
.ghost__body { | ||
fill: $ghost-color; | ||
} | ||
%ghost__eye { | ||
fill: #fff; | ||
position: absolute; | ||
top: (16px / $scale); | ||
width: (16px / $scale); | ||
height: (20px / $scale); | ||
|
||
animation-name: eyes; | ||
animation-duration: $duration; | ||
animation-fill-mode: forwards; | ||
animation-timing-function: steps(1); | ||
animation-iteration-count: infinite; | ||
|
||
&:after { | ||
background: blue; | ||
content: ''; | ||
display: block; | ||
position: absolute; | ||
top: (8px / $scale); | ||
left: 0; | ||
width: (8px / $scale); | ||
height: (8px / $scale); | ||
|
||
animation-name: eyesballs; | ||
animation-duration: $duration; | ||
animation-fill-mode: forwards; | ||
animation-timing-function: steps(1); | ||
animation-iteration-count: infinite; | ||
} | ||
} | ||
.ghost__eye--left { | ||
@extend %ghost__eye; | ||
left: (8px / $scale); | ||
} | ||
.ghost__eye--right { | ||
@extend %ghost__eye; | ||
right: (8px / $scale); | ||
} |