Penguin
Il Progetto
Pinguino animato e interattivo sviluppato con CSS Transforms, creando un personaggio completo con animazioni, interazioni e un paesaggio antartico. L’ultimo progetto guidato prima del portfolio finale.
Codice Sorgente
- index.html
- styles.css
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Penguin</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="left-mountain"></div>
<div class="back-mountain"></div>
<div class="sun"></div>
<div class="penguin">
<div class="penguin-head">
<div class="face left"></div>
<div class="face right"></div>
<div class="chin"></div>
<div class="eye left">
<div class="eye-lid"></div>
</div>
<div class="eye right">
<div class="eye-lid"></div>
</div>
<div class="blush left"></div>
<div class="blush right"></div>
<div class="beak top"></div>
<div class="beak bottom"></div>
</div>
<div class="shirt">
<div>💜</div>
<p>I CSS</p>
</div>
<div class="penguin-body">
<div class="arm left"></div>
<div class="arm right"></div>
<div class="foot left"></div>
<div class="foot right"></div>
</div>
</div>
<div class="ground"></div>
</body>
</html>
:root {
--penguin-face: white;
--penguin-picorna: orange;
--penguin-skin: gray;
}
body {
background: linear-gradient(45deg, rgb(118, 201, 255), rgb(247, 255, 222));
margin: 0;
padding: 0;
width: 100%;
height: 100vh;
overflow: hidden;
}
.left-mountain {
width: 300px;
height: 300px;
background: linear-gradient(rgb(203, 241, 228), rgb(80, 183, 255));
position: absolute;
transform: skew(0deg, 44deg);
z-index: 2;
margin-top: 100px;
}
.back-mountain {
width: 300px;
height: 300px;
background: linear-gradient(rgb(203, 241, 228), rgb(47, 170, 255));
position: absolute;
z-index: 1;
transform: rotate(45deg);
left: 110px;
top: 225px;
}
.sun {
width: 200px;
height: 200px;
background-color: yellow;
position: absolute;
border-radius: 50%;
top: -75px;
right: -75px;
}
.penguin {
width: 300px;
height: 300px;
margin: auto;
margin-top: 75px;
z-index: 4;
position: relative;
transition: transform 1s ease-in-out 0ms;
}
.penguin * {
position: absolute;
}
.penguin:active {
transform: scale(1.5);
cursor: not-allowed;
}
.penguin-head {
width: 50%;
height: 45%;
background: linear-gradient(
45deg,
var(--penguin-skin),
rgb(239, 240, 228)
);
border-radius: 70% 70% 65% 65%;
top: 10%;
left: 25%;
z-index: 1;
}
.face {
width: 60%;
height: 70%;
background-color: var(--penguin-face);
border-radius: 70% 70% 60% 60%;
top: 15%;
}
.face.left {
left: 5%;
}
.face.right {
right: 5%;
}
.chin {
width: 90%;
height: 70%;
background-color: var(--penguin-face);
top: 25%;
left: 5%;
border-radius: 70% 70% 100% 100%;
}
.eye {
width: 15%;
height: 17%;
background-color: black;
top: 45%;
border-radius: 50%;
}
.eye.left {
left: 25%;
}
.eye.right {
right: 25%;
}
.eye-lid {
width: 150%;
height: 100%;
background-color: var(--penguin-face);
top: 25%;
left: -23%;
border-radius: 50%;
}
.blush {
width: 15%;
height: 10%;
background-color: pink;
top: 65%;
border-radius: 50%;
}
.blush.left {
left: 15%;
}
.blush.right {
right: 15%;
}
.beak {
height: 10%;
background-color: var(--penguin-picorna);
border-radius: 50%;
}
.beak.top {
width: 20%;
top: 60%;
left: 40%;
}
.beak.bottom {
width: 16%;
top: 65%;
left: 42%;
}
.shirt {
font: bold 25px Helvetica, sans-serif;
top: 165px;
left: 127.5px;
z-index: 1;
color: #6a6969;
}
.shirt div {
font-weight: initial;
top: 22.5px;
left: 12px;
}
.penguin-body {
width: 53%;
height: 45%;
background: linear-gradient(
45deg,
rgb(134, 133, 133) 0%,
rgb(234, 231, 231) 25%,
white 67%
);
border-radius: 80% 80% 100% 100%;
top: 40%;
left: 23.5%;
}
.penguin-body::before {
content: "";
position: absolute;
width: 50%;
height: 45%;
background-color: var(--penguin-skin);
top: 10%;
left: 25%;
border-radius: 0% 0% 100% 100%;
opacity: 70%;
}
.arm {
width: 30%;
height: 60%;
background: linear-gradient(
90deg,
var(--penguin-skin),
rgb(209, 210, 199)
);
border-radius: 30% 30% 30% 120%;
z-index: -1;
}
.arm.left {
top: 35%;
left: 5%;
transform-origin: top left;
transform: rotate(130deg) scaleX(-1);
animation: 3s linear infinite wave;
}
.arm.right {
top: 0%;
right: -5%;
transform: rotate(-45deg);
}
@keyframes wave {
10% {
transform: rotate(110deg) scaleX(-1);
}
20% {
transform: rotate(130deg) scaleX(-1);
}
30% {
transform: rotate(110deg) scaleX(-1);
}
40% {
transform: rotate(130deg) scaleX(-1);
}
}
.foot {
width: 15%;
height: 30%;
background-color: var(--penguin-picorna);
top: 85%;
border-radius: 50%;
z-index: -1;
}
.foot.left {
left: 25%;
transform: rotate(80deg);
}
.foot.right {
right: 25%;
transform: rotate(-80deg);
}
.ground {
width: 100vw;
height: calc(100vh - 300px);
background: linear-gradient(90deg, rgb(88, 175, 236), rgb(182, 255, 255));
z-index: 3;
position: absolute;
margin-top: -58px;
}
La sensazione di “ripasso totale”
In diversi momenti di questo progetto ho pensato che fosse orientato a un ripasso totale. freeCodeCamp è stato concepito con questa logica, ma in quest’ultimo progetto, forse perché è l’ultimo guidato prima di concludere il corso, ho percepito questa sensazione in modo ancora più forte.
È come una “greatest hits” di tutto ciò che ho imparato finora: CSS Variables, transforms, animations, positioning, gradienti, pseudo-elementi, selettori avanzati… tutto concentrato in un progetto adorabile!
La scoperta dei cursori CSS
Mi è piaciuta moltissimo la parte in cui ho imparato cursor: not-allowed, e ho voluto approfondire per scoprire gli altri. Questo è ciò che ho trovato:
cursor: pointer; /* 👆 Mano (cliccabile) */
cursor: grab; /* ✋ Mano aperta (trascinabile) */
cursor: grabbing; /* ✊ Mano chiusa (drag in corso) */
cursor: not-allowed; /* 🚫 Accesso negato */
cursor: wait; /* ⏳ Clessidra (attendi) */
cursor: help; /* ❓ Punto interrogativo */
cursor: text; /* 📝 Cursore di testo */
L’impatto UX dei cursori: ogni cursore comunica immediatamente un’affordance all’utente. pointer dice “puoi cliccare”, grab suggerisce “puoi trascinare”, wait informa che “il sistema sta elaborando”, not-allowed previene la frustrazione mostrando chiaramente i limiti. Sono micro-interazioni che rendono l’interfaccia più intuitiva.
Cosa Ho Imparato
CSS Transforms avanzati:
- transform-origin per punti di rotazione personalizzati
- scaleX(-1) per ribaltare elementi orizzontalmente
- Combinazioni complesse di rotate + scale
- transform sugli stati interattivi (
:active)
Animazioni sofisticate:
- @keyframes con timing preciso
- animation con linear, infinite e durate personalizzate
- Animazioni di saluto che si ripetono all’infinito
CSS Variables in azione:
- Design system per i colori del pinguino
- Coerenza cromatica in tutto il progetto
- Modifica globale semplificata
Pseudo-elementi creativi:
- ::before per creare forme aggiuntive
- Layering con z-index per dare profondità
- Opacity per effetti di overlay
Layout creativo:
- Positioning assoluto per precisione millimetrica
- Border-radius complessi per forme organiche
- Gradienti lineari per sfumature realistiche
L’energia per il progetto finale
Sono super carico per il progetto finale, ovvero il Personal Portfolio Webpage Certification Project!
Ora è il momento di mettere tutto insieme in un portfolio che racconti questo incredibile percorso.
Prossimo progetto: Personal Portfolio Webpage (CERTIFICATION PROJECT!)