-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
174 lines (143 loc) · 5.34 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Fluid Simulation</title>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Roboto', sans-serif;
background-color: #f4f4f4;
color: #333;
display: flex;
flex-direction: column;
align-items: center;
padding-top: 20px;
}
#fluidCanvas {
border: 2px solid #005A9C;
margin-top: 20px;
}
.control-panel {
background-color: #ffffff;
padding: 10px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
margin-bottom: 20px;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
gap: 10px;
/* Adjusts space between controls */
}
.control-panel h2 {
font-size: 18px;
/* Smaller title */
color: #005A9C;
flex-basis: 100%;
/* Ensures the title takes full width */
margin: 8px 0;
}
input,
select,
button {
padding: 8px;
border: 1px solid #ccc;
border-radius: 5px;
width: auto;
/* Adjust width or set to auto for smaller controls */
box-sizing: border-box;
font-size: 14px;
/* Smaller font size for text in controls */
}
button {
background-color: #005A9C;
color: white;
cursor: pointer;
}
button:hover {
background-color: #003d73;
}
/* You might need this if controls are too squeezed */
@media (max-width: 600px) {
.control-panel {
flex-direction: column;
}
}
.stats-panel {
background-color: #ffffff;
padding: 10px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
margin-top: 20px;
font-size: 14px;
}
</style>
</head>
<body>
<form id="simulationSettings">
Grid Size: <input type="number" id="size" value="64"><br>
Diffusion: <input type="number" id="diffusion" step="any" value="10"><br>
Viscosity: <input type="number" id="viscosity" step="any" value="0.001"><br>
Time Step: <input type="number" id="dt" step="any" value=".001"><br>
Particle Count: <input type="number" id="particleCount" value="5000"><br>
<button type="button" onclick="startSimulation()">Reset Simulation</button>
<button type="button" id="reinitializeParticles">Reinitialize Particles</button>
<select id="visualizationMode">
<option value="dye">Dye Concentration</option>
<option value="velocity">Velocity Field</option>
<option value="pressure">Pressure Field</option>
<option value="flowLines">Flow Field Lines</option>
<option value="particles">Particles</option>
<option value="particlesAndPressure">Particles and Pressure</option>
<option value="particlesAndPressureAndVelocity" selected>Particles, Pressure, and Velocity</option>
<option value="particlesAndVelocity">Particles and Velocity</option>
<option value="combined">Combined (Dye + Velocity)</option>
</select>
</form>
<canvas id="fluidCanvas"></canvas>
<script src="game.js"></script>
<script>
let game;
function startSimulation ()
{
const size = document.getElementById( "size" ).value;
const diffusion = document.getElementById( "diffusion" ).value;
const viscosity = document.getElementById( "viscosity" ).value;
const dt = document.getElementById( "dt" ).value;
const particleCount = parseInt( document.getElementById( 'particleCount' ).value, 10 );
if ( game )
{
// Clear previous simulation if exists
game.stop();
}
game = new FluidGame( +size, +diffusion, +viscosity, +dt, particleCount );
game.visualizationMode = document.getElementById( "visualizationMode" ).value;
game.start();
}
document.getElementById( 'reinitializeParticles' ).addEventListener( 'click', function ()
{
if ( game )
{
const newParticleCount = parseInt( document.getElementById( 'particleCount' ).value, 10 );
game.particleCount = newParticleCount; // Update the particle count in the game object
game.reinitializeParticles();
game.render();
}
} );
document.getElementById( "visualizationMode" ).addEventListener( "change", function ()
{
if ( game )
{
game.visualizationMode = this.value;
}
} );
startSimulation(); // Start with default values
</script>
<div id="statsPanel" class="stats-panel">
<div>Average Pressure: <span id="avgPressure">0</span></div>
<div>Average Velocity: <span id="avgVelocity">0</span></div>
</div>
</body>
</html>