CODE TO CREATE A FAN

<!DOCTYPE html>
<html lang=”en”>
<head>
    <meta charset=”UTF-8″>
    <meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
    <title>Electric Fan Control</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background: linear-gradient(to bottom right, #3a7bd5, #00d2ff);
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            color: #fff;
        }
        .fan-container {
            background: #222;
            padding: 20px;
            border-radius: 20px;
            text-align: center;
            box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
        }
        .fan {
            width: 150px;
            height: 150px;
            border: 10px solid #555;
            border-radius: 50%;
            margin: 0 auto 20px auto;
            position: relative;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
        }
        .blade {
            width: 60px;
            height: 20px;
            background: #ff4757;
            border-radius: 10px;
            position: absolute;
            top: 50%;
            left: 50%;
            transform-origin: 50% 50%;
            transform: translate(-50%, -50%);
        }
        .blade:nth-child(1) { transform: translate(-50%, -50%) rotate(0deg); }
        .blade:nth-child(2) { transform: translate(-50%, -50%) rotate(120deg); }
        .blade:nth-child(3) { transform: translate(-50%, -50%) rotate(240deg); }
        .controls {
            display: flex;
            flex-direction: column;
            gap: 15px;
        }
        .indicator {
            font-size: 18px;
            margin-bottom: 10px;
        }
        .speed-buttons, .onoff-switch {
            display: flex;
            justify-content: center;
            gap: 10px;
        }
        .button {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            border: none;
            background: #00a8ff;
            color: #fff;
            font-size: 18px;
            cursor: pointer;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
            transition: background 0.3s;
        }
        .button:active {
            background: #0097e6;
        }
        .onoff-button {
            background: #ff4757;
            width: 60px;
        }
        .onoff-button.on {
            background: #2ed573;
        }
    </style>
</head>
<body>
    <div class=”fan-container”>
        <div class=”fan”>
            <div class=”blade” id=”blade1″></div>
            <div class=”blade” id=”blade2″></div>
            <div class=”blade” id=”blade3″></div>
        </div>
        <div class=”controls”>
            <div class=”indicator” id=”speed-indicator”>Speed: 0</div>
            <div class=”speed-buttons”>
                <button class=”button” onclick=”setSpeed(1)”>1</button>
                <button class=”button” onclick=”setSpeed(2)”>2</button>
                <button class=”button” onclick=”setSpeed(3)”>3</button>
                <button class=”button” onclick=”setSpeed(4)”>4</button>
                <button class=”button” onclick=”setSpeed(5)”>5</button>
            </div>
            <div class=”onoff-switch”>
                <button class=”button onoff-button” id=”onoff-button” onclick=”toggleFan()”>Off</button>
            </div>
        </div>
    </div>
    <script>
        let fanOn = false;
        let currentSpeed = 0;
        let fanInterval;
        function setSpeed(speed) {
            if (fanOn) {
                currentSpeed = speed;
                document.getElementById(‘speed-indicator’).textContent = ‘Speed: ‘ + speed;
                adjustFanSpeed();
            }
        }
        function toggleFan() {
            fanOn = !fanOn;
            document.getElementById(‘onoff-button’).textContent = fanOn ? ‘On’ : ‘Off’;
            document.getElementById(‘onoff-button’).classList.toggle(‘on’, fanOn);
            if (fanOn) {
                adjustFanSpeed();
            } else {
                stopFan();
            }
        }
        function adjustFanSpeed() {
            stopFan();
            const rotationSpeed = 1000 / currentSpeed;
            fanInterval = setInterval(() => {
                document.getElementById(‘blade1’).style.transform += ‘rotate(120deg)’;
                document.getElementById(‘blade2’).style.transform += ‘rotate(120deg)’;
                document.getElementById(‘blade3’).style.transform += ‘rotate(120deg)’;
            }, rotationSpeed);
        }
        function stopFan() {
            clearInterval(fanInterval);
            document.getElementById(‘speed-indicator’).textContent = ‘Speed: 0’;
        }
    </script>
</body>
</html>

Leave a Reply

Your email address will not be published. Required fields are marked *

Resize text
Scroll to Top