EPhysics - Growing Balls

The purpose of this example is to demonstrate the dynamically growing and shrinking of an EPhysics_Body - The code applies the growth of a ball and the shrink of another.

For this example we'll have an EPhysics_World and three EPhysics_Bodys with different sizes associated with an evas_object.

The basic concepts like - defining an EPhysics_World, render geometry, physics limiting boundaries, add an EPhysics_Body, associate it to evas objects, change restitution, friction and impulse properties, were already covered in EPhysics - Bouncing Ball

# Adding the growing/shrinking

In this example we'll use a timer to handle the callback function.

test_data->data = ecore_timer_add(1, _grow_cb, test_data);
ecore_timer_add
Ecore_Timer * ecore_timer_add(double in, Ecore_Task_Cb func, const void *data)
Creates a timer to call the given function in the given period of time.
Definition ecore_timer.c:189

In this callback, we'll pass through a list with 3 balls and apply the growth and the shrink between the limit we'll set. Note that the variable i receives different values on each iteration (-1, 0, 1). For the first iteration it will decrease the size variable, the second will keep the same value, and the last one will increase the size variable.

_grow_cb(void *data)
{
Test_Data *test_data = data;
Evas_Object *obj;
Eina_List *l;
int size, i = -1;
EINA_LIST_FOREACH(test_data->evas_objs, l, obj)
{
evas_object_geometry_get(obj, NULL, NULL, &size, NULL);
size += i * 8;
i++;
if ((size < 20) || (size > 120))
continue;
evas_object_resize(obj, size, size);
}
return EINA_TRUE;
Eina_List
struct _Eina_List Eina_List
Type for a generic double linked list.
Definition eina_list.h:304
EINA_LIST_FOREACH
#define EINA_LIST_FOREACH(list, l, _data)
Definition for the macro to iterate over a list.
Definition eina_list.h:1415
EINA_TRUE
#define EINA_TRUE
boolean value TRUE (numerical value 1)
Definition eina_types.h:539
evas_object_geometry_get
EVAS_API void evas_object_geometry_get(const Evas_Object *eo_obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
Retrieves the position and (rectangular) size of the given Evas object.
Definition evas_object_main.c:1335
Evas_Object
Efl_Canvas_Object Evas_Object
An Evas Object handle.
Definition Evas_Common.h:185
evas_object_resize
EVAS_API void evas_object_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
Changes the size of the given Evas object.
Definition evas_object_main.c:1236
}

Here we finish the example. The full source code can be found at test_growing_balls.c.