generated from mayacoda/simple-threejs-typescript-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgridjson.ts
116 lines (106 loc) · 3.22 KB
/
gridjson.ts
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
import { promises as fs } from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
let refjson: any[] = []
for (let i = 0; i < 4; i++) {
refjson.push(
await fs.readFile(
path.join(__dirname, 'produced', `r${i + 1}c2.json`),
'utf8'
)
)
}
// let maxjson = await fs.readFile(
// path.join(__dirname, 'produced', 'r4c4.json'),
// 'utf8'
// )
// let minjson = await fs.readFile(
// path.join(__dirname, 'produced', 'r1c1.json'),
// 'utf8'
// )
// let max = JSON.parse(maxjson)
// let min = JSON.parse(minjson)
// function intermediatValues(a: number, b: number, count: number) {
// let result: number[] = []
// for (let i = 0; i < count; i++) {
// result.push(a + ((b - a) * i) / (count - 1))
// }
// return result
// }
// console.log(intermediatValues(1,12,4));
function copyProperties(srcJSON: any, destJSON: any) {
for (let key in srcJSON) {
if (srcJSON.hasOwnProperty(key)) {
destJSON[key] = srcJSON[key]
}
}
}
// let tmpJSON = { ...min}
const petales = [1, 5, 7, 12]
for (let i = 0; i < refjson.length; i++) {
for (let j = 0; j < refjson.length; j++) {
if (j == 1) continue
let tmpJSON = JSON.parse(refjson[i])
tmpJSON.Pétales.controllers.k = petales[j]
tmpJSON.Sépales.controllers.k = petales[j]
let filename = `r${i + 1}c${j + 1}.json`
await fs.writeFile(
path.join(__dirname, 'produced', filename),
JSON.stringify(tmpJSON)
)
}
}
// for (let i = 0; i < petales.length; i++) {
// for (let j = 0; j < petales.length; j++) {
// if (!((i == 0 && j == 0) || (i == 3 && j == 3))) {
// let tmpJSON = { ...min }
// tmpJSON.Pétales.controllers.a = intermediatValues(
// min.Pétales.controllers.a,
// max.Pétales.controllers.a,
// 4
// )[i]
// tmpJSON.Pétales.controllers.b = intermediatValues(
// min.Pétales.controllers.b,
// max.Pétales.controllers.b,
// 4
// )[i]
// tmpJSON.Pétales.controllers.c = intermediatValues(
// min.Pétales.controllers.c,
// max.Pétales.controllers.c,
// 4
// )[i]
// tmpJSON.Pétales.controllers.d = intermediatValues(
// min.Pétales.controllers.d,
// max.Pétales.controllers.d,
// 4
// )[i]
// tmpJSON.Pétales.controllers.k = petales[j]
// tmpJSON.Sépales.controllers.a = intermediatValues(
// min.Sépales.controllers.a,
// max.Sépales.controllers.a,
// 4
// )[i]
// tmpJSON.Sépales.controllers.b = intermediatValues(
// min.Sépales.controllers.b,
// max.Sépales.controllers.b,
// 4
// )[i]
// tmpJSON.Sépales.controllers.c = intermediatValues(
// min.Sépales.controllers.c,
// max.Sépales.controllers.c,
// 4
// )[i]
// tmpJSON.Sépales.controllers.k = petales[j]
// let filename = `r${i + 1}c${j + 1}.json`
// await fs.writeFile(
// path.join(__dirname, 'produced', filename),
// JSON.stringify(tmpJSON)
// )
// }
// }
// }
// // for (let i = 0; i < 4; i++){
// // for (let j = 0; j < 4; j++){
// // }