File size: 10,339 Bytes
76d0fa7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26ede42
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Windows Pipes Screensaver</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <style>
        body {
            margin: 0;
            overflow: hidden;
            background-color: #000;
        }
        
        canvas {
            display: block;
        }
        
        .controls {
            position: absolute;
            bottom: 20px;
            left: 50%;
            transform: translateX(-50%);
            background-color: rgba(0, 0, 0, 0.7);
            padding: 10px 20px;
            border-radius: 8px;
            color: white;
            font-family: Arial, sans-serif;
            display: flex;
            gap: 15px;
            align-items: center;
        }
        
        .controls button {
            background-color: #0078d7;
            color: white;
            border: none;
            padding: 5px 10px;
            border-radius: 4px;
            cursor: pointer;
            transition: background-color 0.3s;
        }
        
        .controls button:hover {
            background-color: #005a9e;
        }
        
        .title {
            position: absolute;
            top: 20px;
            left: 50%;
            transform: translateX(-50%);
            color: white;
            font-family: 'Arial', sans-serif;
            font-size: 24px;
            text-shadow: 0 0 10px rgba(0, 120, 215, 0.7);
            background-color: rgba(0, 0, 0, 0.5);
            padding: 10px 20px;
            border-radius: 8px;
        }
        
        .pipe-count {
            display: flex;
            align-items: center;
            gap: 5px;
        }
        
        input[type="range"] {
            width: 100px;
        }
    </style>
</head>
<body>
    <div class="title">Windows Pipes Screensaver</div>
    <canvas id="pipesCanvas"></canvas>
    <div class="controls">
        <div class="pipe-count">
            <span>Pipe Count:</span>
            <input type="range" id="pipeCount" min="5" max="50" value="15">
            <span id="pipeCountValue">15</span>
        </div>
        <div class="pipe-count">
            <span>Speed:</span>
            <input type="range" id="speedControl" min="1" max="10" value="5">
            <span id="speedValue">5</span>
        </div>
        <button id="colorBtn">Random Colors</button>
        <button id="resetBtn">Reset</button>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', () => {
            const canvas = document.getElementById('pipesCanvas');
            const ctx = canvas.getContext('2d');
            const pipeCountInput = document.getElementById('pipeCount');
            const pipeCountValue = document.getElementById('pipeCountValue');
            const speedControl = document.getElementById('speedControl');
            const speedValue = document.getElementById('speedValue');
            const colorBtn = document.getElementById('colorBtn');
            const resetBtn = document.getElementById('resetBtn');
            
            // Set canvas size
            function resizeCanvas() {
                canvas.width = window.innerWidth;
                canvas.height = window.innerHeight;
            }
            
            resizeCanvas();
            window.addEventListener('resize', resizeCanvas);
            
            // Pipe settings
            let pipeCount = parseInt(pipeCountInput.value);
            let speed = parseInt(speedControl.value);
            let useRandomColors = false;
            let pipes = [];
            const colors = [
                '#0078d7', '#107c10', '#e81123', '#ffb900', 
                '#881798', '#00b7c3', '#ff8c00', '#5c2d91'
            ];
            
            // Pipe class
            class Pipe {
                constructor() {
                    this.reset();
                    this.color = colors[Math.floor(Math.random() * colors.length)];
                }
                
                reset() {
                    this.x = Math.random() * canvas.width;
                    this.y = Math.random() * canvas.height;
                    this.direction = Math.floor(Math.random() * 4); // 0: right, 1: down, 2: left, 3: up
                    this.length = 0;
                    this.maxLength = 50 + Math.random() * 100;
                    this.speed = 2 + Math.random() * 3;
                    this.bendCount = 0;
                    this.maxBends = 2 + Math.floor(Math.random() * 3);
                }
                
                update() {
                    const moveAmount = this.speed * (speed / 5);
                    
                    switch(this.direction) {
                        case 0: // right
                            this.x += moveAmount;
                            break;
                        case 1: // down
                            this.y += moveAmount;
                            break;
                        case 2: // left
                            this.x -= moveAmount;
                            break;
                        case 3: // up
                            this.y -= moveAmount;
                            break;
                    }
                    
                    this.length += moveAmount;
                    
                    // Check if we should bend
                    if (this.length >= this.maxLength && this.bendCount < this.maxBends) {
                        this.length = 0;
                        this.bendCount++;
                        this.maxLength = 50 + Math.random() * 100;
                        
                        // Randomly choose to turn left or right relative to current direction
                        if (Math.random() > 0.5) {
                            this.direction = (this.direction + 1) % 4;
                        } else {
                            this.direction = (this.direction - 1 + 4) % 4;
                        }
                    }
                    
                    // Check if we should reset
                    if (this.x < 0 || this.x > canvas.width || this.y < 0 || this.y > canvas.height || 
                        (this.length >= this.maxLength && this.bendCount >= this.maxBends)) {
                        this.reset();
                    }
                }
                
                draw(ctx) {
                    ctx.strokeStyle = useRandomColors ? 
                        `hsl(${Math.random() * 360}, 100%, 50%)` : this.color;
                    ctx.lineWidth = 8;
                    ctx.lineCap = 'round';
                    
                    ctx.beginPath();
                    
                    // Draw the pipe segment based on direction
                    switch(this.direction) {
                        case 0: // right
                            ctx.moveTo(this.x - this.length, this.y);
                            ctx.lineTo(this.x, this.y);
                            break;
                        case 1: // down
                            ctx.moveTo(this.x, this.y - this.length);
                            ctx.lineTo(this.x, this.y);
                            break;
                        case 2: // left
                            ctx.moveTo(this.x + this.length, this.y);
                            ctx.lineTo(this.x, this.y);
                            break;
                        case 3: // up
                            ctx.moveTo(this.x, this.y + this.length);
                            ctx.lineTo(this.x, this.y);
                            break;
                    }
                    
                    ctx.stroke();
                    
                    // Draw the pipe joint
                    ctx.fillStyle = useRandomColors ? 
                        `hsl(${Math.random() * 360}, 100%, 50%)` : this.color;
                    ctx.beginPath();
                    ctx.arc(this.x, this.y, 5, 0, Math.PI * 2);
                    ctx.fill();
                }
            }
            
            // Initialize pipes
            function initPipes() {
                pipes = [];
                for (let i = 0; i < pipeCount; i++) {
                    pipes.push(new Pipe());
                }
            }
            
            initPipes();
            
            // Animation loop
            function animate() {
                ctx.fillStyle = 'rgba(0, 0, 0, 0.1)';
                ctx.fillRect(0, 0, canvas.width, canvas.height);
                
                for (let pipe of pipes) {
                    pipe.update();
                    pipe.draw(ctx);
                }
                
                requestAnimationFrame(animate);
            }
            
            animate();
            
            // Event listeners
            pipeCountInput.addEventListener('input', () => {
                pipeCount = parseInt(pipeCountInput.value);
                pipeCountValue.textContent = pipeCount;
                initPipes();
            });
            
            speedControl.addEventListener('input', () => {
                speed = parseInt(speedControl.value);
                speedValue.textContent = speed;
            });
            
            colorBtn.addEventListener('click', () => {
                useRandomColors = !useRandomColors;
                colorBtn.textContent = useRandomColors ? 'Solid Colors' : 'Random Colors';
            });
            
            resetBtn.addEventListener('click', () => {
                initPipes();
            });
            
            // Mouse movement to reset position (like a real screensaver)
            let mouseX = 0;
            let mouseY = 0;
            let lastMouseMove = Date.now();
            
            document.addEventListener('mousemove', (e) => {
                mouseX = e.clientX;
                mouseY = e.clientY;
                lastMouseMove = Date.now();
                
                // If mouse is moved, reset all pipes
                if (Date.now() - lastMouseMove < 100) {
                    for (let pipe of pipes) {
                        pipe.reset();
                    }
                }
            });
        });
    </script>
</body>
</html>