Skip to content

Instantly share code, notes, and snippets.

@yhdesai
Created December 1, 2021 12:03
Show Gist options
  • Save yhdesai/69e032c0ca3362581f747b2610885cb1 to your computer and use it in GitHub Desktop.
Save yhdesai/69e032c0ca3362581f747b2610885cb1 to your computer and use it in GitHub Desktop.
The Flying Robot (Pure CSS Drawing/Animation) [codepen challenge]
<div class="container">
<div class="spaceship">
<div id="star1"></div>
<div id="star2"></div>
<div id="star3"></div>
<div class="robot">
<div id="half">
<div id="brain"></div>
</div>
<div id="head">
<span id="lc"></span><span id="le"></span><span id="re"></span>
<div id="mouth"></div>
<span id="rc"></span>
</div>
<div id="foot"></div>
<div id="leg-1"></div>
<div id="leg-2"></div>
</div>
<div class="spaceship_top"></div>
<div class="spaceship_middle">
<div class="spaceship_balls_1"></div>
<div class="spaceship_balls_2"></div>
<div class="spaceship_balls_3"></div>
<div class="spaceship_balls_4"></div>
<div class="spaceship_balls_5"></div>
</div>
<div class="spaceship_bottom">
<div class="abduct_hole1"></div>
<div class="abduct_hole2"></div>
<div class="abduct_hole3"></div>
<div class="abduct_hole4"></div>
<div class="abduct_hole5"></div>
</div>
</div>
</div>
// No JS. Thanks for visiting!
// Thanks to @Aleks for robot divs
// If you enjoy make sure to ♥ this codepen!
// Not tested on mobile.
@dimension: 100px;
* {
margin: 0 auto;
-webkit-user-select: none;
}
body {
height: 100vh;
overflow: hidden;
animation: bodycolor 16s infinite;
}
.centered() {
margin: auto;
position: absolute;
bottom: 0;
left: 0;
top: 0;
right: 0;
}
.container {
position: absolute;
width: 100%;
height: 100%;
overflow: hidden;
}
.spaceship {
position: absolute;
top: 30%;
height: 250px;
width: 300px;
margin-left: -150px;
animation: spaceshipleft 8s infinite;
}
.spaceship_top {
.centered();
top: -150px;
height: 150px;
width: 200px;
background-color: #f6a7ba;
border-radius: 8rem 8rem 0 0;
box-shadow: inset 6px 2px 3px 0 #c2c2c2;
}
.spaceship_top::before {
content: "";
position: absolute;
left: 150px;
top: 32px;
height: 8px;
width: 10px;
background-color: white;
border-radius: 2rem;
transform: rotate(42deg);
}
.spaceship_top::after {
content: "";
position: absolute;
left: 130px;
top: 20px;
height: 10px;
width: 20px;
background-color: white;
border-radius: 2rem;
transform: rotate(32deg);
}
.spaceship_middle {
.centered();
width: 300px;
height: 70px;
overflow: hidden;
border-radius: 5rem;
box-shadow: inset 6px 2px 3px 0 #c2c2c2;
z-index: 3;
animation: colorswap_middle 16s infinite;
}
.spaceship_bottom {
.centered();
top: 75px;
width: 165px;
height: 30px;
background-color: #9c0327;
border-radius: 0 0 2rem 2rem;
z-index: -1;
box-shadow: inset 5px 2px 3px 0 #c2c2c2;
z-index: 2;
}
.abduct_hole1 {
position: absolute;
left: 32px;
border: 2px solid white;
border-radius: 50%;
background: rgba(0, 0, 0, 0);
width: 100px;
height: 100px;
transform: rotateX(75deg);
animation: abduct 8s infinite, abductcolor 16s infinite;
}
.abduct_hole2 {
position: absolute;
left: 32px;
top: 20px;
border: 2px solid white;
border-radius: 50%;
background: rgba(0, 0, 0, 0);
width: 100px;
height: 100px;
transform: rotateX(75deg);
animation: abductreverse 8s 0.1s infinite, abductcolor 16s infinite;
}
.abduct_hole3 {
position: absolute;
left: 32px;
top: 35px;
border: 2px solid white;
border-radius: 50%;
background: rgba(0, 0, 0, 0);
width: 100px;
height: 100px;
transform: rotateX(75deg);
animation: abduct 8s 0.2s infinite, abductcolor 16s infinite;
}
.abduct_hole4 {
position: absolute;
left: 30px;
top: 50px;
border: 2px solid white;
border-radius: 50%;
background: rgba(0, 0, 0, 0);
width: 100px;
height: 100px;
transform: rotateX(75deg);
animation: abductreverse 8s infinite, abductcolor 16s infinite;
}
.abduct_hole5 {
position: absolute;
left: 32px;
top: 70px;
border: 2px solid white;
border-radius: 50%;
background: rgba(0, 0, 0, 0);
width: 100px;
height: 100px;
transform: rotateX(75deg);
animation: abductreverse 8s infinite, abductcolor 16s infinite;
}
.spaceship_balls_1 {
position: absolute;
top: 10px;
height: 50px;
width: 50px;
border-radius: 50%;
animation: moveleft 3s linear infinite, colorswap 16s infinite;
box-shadow: inset 6px 2px 3px 0 #c2c2c2;
}
.spaceship_balls_1::before {
content: "";
position: absolute;
top: 0;
left: 60px;
background-color: inherit;
width: 50px;
height: 50px;
border-radius: 50%;
box-shadow: inset 6px 2px 3px 0 #c2c2c2;
}
.spaceship_balls_1::after {
content: "";
position: absolute;
top: 0;
left: 120px;
background-color: inherit;
width: 50px;
height: 50px;
border-radius: 50%;
box-shadow: inset 6px 2px 3px 0 #c2c2c2;
}
.spaceship_balls_2 {
position: absolute;
top: 10px;
height: 50px;
width: 50px;
left: 360px;
border-radius: 50%;
animation: moveleft 3s linear 0.64s infinite, colorswap 16s infinite;
box-shadow: inset 6px 2px 3px 0 #c2c2c2;
}
.spaceship_balls_2::before {
content: "";
position: absolute;
top: 0;
left: 60px;
background-color: inherit;
width: 50px;
height: 50px;
border-radius: 50%;
box-shadow: inset 6px 2px 3px 0 #c2c2c2;
}
.spaceship_balls_2::after {
content: "";
position: absolute;
top: 0;
left: 120px;
background-color: inherit;
width: 50px;
height: 50px;
border-radius: 50%;
box-shadow: inset 6px 2px 3px 0 #c2c2c2;
}
.spaceship_balls_3 {
position: absolute;
top: 10px;
height: 50px;
width: 50px;
left: 720px;
border-radius: 50%;
animation: moveleft 3s linear 1.28s infinite, colorswap 16s infinite;
box-shadow: inset 6px 2px 3px 0 #c2c2c2;
}
.spaceship_balls_3::before {
content: "";
position: absolute;
top: 0;
left: 60px;
background-color: inherit;
width: 50px;
height: 50px;
border-radius: 50%;
box-shadow: inset 6px 2px 3px 0 #c2c2c2;
}
.spaceship_balls_3::after {
content: "";
position: absolute;
top: 0;
left: 120px;
background-color: inherit;
width: 50px;
height: 50px;
border-radius: 50%;
box-shadow: inset 6px 2px 3px 0 #c2c2c2;
}
.spaceship_balls_4 {
position: absolute;
top: 10px;
height: 50px;
width: 50px;
left: 1080px;
border-radius: 50%;
animation: moveleft 3s linear 1.92s infinite, colorswap 16s infinite;
box-shadow: inset 6px 2px 3px 0 #c2c2c2;
}
.spaceship_balls_4::before {
content: "";
position: absolute;
top: 0;
left: 60px;
background-color: inherit;
width: 50px;
height: 50px;
border-radius: 50%;
box-shadow: inset 6px 2px 3px 0 #c2c2c2;
}
.spaceship_balls_4::after {
content: "";
position: absolute;
top: 0;
left: 120px;
background-color: inherit;
width: 50px;
height: 50px;
border-radius: 50%;
box-shadow: inset 6px 2px 3px 0 #c2c2c2;
}
.spaceship_balls_5 {
position: absolute;
top: 10px;
height: 50px;
width: 50px;
left: 1440px;
border-radius: 50%;
animation: moveleft 3s linear 2.56s infinite, colorswap 16s infinite;
box-shadow: inset 6px 2px 3px 0 #c2c2c2;
}
.spaceship_balls_5::before {
content: "";
position: absolute;
top: 0;
left: 60px;
background-color: inherit;
width: 50px;
height: 50px;
border-radius: 50%;
box-shadow: inset 6px 2px 3px 0 #c2c2c2;
}
.spaceship_balls_5::after {
content: "";
position: absolute;
top: 0;
left: 120px;
background-color: inherit;
width: 50px;
height: 50px;
border-radius: 50%;
box-shadow: inset 6px 2px 3px 0 #c2c2c2;
}
.robot {
text-align: center;
width: @dimension * 3;
position: absolute;
left: 50%;
margin-left: @dimension * 3 / -2;
margin-top: @dimension * -2;
transform: scale(0.25);
z-index: 1;
animation: robotup 16s infinite;
}
#half {
text-align: center;
width: @dimension * 3 - 20;
height: @dimension * 2;
background: #f16385;
border: 10px solid #a62a48;
border-top-left-radius: @dimension * 3;
border-top-right-radius: @dimension * 3;
}
#brain {
margin: 0 auto;
margin-top: 20px;
width: @dimension + 60;
height: @dimension - 40;
background: #f48aa3;
border: 20px solid #d6365c;
border-top-left-radius: @dimension * 2;
border-top-right-radius: @dimension * 2;
}
#head {
position: inherit;
top: @dimension + 40;
right: -10px;
width: @dimension * 3 + 20;
height: @dimension;
background: #162736;
}
#foot {
position: inherit;
top: @dimension * 2 + 40;
left: 10px;
width: (@dimension * 2) + 80px;
height: @dimension / 5;
background: #162736;
}
#le {
margin-top: 20px;
margin-right: 10px;
display: inline-block;
width: @dimension / 3;
height: @dimension / 3;
border: 10px solid #d6365c;
border-radius: 50%;
background: #f8b1c2;
}
#re {
margin-left: 10px;
display: inline-block;
width: @dimension / 3;
height: @dimension / 3;
border: 10px solid #d6365c;
border-radius: 50%;
background: #f8b1c2;
}
#lc {
margin-right: 10px;
display: inline-block;
width: @dimension / 8;
height: @dimension / 8;
border-radius: 50%;
background: #ee3d67;
box-shadow: 0 0 5px rgba(255, 0, 102, 1);
-webkit-box-shadow: 0 0 5px rgba(255, 0, 102, 1);
-moz-box-shadow: 0 0 5px rgba(255, 0, 102, 1);
}
#rc {
display: inline-block;
width: @dimension / 8;
height: @dimension / 8;
border-radius: 50%;
background: #ee3d67;
box-shadow: 0 0 5px rgba(255, 0, 102, 1);
-webkit-box-shadow: 0 0 5px rgba(255, 0, 102, 1);
-moz-box-shadow: 0 0 5px rgba(255, 0, 102, 1);
}
#mouth {
z-index: 9999;
position: inherit;
margin-top: 10px;
margin-left: @dimension + 50;
height: 10px;
width: 20px;
border-radius: 0 0 90px 90px;
-moz-border-radius: 0 0 90px 90px;
-webkit-border-radius: 0 0 90px 90px;
border-right: 5px solid #ee3d67;
border-left: 5px solid #ee3d67;
border-bottom: 5px solid #ee3d67;
}
#leg-1 {
display: inline-block;
position: relative;
top: @dimension - 40;
left: 10px;
width: @dimension;
height: @dimension / 5;
background: #162736;
transform: rotate(60deg);
-ms-transform: rotate(60deg); /* IE 9 */
-webkit-transform: rotate(60deg); /* Safari and Chrome */
border-top-right-radius: @dimension / 5;
border-bottom-right-radius: @dimension / 5;
}
#leg-2 {
display: inline-block;
position: relative;
top: @dimension - 40;
left: 10px;
width: @dimension;
height: @dimension / 5;
background: #162736;
transform: rotate(-60deg);
-ms-transform: rotate(-60deg); /* IE 9 */
-webkit-transform: rotate(-60deg); /* Safari and Chrome */
border-top-left-radius: @dimension / 5;
border-bottom-left-radius: @dimension / 5;
}
#star1 {
margin: 50px 0;
position: relative;
left: -100px;
top: -100px;
display: block;
color: #ffd94d;
width: 0px;
height: 0px;
border-right: 100px solid transparent;
border-bottom: 70px solid #ffd94d;
border-left: 100px solid transparent;
transform: rotate(35deg) scale(0.15);
z-index: 5;
animation: starpopup 16s infinite;
}
#star1:before {
border-bottom: 80px solid #ffd94d;
border-left: 30px solid transparent;
border-right: 30px solid transparent;
position: absolute;
height: 0;
width: 0;
top: -45px;
left: -50px;
display: block;
content: "";
transform: rotate(-35deg);
}
#star1:after {
position: absolute;
display: block;
color: #ffd94d;
top: 3px;
left: -105px;
width: 0px;
height: 0px;
border-right: 100px solid transparent;
border-bottom: 70px solid #ffd94d;
border-left: 100px solid transparent;
transform: rotate(-70deg);
content: "";
}
#star2 {
margin: 50px 0;
position: relative;
left: 210px;
top: -220px;
display: block;
color: #ffd94d;
width: 0px;
height: 0px;
border-right: 100px solid transparent;
border-bottom: 70px solid #ffd94d;
border-left: 100px solid transparent;
transform: rotate(35deg) scale(0.15);
z-index: 5;
animation: starpopup 16s infinite;
}
#star2:before {
border-bottom: 80px solid #ffd94d;
border-left: 30px solid transparent;
border-right: 30px solid transparent;
position: absolute;
height: 0;
width: 0;
top: -45px;
left: -65px;
display: block;
content: "";
transform: rotate(-35deg);
}
#star2:after {
position: absolute;
display: block;
color: #ffd94d;
top: 3px;
left: -105px;
width: 0px;
height: 0px;
border-right: 100px solid transparent;
border-bottom: 70px solid #ffd94d;
border-left: 100px solid transparent;
transform: rotate(-70deg);
content: "";
}
#star3 {
margin: 50px 0;
position: relative;
left: 45px;
top: -410px;
display: block;
color: #ffd94d;
width: 0px;
height: 0px;
border-right: 100px solid transparent;
border-bottom: 70px solid #ffd94d;
border-left: 100px solid transparent;
transform: rotate(35deg) scale(0.15);
z-index: 5;
animation: starpopup 16s infinite;
}
#star3:before {
border-bottom: 80px solid #ffd94d;
border-left: 30px solid transparent;
border-right: 30px solid transparent;
position: absolute;
height: 0;
width: 0;
top: -45px;
left: -65px;
display: block;
content: "";
transform: rotate(-35deg);
}
#star3:after {
position: absolute;
display: block;
color: #ffd94d;
top: 3px;
left: -105px;
width: 0px;
height: 0px;
border-right: 100px solid transparent;
border-bottom: 70px solid #ffd94d;
border-left: 100px solid transparent;
transform: rotate(-70deg);
content: "";
}
@keyframes starpopup{
0% {opacity: 0; transform: rotate(35deg) scale(0.1);}
20% {opacity: 0; transform: rotate(235deg) scale(0.1);}
21% {opacity: 1; transform: rotate(-135deg) scale(0.1);}
28% {opacity: 0; transform: rotate(-635deg) scale(0.1);}
55% {opacity: 0; transform: rotate(135deg) scale(0.1);}
70% {opacity: 0; transform: rotate(935deg) scale(0.1);}
71% {opacity: 1; transform: rotate(-135deg) scale(0.1);}
78% {opacity: 0; transform: rotate(-635deg) scale(0.1);}
100% {opacity: 0;transform: rotate(35deg) scale(0.1);}
}
@keyframes robotup {
0% {top: 80%;}
20% {top: 80%;}
25% {top: 43%;}
50% {top: 44%;}
70% {top: 44%;}
75% {top: 80%;}
100% {top: 80%;}
}
@keyframes abduct {
0% {opacity: 0;}
42% {opacity: 0;}
43% {opacity: 0.8; transform: rotateX(75deg) translateY(0px);}
45% { transform: rotateX(75deg) translateY(200px) scale(0.8); opacity: 0.8;}
47% {transform: rotateX(75deg) translateY(0px); opacity: 0.8;}
48% {opacity: 0;}
100% {opacity: 0;}
}
@keyframes abductreverse {
0% {opacity: 0;}
42% {opacity: 0;}
43% { opacity: 0.8; transform: rotateX(75deg) translateY(0px);}
45% {opacity: 0.8; transform: rotateX(75deg) translateY(-100px);}
48% {opacity: 0.8; transform: rotateX(75deg) translateY(0px);}
49% {opacity: 0;}
100% {opacity: 0;}
}
@keyframes moveleft {
0% {left: 350px;}
100% {left: -500px;}
}
@keyframes spaceshipleft {
0% {transform: rotate(-10deg); left: 200%;}
15% {transform: rotate(-10deg);}
30% {left: 45%; transform: rotate(10deg);}
40% {left: 50%; transform: rotate(0deg) translateY(0px);}
45% {left: 50%; transform: rotate(0deg) translateY(-10px);}
50% { left: 50%; transform: rotate(0deg) translateY(0px);}
60% {left: 55%; transform: rotate(-10deg);}
61% {left: 55%;}
100% {left: -100%;}
}
@keyframes bodycolor {
0% {background-image: linear-gradient(to top,#ee3d67,#ef466e,#f04f75,#f1567b,#f25e82);}
20% {background-image: linear-gradient(to top,#ee3d67,#ef466e,#f04f75, #f1567b, #f25e82);}
21% {background-image: linear-gradient(to right top, #ffffff, #f7f2fa, #f4e4f1,#f3d5e4,#f4c6d2);}
70% {background-image: linear-gradient(to right top, #ffffff,#f7f2fa,#f4e4f1,#f3d5e4,#f4c6d2);}
71% {background-image: linear-gradient(to top, #ee3d67, #ef466e, #f04f75, #f1567b, #f25e82);}
100% {background-image: linear-gradient(to top, #ee3d67, #ef466e, #f04f75, #f1567b, #f25e82);}
}
@keyframes abductcolor {
0% {border: 2px solid white;}
20% {border: 2px solid white;}
21% {border: 2px solid #ee3d67;}
70% {border: 2px solid #ee3d67;}
71% {border: 2px solid white;}
100% {border: 2px solid white;}
}
@keyframes colorswap {
0% {background-color: #ee3d67;}
20% {background-color: #ee3d67;}
21% {background-color: #fff;}
70% {background-color: #fff;}
71% {background-color: #ee3d67;}
100% {background-color: #ee3d67;}
}
@keyframes colorswap_middle {
0% {background-color: #fff;}
20% {background-color: #fff;}
21% {background-color: #ee3d67;}
70% {background-color: #ee3d67;}
71% {background-color: #fff;}
100% {background-color: #fff;}
}

The Flying Robot (Pure CSS Drawing/Animation) [codepen challenge]

Pure CSS animation of a robot riding his UFO for the May 2019 codepen challenge

A Pen by Tucker Massad on CodePen.

License.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment