@@ -68,6 +68,25 @@ static ExpContent* _expcontent(LottieExpression* exp, float frameNo, LottieObjec
68
68
}
69
69
70
70
71
+ static float _rand ()
72
+ {
73
+ return (float )(rand () % 10000001 ) * 0 .0000001f ;
74
+ }
75
+
76
+
77
+ static jerry_value_t _point2d (const Point & pt)
78
+ {
79
+ auto obj = jerry_object ();
80
+ auto v1 = jerry_number (pt.x );
81
+ auto v2 = jerry_number (pt.y );
82
+ jerry_object_set_index (obj, 0 , v1);
83
+ jerry_object_set_index (obj, 1 , v2);
84
+ jerry_value_free (v1);
85
+ jerry_value_free (v2);
86
+ return obj;
87
+ }
88
+
89
+
71
90
static void contentFree (void *native_p, struct jerry_object_native_info_t *info_p)
72
91
{
73
92
free (native_p);
@@ -603,8 +622,7 @@ static jerry_value_t _length(const jerry_call_info_t* info, const jerry_value_t
603
622
604
623
static jerry_value_t _random (const jerry_call_info_t * info, const jerry_value_t args[], const jerry_length_t argsCnt)
605
624
{
606
- auto val = (float )(rand () % 10000001 );
607
- return jerry_number (val * 0 .0000001f );
625
+ return jerry_number (_rand ());
608
626
}
609
627
610
628
@@ -821,6 +839,32 @@ static jerry_value_t _speedAtTime(const jerry_call_info_t* info, const jerry_val
821
839
}
822
840
823
841
842
+
843
+ static jerry_value_t _wiggle (const jerry_call_info_t * info, const jerry_value_t args[], const jerry_length_t argsCnt)
844
+ {
845
+ auto data = static_cast <ExpContent*>(jerry_object_get_native_ptr (info->function , &freeCb));
846
+ auto freq = jerry_value_as_number (args[0 ]);
847
+ auto amp = jerry_value_as_number (args[1 ]);
848
+ auto octaves = (argsCnt > 2 ) ? jerry_value_as_int32 (args[2 ]) : 1 ;
849
+ auto ampm = (argsCnt > 3 ) ? jerry_value_as_number (args[3 ]) : 5 .0f ;
850
+ auto time = (argsCnt > 4 ) ? jerry_value_as_number (args[4 ]) : data->exp ->comp ->timeAtFrame (data->frameNo );
851
+
852
+ Point result = {100 .0f , 100 .0f };
853
+
854
+ for (int o = 0 ; o < octaves; ++o) {
855
+ auto repeat = int (time * freq);
856
+ auto frac = (time * freq - float (repeat)) * 1 .25f ;
857
+ for (int i = 0 ; i < repeat; ++i) {
858
+ result.x += (_rand () * 2 .0f - 1 .0f ) * amp * frac;
859
+ result.y += (_rand () * 2 .0f - 1 .0f ) * amp * frac;
860
+ }
861
+ freq *= 2 .0f ;
862
+ amp *= ampm;
863
+ }
864
+ return _point2d (result);
865
+ }
866
+
867
+
824
868
static bool _loopOutCommon (LottieExpression* exp, const jerry_value_t args[], const jerry_length_t argsCnt)
825
869
{
826
870
exp ->loop .mode = LottieExpression::LoopMode::OutCycle;
@@ -1044,7 +1088,11 @@ static void _buildProperty(float frameNo, jerry_value_t context, LottieExpressio
1044
1088
jerry_object_set_native_ptr (speedAtTime, nullptr , exp );
1045
1089
jerry_value_free (speedAtTime);
1046
1090
1047
- // wiggle(freq, amp, octaves=1, amp_mult=.5, t=time)
1091
+ auto wiggle = jerry_function_external (_wiggle);
1092
+ jerry_object_set_sz (context, " wiggle" , wiggle);
1093
+ jerry_object_set_native_ptr (wiggle, &freeCb, _expcontent (exp , frameNo, exp ->object ));
1094
+ jerry_value_free (wiggle);
1095
+
1048
1096
// temporalWiggle(freq, amp, octaves=1, amp_mult=.5, t=time)
1049
1097
// smooth(width=.2, samples=5, t=time)
1050
1098
0 commit comments