I'm interested in developing an algorithm that can replicate values for a specific object schema, as shown in the sample data below:
let layer1 = {name: 'x',
values: [{_color: '#996666', time: 0, tween: 'quadEaseIn', value: 0},
{_color: '#b074a0', time: 4, value: 5.500023},
{_color: '#b074a0', time: 3, value: 4.500023},
{_color: '#b074a0', time: 2, value: 3.500023}],
tmpValue: 3.500023,
_color: '#6ee167',
_value: 0};
The 3rd, 4th, and 5th lines of this sample data are crucial to solving this problem.
Here is what the algorithm looks like so far. The variable numKeyframes has already been defined (n). In the first loop, dynamic objects are added to an array called keyframes.
In the second loop, the keyframes array is included within the layer object. The goal here is for keyframes to insert multiple objects in place of the existing object (similar to the sample object data provided above).
...
var keyframes = [];
var timevals = [1, 2, 3, 4, 5]
for (var k=0; k<numKeyframes; k++) {
var tv = timevals[k];
var kf = {_color: '#FF0000', time: tv, value: 3.500023}
keyframes.push(kf);
}
// creating x, y, z layers
for (var i=0; i<3; i++) {
layer = {name: layerNames[i],
values: [{_color: layerValuesColors[i],
time: layerValuesTime[i],
tween: 'quadEaseIn',
value: layerValuesValues[i]},
keyframes],
tmpValue: layertmpValues[i],
_color: layerColors2[i],
_value: layerValues[i]}
layerData.push(layer);
}
...
However, this approach does not seem to be working as intended. It appears that no objects are being included.
If I replace `keyframes]` with `keyframes[0]]`, it works but only retrieves the first value (object) instead of inserting all values (objects).
What would be the most effective way to address this issue?