-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
206 lines (180 loc) · 6.57 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home Page</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://kit.fontawesome.com/b71972c7cc.js" crossorigin="anonymous"></script>
<style>
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono&display=swap');
:root{
font-family: 'JetBrains Mono', monospace;
font-size: 16px;
--background-color: #252323;
--accent-color: #F45D01;
--secondary-color: #188EDC;
--button-color: var(--accent-color);
--button-shadow-color: rgba(0, 0, 0, 0.1);
--font-color: #D6D6B1;
--dark-font-color: var(--background-color);
--panel-color: #423F3F;
}
body{
background-color: var(--background-color);
padding-top: 2rem;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.CodeMirror{
font-size: 13px;
font-family: 'JetBrains Mono', monospace;
height: 80vh;
}
.CodeMirror-scroll {
overflow-y: scroll;
overflow-x: auto;
}
button{
transition: all ease-in-out 0.1s;
}
button:hover{
transform: translate(0,-0.3rem);
box-shadow: 0 0.5rem 1rem var(--button-shadow-color);
}
button:active{
transform: translate(0,0rem);
}
select{
outline: none;
transition: all ease-in-out 0.3s;
}
</style>
</head>
<body>
<!-- <div class=" -->
<!-- fixed bottom-0 right-0 -->
<!-- p-2 -->
<!-- "> -->
<!-- <p style="font-family: 'JetBrains Mono'" -->
<!-- class=" -->
<!-- text-sm text-white -->
<!-- ">Developed by Sokmontrey Sythat. -->
<!-- <a target="_blank" href="https://github.com/sokmontrey/dynamical-js" -->
<!-- class="text-blue-400 underline">GitHub</a> -->
<!-- </p> -->
<!-- </div> -->
<div class="
flex flex-col
justify-center items-center
h-[100vh]
">
<p class="
text-[var(--font-color)]
text-4xl font-bold
">
Dynamical JS
</p>
<canvas id="canvas"></canvas>
</div>
<div class="
w-[100%] h-[50vh]
bg-[var(--secondary-color)] text-[var(--font-color)]
p-10
">
<div class="
flex justify-start items-center
">
<p class="
text-4xl font-bold
">
By Sokmontrey
</p>
<a href='./example/example.html'><button class="
bg-[var(--font-color)] text-[var(--dark-font-color)]
px-6 py-3
mt-2 ml-7
rounded font-bold
">
See Examples
</button></a>
<a target="_blank" href='https://github.com/sokmontrey/dynamical-js'>
<button class="
bg-[var(--secondary-color)] text-[var(--font-color)]
px-6 py-3
mt-2 ml-5
rounded font-bold
">
<i class="fa-brands fa-github"></i>
GitHub
</button></a>
</div>
<p class="
py-5
">Dynamical JS is a 2D physic engine written from scratch in JavaScript.</p>
</div>
<script type="module">
import { Vector } from './src/util/dynamical_vector.js';
import Renderer from './src/util/renderer.js';
import PointMass from './src/dynamical/point_mass.js';
import Constraint, {DistanceConstraint} from './src/dynamical/constraint.js';
const canvas = document.getElementById('canvas');
const renderer = new Renderer(canvas);
renderer.setBackground('#252323');
const c = renderer.context;
const g = c.createLinearGradient(0,500,0,0);
g.addColorStop(0, "rgba(255,255,255,0.5)");
g.addColorStop(1, "rgba(46, 52, 64, 0.01)");
const word1 = "A Physic";
const word2 = "Engine";
c.font = "1.7rem 'JetBrains Mono'";
const text_width = c.measureText(word1).width;
const text_width2 = c.measureText(word2).width;
const points = [
PointMass.create(200, 150),
PointMass.create(200 + text_width, 150),
PointMass.create(200 + text_width + 100, 150)
];
const connections = [
new DistanceConstraint(points[0], points[1]),
new DistanceConstraint(points[1], points[2])
];
connections[1].graphic.stroke_width = 3;
const container = Constraint.create('circle_container')
.setRadius(200)
.setOffset(new Vector(50, -50))
.setFrictionConstant(0.0);
renderer.update((delta_time)=>{
renderer.clear();
renderer.circle(container._center,container._radius).setFillStyle(g).fill();
for(let each of points){
each.applyGravity(new Vector(0, 9.8));
}
for(let i=0; i<3; i++){
for(let each of points){
each.updatePosition(delta_time*0.55);
}
for(let each of connections){
each.check();
}
container.check(points[0]);
container.check(points[1]);
}
renderer.draw(connections[1])
renderer.circle(points[1].position, 5).setFillStyle('gray').fill();
renderer.circle(points[2].position, 5).fill();
renderer.setFillStyle('white');
const angle = Math.atan2(points[1].position.y - points[0].position.y, points[1].position.x - points[0].position.x);
c.translate(points[0].position.x, points[0].position.y);
c.rotate(angle);
c.fillText(word1, 0, 0);
c.setTransform(1, 0, 0, 1, 0, 0);
renderer.setFillStyle('#F45D01');
c.fillText(word2, points[2].position.x - text_width2/2, points[2].position.y + text_width2/4);
});
</script>
</body>
</html>