-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
337 lines (287 loc) · 6.94 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
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
<!DOCTYPE html>
<html lang="en">
<html>
<head>
<title></title>
<meta charset="UTF-8" />
<style>
/* ensure the content fills the available page without borders */
* { margin: 0px; }
</style>
</head>
<body>
<script type="module">
import { showArtwork, scene } from './webxrp5.js';
/*
See documentation at https://github.com/worldmaking/WebXR_P5js_eCampus21/blob/main/README.md
WebXR_P5js is a template for embedding P5.js sketches inside a Three.js WebXR-ready scene for VR and desktop display.
WebXR_P5js_eCampus21 by Haru Ji and Graham Wakefield and is licensed under the GNU General Public License v3.0, except where otherwise noted.
This project is made possible with funding by the Government of Ontario and through eCampusOntario’s support of the Virtual Learning Strategy.
To learn more about the Virtual Learning Strategy visit: https://vls.ecampusontario.ca.
*/
// First label
let label0 = `
WebXR Sketch 101
Haru Ji, 2021, Jungle, p5.js
This is a prototyping WebXR
exhibition & critique space for
Digital Atelier 1: Discovery,
Experiment 2 Endless Forms Most Beautiful.
`;
let code0 = `
let w = width, h = height;
let num = 25; // number of circles
let points = [];
for (let i=0; i<num; i++){
points[i] = {
x: random(w), // circle x position
y: random(h), // circle y position
r: random(20, 40), // circle size
vx: 1, // velocity x directin
vy: random(-1, 1), // velocity y direction
c: 1555, // color initial tone
}
}
function draw () {
background(180, 2); //background gray tone, transparency
for (let i=0; i<num; i++){
let p = points[i];
p.x += p.vx;
p.y += p.vy;
p.vy += 0.03; // gravity
for (let j=i+1; j<num; j++){
let n = points[j];
stroke((p.y+100)%(n.c*2), ((p.y+n.y)-p.c)%155, (n.y-n.c)%255);
strokeWeight(p.r%2);
//line(p.x, p.y, n.x, n.y);
let d = dist(p.x, p.y, n.x, n.y);
let cs = p.r + n.r;
if (d<=cs) {
p.vx *= -1;
p.vy *= -1;
n.vx *= -1;
n.vy *= -1;
p.r = max(min(abs(n.r + random(-10, 10)), 300), 5);
n.r = max(min(abs(p.r + random(-10, 10)), 300), 5);
p.c = random(255);
n.c = random(255);
}
}
if (p.x<=p.r){
p.x = p.r;
p.vx = abs(p.vx);
} else if (p.x>=(w-p.r)){
p.x = w-p.r;
p.vx = -abs(p.vx);
}
if (p.y<p.r) {
p.y = p.r;
p.vy = abs(p.vy);
} else if (p.y>=(h-p.r)){
p.y = h-p.r;
p.vy = -abs(p.vy);
}
strokeWeight(p.r%15);
//fill(p.y+5%5 + p.c, p.x+3%5-p.c, p.x+15%15-p.c, 100);
fill((p.c)%255, (255-p.c), (255-p.c+155));
stroke((p.y+p.c)%255, (p.y-p.c)%155, p.c%155);
ellipse(p.x, p.y, p.r*2);
}
}
`;
let group0 = showArtwork({
width: 8,
height: 4,
code: code0,
label: label0,
});
group0.position.set(0, 0, -4);
console.log(
group0.children[0].userData.sketch.sketch.elt.dispatchEvent(
new MouseEvent('click')
)
);
let label1 = `
WebXR Sketch 102
Haru Ji, 2021
This is a prototyping WebXR
exhibition & critique space for
Digital Atelier 1: Discovery,
Experiment 2 Endless Forms Most Beautiful.
`;
let code1 = `
let w = width, h = height;
let num = 100;
let points = [];
for (let i=0; i<num; i++){
points[i] = {
x: random(w),
y: random(h),
r: random(50, 100),
vx: 5,
vy: random(-10, 10),
c: random(1),
}
}
function draw () {
background(55, 5);
for (let i=0; i<num; i++){
let p = points[i];
p.x += p.vx;
p.y += p.vy;
p.vy += 0.03;
for (let j=i+1; j<num; j++){
let n = points[j];
// stroke(p.y+5%55, p.x+3%55, p.x+55%255, 55);
// strokeWeight(p.x%2);
// // line(p.x, p.y, n.x, n.y);
let d = dist(p.x, p.y, n.x, n.y);
let cs = p.r/2 + n.r/2;
if (d<cs) {
p.vx *= -1;
p.vy *= -1;
n.vx *= -1;
n.vy *= -1;
p.r = abs(p.r + random(-20, 19));
p.c *= -1;
}
}
if (p.x < p.r/2) {
p.x = p.r/2;
p.vx = abs(p.vx);
} else if (p.x+p.r/2 > w){
p.x = w-p.r/2;
p.vx = -abs(p.vx);
}
if (p.y < p.r/2) {
p.y = p.r/2;
p.vy = abs(p.vy);
} else if (p.y+p.r/2 > h){
p.y = h-p.r/2;
p.vy = -abs(p.vy);
}
if (p.r>h){
p.r -= 10;
}
fill((p.c*55+255)%255, p.c*55+p.y%25+5, p.c*55+p.x%55+55);
//ellipse(p.x, p.y, p.r);
square(p.x, p.y, p.r, p.r/5);
}
}
`;
let group1 = showArtwork({
width: 1,
height: 1,
depth: 1,
code: code1,
label: label1,
update: function (artwork) {
artwork.rotation.y += 0.01;
artwork.rotation.x += 0.003;
},
});
group1.position.set(3.5, 0, 0);
group1.rotation.y = -Math.PI / 2;
let label2 = `
WebXR Sketch 103: Game of Life
Haru Ji, 2021
This is a prototyping WebXR
exhibition & critique space for
Digital Atelier 1: Discovery,
Experiment 2 Endless Forms Most Beautiful.
`;
let code2 = `
let w = width, h = height;
let cn = 64;
let cx = w/cn;
let cy = h/cn;
let cells = [];
let newCells = [];
for (let i=0; i<cn; i++){
cells[i] = [];
newCells[i] = [];
for (let j=0; j<cn; j++){
let c = random(1);
fill(c * 255);
cells[i][j] = c;
rect(i*cx, j*cy, cx, cy);
}
}
function draw () {
background(0, 15);
for (let i=0; i<cn; i++){
for (let j=0; j<cn; j++){
if (i==0 || i==cn-1 || j==0 || j==cn-1){
newCells[i][j] = int(random(2));
} else {
// neighbor numbers
let s = cells[i][j+1];
let n = cells[i][j-1];
let w = cells[i-1][j];
let e = cells[i+1][j];
let sw = cells[i-1][j+1];
let se = cells[i+1][j+1];
let nw = cells[i-1][j-1];
let ne = cells[i+1][j-1];
let sum = s+n+w+e+sw+se+nw+ne;
if (cells[i][j]){
if (sum<2 || sum>3){
newCells[i][j] = 0;
} else {
newCells[i][j] = 1;
}
}
if (cells[i][j]==0){
if (sum==3){
newCells[i][j] = 1;
} else {
newCells[i][j] = 0;
}
}
}
}
}
for (let i=0; i<cn; i++){
for (let j=0; j<cn; j++){
let c = newCells[i][j];
fill(c * 255 + 35, c * 155 + 15, c * 55 + 15, 55);
rect(i*cx, j*cy, cx, cy);
cells[i][j] = c;
}
}
}//draw function
`;
let group2 = showArtwork({
width: 3,
height: 3,
code: code2,
label: label2,
});
group2.position.set(0, 0, 4);
group2.rotation.y = Math.PI;
let label3 = `
WebXR Image 104
Digital Atelier: Endless Forms Most Beautiful
Credit, right to left, top: 1, Donato Liotino,
2. Natalie Le Huenen 3. Mahnoor Shahid,
bottom: 4. Tania Samokhvalova, 5. Natalie Le Huenen,
6. Anran Zhou (DF Undergraduate students
from OCAD University)
This is how to show an image from a remote URL.
This is a prototyping WebXR
exhibition & critique space for eCampus.
Digital Atelier 1: Discovery,
Experiment 2
`;
let group3 = showArtwork({
width: 3,
height: 2,
image: './assets/atelier.jpg',
label: label3,
});
group3.position.set(-4, 0, 0);
group3.rotation.y = Math.PI / 2;
</script>
</body>
</html>
</html>