8000 Merge pull request #29 from TinyCircuits/tween-start-none · TinyCircuits/micropython@e14db00 · GitHub
[go: up one dir, main page]

Skip to content

Commit e14db00

Browse files
authored
Merge pull request micropython#29 from TinyCircuits/tween-start-none
Allow passing None as the start value for Tween.start, to denote the current value of the tweened attribute.
2 parents 68f815b + 6c349f9 commit e14db00

File tree

4 files changed

+33
-28
lines changed

4 files changed

+33
-28
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
filesystem/last_crash.txt
2-
doc/build
2+
doc/build
3+
.vscode

filesystem/system/launcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def on_just_focused(self):
155155
self.title_text_node.opacity = 1.0
156156

157157
camera_tween.stop()
158-
camera_tween.start(camera, "position", camera.position, Vector3(self.position.x, self.position.y, camera.position.z), 250.0, 1.0, ONE_SHOT, EASE_BACK_OUT)
158+
camera_tween.start(camera, "position", None, Vector3(self.position.x, self.position.y, camera.position.z), 250.0, 1.0, ONE_SHOT, EASE_BACK_OUT)
159159

160160
def on_just_unfocused(self):
161161
self.set_opacity(0.65)

filesystem/system/splash.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,17 @@ def __init__(self):
6161

6262

6363
def after(self):
64-
self.T_tween.start(self.T_sprite, "position", self.T_sprite.position, Vector2(-53, 0), random.uniform(2000.0, 2400.0), 1.0, ONE_SHOT, EASE_ELAST_OUT)
65-
self.h_tween.start(self.h_sprite, "position", self.h_sprite.position, Vector2(-44, 0), random.uniform(2000.0, 2400.0), 1.0, ONE_SHOT, EASE_ELAST_OUT)
66-
self.u_tween.start(self.u_sprite, "position", self.u_sprite.position, Vector2(-34, 2), random.uniform(2000.0, 2400.0), 1.0, ONE_SHOT, EASE_ELAST_OUT)
67-
self.m_tween.start(self.m_sprite, "position", self.m_sprite.position, Vector2(-24, 2), random.uniform(2000.0, 2400.0), 1.0, ONE_SHOT, EASE_ELAST_OUT)
68-
self.b_tween.start(self.b_sprite, "position", self.b_sprite.position, Vector2(-13, 0), random.uniform(2000.0, 2400.0), 1.0, ONE_SHOT, EASE_ELAST_OUT)
69-
self.y_tween.start(self.y_sprite, "position", self.y_sprite.position, Vector2(-4, 4), random.uniform(2000.0, 2400.0), 1.0, ONE_SHOT, EASE_ELAST_OUT)
70-
self.C_tween.sta 8000 rt(self.C_sprite, "position", self.C_sprite.position, Vector2(10, 0), random.uniform(2000.0, 2400.0), 1.0, ONE_SHOT, EASE_ELAST_OUT)
71-
self.GO_tween.start(self.GO_sprite, "position", self.GO_sprite.position, Vector2(21, 0), random.uniform(2000.0, 2400.0), 1.0, ONE_SHOT, EASE_ELAST_OUT)
72-
self.L_tween.start(self.L_sprite, "position", self.L_sprite.position, Vector2(31, 0), random.uniform(2000.0, 2400.0), 1.0, ONE_SHOT, EASE_ELAST_OUT)
73-
self.RO_tween.start(self.RO_sprite, "position", self.RO_sprite.position, Vector2(41, 0), random.uniform(2000.0, 2400.0), 1.0, ONE_SHOT, EASE_ELAST_OUT)
74-
self.R_tween.start(self.R_sprite, "position", self.R_sprite.position, Vector2(52, -1), random.uniform(2000.0, 2400.0), 1.0, ONE_SHOT, EASE_ELAST_OUT)
64+
self.T_tween.start(self.T_sprite, "position", None, Vector2(-53, 0), random.uniform(2000.0, 2400.0), 1.0, ONE_SHOT, EASE_ELAST_OUT)
65+
self.h_tween.start(self.h_sprite, "position", None, Vector2(-44, 0), random.uniform(2000.0, 2400.0), 1.0, ONE_SHOT, EASE_ELAST_OUT)
66+
self.u_tween.start(self.u_sprite, "position", None, Vector2(-34, 2), random.uniform(2000.0, 2400.0), 1.0, ONE_SHOT, EASE_ELAST_OUT)
67+
self.m_tween.start(self.m_sprite, "position", None, Vector2(-24, 2), random.uniform(2000.0, 2400.0), 1.0, ONE_SHOT, EASE_ELAST_OUT)
68+
self.b_tween.start(self.b_sprite, "position", None, Vector2(-13, 0), random.uniform(2000.0, 2400.0), 1.0, ONE_SHOT, EASE_ELAST_OUT)
69+
self.y_tween.start(self.y_sprite, "position", None, Vector2(-4, 4), random.uniform(2000.0, 2400.0), 1.0, ONE_SHOT, EASE_ELAST_OUT)
70+
self.C_tween.start(self.C_sprite, "position", None, Vector2(10, 0), random.uniform(2000.0, 2400.0), 1.0, ONE_SHOT, EASE_ELAST_OUT)
71+
self.GO_tween.start(self.GO_sprite, "position", None, Vector2(21, 0), random.uniform(2000.0, 2400.0), 1.0, ONE_SHOT, EASE_ELAST_OUT)
72+
self.L_tween.start(self.L_sprite, "position", None, Vector2(31, 0), random.uniform(2000.0, 2400.0), 1.0, ONE_SHOT, EASE_ELAST_OUT)
73+
self.RO_tween.start(self.RO_sprite, "position", None, Vector2(41, 0), random.uniform(2000.0, 2400.0), 1.0, ONE_SHOT, EASE_ELAST_OUT)
74+
self.R_tween.start(self.R_sprite, "position", None, Vector2(52, -1), random.uniform(2000.0, 2400.0), 1.0, ONE_SHOT, EASE_ELAST_OUT)
7575

7676
# Need to give the screen time to setup, wait 650ms before starting animation
7777
delay = MainDelay()

src/animation/engine_animation_tween.c

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// Function positions in this array must correlate to enums in `engine_animation_ease_types`
1717
float (*ease[31])(float) = {
1818
&glm_ease_linear,
19-
19+
2020
&glm_ease_sine_in,
2121
&glm_ease_sine_out,
2222
&glm_ease_sine_inout,
@@ -269,7 +269,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(tween_class_tick_obj, tween_class_tick);
269269
DESC: Starts tweening a value. See https://easings.net/ for plots of the various easing functions
270270
PARAM: [type=object] [name=object] [value=object (the object that has an attribute to be tweened)]
271271
PARAM: [type=string] [name=attribute_name] [value=string]
272-
PARAM: [type=object] [name=start] [value=object (must be the same type as the attribute from `attribute_name`)]
272+
PARAM: [type=None|object] [name=start] [value=None|object (None means the current value, otherwise must be the same type as the attribute from `attribute_name`)]
273273
PARAM: [type=object] [name=end] [value=object (must be the same type as the attribute from `attribute_name`)]
274274
PARAM: [type=int] [name=duration] [value=any positive value representing milliseconds]
275275
PARAM: [type=float] [name=speed] [value=any]
@@ -299,21 +299,24 @@ mp_obj_t tween_class_start(size_t n_args, const mp_obj_t *args){
299299
if(strlen(attr_name) == 0){
300300
mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("Tween: ERROR: Trying to tween without an attribute name to lookup!"));
301301
}
302-
302+
303303
// Get the qstr for the attribute that should be tweened
304304
tween->attr = mp_obj_str_get_qstr(args[2]);
305305

306-
const mp_obj_type_t *value_type = mp_obj_get_type(mp_load_attr(tween->object, tween->attr));
307-
const mp_obj_type_t *start_type = mp_obj_get_type(args[3]);
308-
const mp_obj_type_t *end_type = mp_obj_get_type(args[4]);
306+
const mp_obj_t start_value = mp_load_attr(tween->object, tween->attr);
307+
const mp_obj_type_t *value_type = mp_obj_get_type(start_value);
308+
const mp_obj_t tween_start_value = args[3] == mp_const_none ? start_value : args[3];
309+
const mp_obj_t tween_end_value = args[4];
310+
const mp_obj_type_t *start_type = mp_obj_get_type(tween_start_value);
311+
const mp_obj_type_t *end_type = mp_obj_get_type(tween_end_value);
309312

310313
if(value_type == &mp_type_float && start_type == &mp_type_float && end_type == &mp_type_float){
311-
tween->initial_0 = mp_obj_get_float(args[3]);
312-
tween->end_0 = mp_obj_get_float(args[4]);
314+
tween->initial_0 = mp_obj_get_float(tween_start_value);
315+
tween->end_0 = mp_obj_get_float(tween_end_value);
313316
tween->tween_type = tween_type_float;
314317
}else if(value_type == &vector2_class_type && start_type == &vector2_class_type && end_type == &vector2_class_type){
315-
vector2_class_obj_t *start = args[3];
316-
vector2_class_obj_t *end = args[4];
318+
vector2_class_obj_t *start = tween_start_value;
319+
vector2_class_obj_t *end = tween_end_value;
317320

318321
tween->initial_0 = start->x.value;
319322
tween->initial_1 = start->y.value;
@@ -323,8 +326,8 @@ mp_obj_t tween_class_start(size_t n_args, const mp_obj_t *args){
323326

324327
tween->tween_type = tween_type_vec2;
325328
}else if(value_type == &vector3_class_type && start_type == &vector3_class_type && end_type == &vector3_class_type){
326-
vector3_class_obj_t *start = args[3];
327-
vector3_class_obj_t *end = args[4];
329+
vector3_class_obj_t *start = tween_start_value;
330+
vector3_class_o C4B7 bj_t *end = tween_end_value;
328331

329332
tween->initial_0 = start->x.value;
330333
tween->initial_1 = start->y.value;
@@ -336,8 +339,8 @@ mp_obj_t tween_class_start(size_t n_args, const mp_obj_t *args){
336339

337340
tween->tween_type = tween_type_vec3;
338341
}else if(value_type == &color_class_type && start_type == &color_class_type && end_type == &color_class_type){
339-
color_class_obj_t *start = args[3];
340-
color_class_obj_t *end = args[4];
342+
color_class_obj_t *start = tween_start_value;
343+
color_class_obj_t *end = tween_end_value;
341344

342345
tween->initial_0 = start->r.value;
343346
tween->initial_1 = start->g.value;
@@ -349,7 +352,8 @@ mp_obj_t tween_class_start(size_t n_args, const mp_obj_t *args){
349352

350353
tween->tween_type = tween_type_color;
351354
}else{
352-
ENGINE_PRINTF("ERROR: Got types value: %s, start: %s, end %s:\n", mp_obj_get_type_str(args[1]), mp_obj_get_type_str(args[3]), mp_obj_get_type_str(args[4]));
355+
ENGINE_PRINTF("ERROR: Got types value: %s, start: %s, end %s:\n",
356+
mp_obj_get_type_str(args[1]), mp_obj_get_type_str(tween_start_value), mp_obj_get_type_str(tween_end_value));
353357
mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("Tween: ERROR: Unknown combination of `value`, `start`, and `end` object types"));
354358
}
355359

0 commit comments

Comments
 (0)
0