Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-demo.git] / examples / animated-shapes / animated-shapes-example.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <dali/dali.h>
19 #include <dali-toolkit/dali-toolkit.h>
20 #include "shared/view.h"
21
22 #include <sstream>
23
24 using namespace Dali;
25 using namespace Dali::Toolkit;
26
27 namespace
28 {
29
30 const char* APPLICATION_TITLE("Animated Shapes");
31
32 const char* VERTEX_SHADER = DALI_COMPOSE_SHADER
33 (
34   attribute mediump vec3 aCoefficient;
35   uniform mediump mat4 uMvpMatrix;
36   uniform mediump vec3 uPosition[MAX_POINT_COUNT];
37   varying lowp vec2 vCoefficient;
38   void main()
39   {
40     int vertexId = int(aCoefficient.z);
41     gl_Position = uMvpMatrix * vec4(uPosition[vertexId], 1.0);
42
43     vCoefficient = aCoefficient.xy;
44   }
45 );
46
47 // Fragment shader.
48 const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER
49 (
50   uniform lowp vec4 uColor;
51   varying lowp vec2 vCoefficient;
52   void main()
53   {
54     lowp float C = (vCoefficient.x*vCoefficient.x-vCoefficient.y);
55     lowp float Cdx = dFdx(C);
56     lowp float Cdy = dFdy(C);
57
58     lowp float distance = float(C / sqrt(Cdx*Cdx + Cdy*Cdy));
59     lowp float alpha = 0.5 - distance;
60     gl_FragColor = vec4( uColor.rgb, uColor.a * alpha );
61   }
62 );
63
64 Shader CreateShader( unsigned int pointCount )
65 {
66   std::ostringstream vertexShader;
67   vertexShader << "#define MAX_POINT_COUNT "<< pointCount << "\n"<<VERTEX_SHADER;
68
69   std::ostringstream fragmentShader;
70   fragmentShader << "#extension GL_OES_standard_derivatives : enable "<< "\n"<<FRAGMENT_SHADER;
71
72   Shader shader = Shader::New( vertexShader.str(), fragmentShader.str() );
73   for( unsigned int i(0); i<pointCount; ++i )
74   {
75     std::ostringstream propertyName;
76     propertyName << "uPosition["<<i<<"]";
77     shader.RegisterProperty(propertyName.str(),Vector3(0.0f,0.0f,0.0f) );
78   }
79
80   return shader;
81 }
82
83 } //unnamed namespace
84
85 // This example shows resolution independent rendering and animation of curves using the gpu.
86 //
87 class AnimatedShapesExample : public ConnectionTracker
88 {
89 public:
90
91   AnimatedShapesExample( Application& application )
92 : mApplication( application )
93 {
94   // Connect to the Application's Init signal
95   mApplication.InitSignal().Connect( this, &AnimatedShapesExample::Create );
96 }
97
98   ~AnimatedShapesExample() = default;
99
100   // The Init signal is received once (only) during the Application lifetime
101   void Create( Application& application )
102   {
103     Window window = application.GetWindow();
104     const Vector2 windowSize = window.GetSize();
105
106     // Creates the background gradient
107     Toolkit::Control background = Dali::Toolkit::Control::New();
108     background.SetProperty( Actor::Property::ANCHOR_POINT, Dali::AnchorPoint::CENTER );
109     background.SetProperty( Actor::Property::PARENT_ORIGIN, Dali::ParentOrigin::CENTER );
110     background.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS );
111     Dali::Property::Map map;
112     map.Insert( Toolkit::Visual::Property::TYPE,  Visual::GRADIENT );
113     Property::Array stopOffsets;
114     stopOffsets.PushBack( 0.0f );
115     stopOffsets.PushBack( 1.0f );
116     map.Insert( GradientVisual::Property::STOP_OFFSET, stopOffsets );
117     Property::Array stopColors;
118     stopColors.PushBack( Vector4( 0.0f,0.0f,1.0f,1.0f ) );
119     stopColors.PushBack( Vector4( 1.0f,1.0f,1.0f,1.0f ) );
120     map.Insert( GradientVisual::Property::STOP_COLOR, stopColors );
121     Vector2 halfWindowSize = windowSize * 0.5f;
122     map.Insert( GradientVisual::Property::START_POSITION,  Vector2(0.0f,-halfWindowSize.y) );
123     map.Insert( GradientVisual::Property::END_POSITION,  Vector2(0.0f,halfWindowSize.y)  );
124     map.Insert( GradientVisual::Property::UNITS, GradientVisual::Units::USER_SPACE );
125     background.SetProperty( Dali::Toolkit::Control::Property::BACKGROUND, map );
126     window.Add( background );
127
128     // Create a TextLabel for the application title.
129     Toolkit::TextLabel label = Toolkit::TextLabel::New( APPLICATION_TITLE );
130     label.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER );
131     label.SetProperty( Actor::Property::PARENT_ORIGIN, Vector3( 0.5f, 0.0f, 0.5f ) );
132     label.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
133     label.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
134     label.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
135     window.Add( label );
136
137     CreateTriangleMorph(Vector3( windowSize.x*0.5f, windowSize.y*0.15f, 0.0f), 100.0f );
138     CreateCircleMorph( Vector3( windowSize.x*0.5f, windowSize.y*0.5f, 0.0f), 55.0f );
139     CreateQuadMorph( Vector3( windowSize.x*0.5f, windowSize.y*0.85f, 0.0f), 60.0f );
140
141     window.KeyEventSignal().Connect( this, &AnimatedShapesExample::OnKeyEvent );
142   }
143
144   void CreateTriangleMorph( Vector3 center, float side )
145   {
146     float h = ( side *0.5f ) / 0.866f;
147
148     Vector3 v0 = Vector3( -h, h, 0.0f );
149     Vector3 v1 = Vector3( 0.0f, -side * 0.366f, 0.0f );
150     Vector3 v2 = Vector3( h, h, 0.0f );
151
152     Vector3 v3 = v0 + ( ( v1 - v0 ) * 0.5f );
153     Vector3 v4 = v1 + ( ( v2 - v1 ) * 0.5f );
154     Vector3 v5 = v2 + ( ( v0 - v2 ) * 0.5f );
155
156     Shader shader = CreateShader( 12 );
157     shader.SetProperty( shader.GetPropertyIndex( "uPosition[0]"), v0 );
158     shader.SetProperty( shader.GetPropertyIndex( "uPosition[1]"), v3 );
159     shader.SetProperty( shader.GetPropertyIndex( "uPosition[2]"), v1 );
160
161     shader.SetProperty( shader.GetPropertyIndex( "uPosition[3]"), v1 );
162     shader.SetProperty( shader.GetPropertyIndex( "uPosition[4]"), v4 );
163     shader.SetProperty( shader.GetPropertyIndex( "uPosition[5]"), v2 );
164
165     shader.SetProperty( shader.GetPropertyIndex( "uPosition[6]"), v2 );
166     shader.SetProperty( shader.GetPropertyIndex( "uPosition[7]"), v5 );
167     shader.SetProperty( shader.GetPropertyIndex( "uPosition[8]"), v0 );
168
169     shader.SetProperty( shader.GetPropertyIndex( "uPosition[9]"),  v0 );
170     shader.SetProperty( shader.GetPropertyIndex( "uPosition[10]"), v1 );
171     shader.SetProperty( shader.GetPropertyIndex( "uPosition[11]"), v2 );
172
173
174     //Create geometry
175     static const Vector3 vertexData[] = { Dali::Vector3( 0.0f, 0.0f, 0.0f ),
176                                           Dali::Vector3( 0.5f, 0.0f, 1.0f ),
177                                           Dali::Vector3( 1.0f, 1.0f, 2.0f ),
178
179                                           Dali::Vector3( 0.0f, 0.0f, 3.0f ),
180                                           Dali::Vector3( 0.5f, 0.0f, 4.0f ),
181                                           Dali::Vector3( 1.0f, 1.0f, 5.0f ),
182
183                                           Dali::Vector3( 0.0f, 0.0f, 6.0f ),
184                                           Dali::Vector3( 0.5f, 0.0f, 7.0f ),
185                                           Dali::Vector3( 1.0f, 1.0f, 8.0f ),
186
187                                           Dali::Vector3( 0.0f, 1.0f, 9.0f ),
188                                           Dali::Vector3( 0.0f, 1.0f, 10.0f ),
189                                           Dali::Vector3( 0.0f, 1.0f, 11.0f )
190     };
191
192     unsigned short indexData[] = { 0, 2, 1, 3, 5, 4, 6, 8, 7, 9, 11, 10 };
193
194     //Create a vertex buffer for vertex positions and texture coordinates
195     Dali::Property::Map vertexFormat;
196     vertexFormat["aCoefficient"] = Dali::Property::VECTOR3;
197     Dali::PropertyBuffer vertexBuffer = Dali::PropertyBuffer::New( vertexFormat );
198     vertexBuffer.SetData( vertexData, sizeof(vertexData)/sizeof(vertexData[0]));
199
200     //Create the geometry
201     Dali::Geometry geometry = Dali::Geometry::New();
202     geometry.AddVertexBuffer( vertexBuffer );
203     geometry.SetIndexBuffer( indexData, sizeof(indexData)/sizeof(indexData[0]) );
204
205     Renderer renderer = Renderer::New( geometry, shader );
206     renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
207
208     Actor actor = Actor::New();
209     actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
210     actor.SetProperty( Actor::Property::POSITION, center );
211     actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
212     actor.SetProperty( Actor::Property::COLOR,Vector4(1.0f,1.0f,0.0f,1.0f) );
213     actor.AddRenderer( renderer );
214
215     Window window = mApplication.GetWindow();
216     window.Add( actor );
217
218     //Animation
219     Animation animation = Animation::New(5.0f);
220     KeyFrames k0 = KeyFrames::New();
221     k0.Add( 0.0f,v3  );
222     k0.Add( 0.5f, v3 + Vector3(-150.0f,-150.0f,0.0f));
223     k0.Add( 1.0f, v3 );
224     animation.AnimateBetween( Property(shader, "uPosition[1]"),k0, AlphaFunction::EASE_IN_OUT_SINE );
225
226     k0 = KeyFrames::New();
227     k0.Add( 0.0f,v4  );
228     k0.Add( 0.5f, v4 + Vector3(150.0f,-150.0f,0.0f));
229     k0.Add( 1.0f, v4 );
230     animation.AnimateBetween( Property(shader,"uPosition[4]"),k0, AlphaFunction::EASE_IN_OUT_SINE );
231
232     k0 = KeyFrames::New();
233     k0.Add( 0.0f,v5  );
234     k0.Add( 0.5f, v5 + Vector3(0.0,150.0f,0.0f));
235     k0.Add( 1.0f, v5 );
236     animation.AnimateBetween( Property(shader, "uPosition[7]"),k0, AlphaFunction::EASE_IN_OUT_SINE );
237     animation.SetLooping( true );
238     animation.Play();
239   }
240
241   void CreateCircleMorph( Vector3 center, float radius )
242   {
243     Shader shader = CreateShader( 16 );
244     shader.SetProperty( shader.GetPropertyIndex("uPosition[0]"), Vector3( -radius, -radius, 0.0f ) );
245     shader.SetProperty( shader.GetPropertyIndex("uPosition[1]"), Vector3( 0.0f, -radius, 0.0f ) );
246     shader.SetProperty( shader.GetPropertyIndex("uPosition[2]"), Vector3( radius, -radius, 0.0f ) );
247
248     shader.SetProperty( shader.GetPropertyIndex("uPosition[3]"), Vector3( radius, -radius, 0.0f ) );
249     shader.SetProperty( shader.GetPropertyIndex("uPosition[4]"), Vector3( radius, 0.0f, 0.0f ) );
250     shader.SetProperty( shader.GetPropertyIndex("uPosition[5]"), Vector3( radius, radius, 0.0f ) );
251
252     shader.SetProperty( shader.GetPropertyIndex("uPosition[6]"), Vector3( radius, radius, 0.0f ) );
253     shader.SetProperty( shader.GetPropertyIndex("uPosition[7]"), Vector3( 0.0f, radius, 0.0f ) );
254     shader.SetProperty( shader.GetPropertyIndex("uPosition[8]"), Vector3( -radius, radius, 0.0f ) );
255
256     shader.SetProperty( shader.GetPropertyIndex("uPosition[9]"),  Vector3( -radius, radius, 0.0f ) );
257     shader.SetProperty( shader.GetPropertyIndex("uPosition[10]"), Vector3( -radius, 0.0f, 0.0f ) );
258     shader.SetProperty( shader.GetPropertyIndex("uPosition[11]"), Vector3( -radius, -radius, 0.0f ) );
259
260     shader.SetProperty( shader.GetPropertyIndex("uPosition[12]"), Vector3( -radius, -radius, 0.0f ) );
261     shader.SetProperty( shader.GetPropertyIndex("uPosition[13]"),  Vector3( radius, -radius, 0.0f ) );
262     shader.SetProperty( shader.GetPropertyIndex("uPosition[14]"), Vector3( radius, radius, 0.0f ) );
263     shader.SetProperty( shader.GetPropertyIndex("uPosition[15]"), Vector3( -radius, radius, 0.0f ) );
264
265     //shader.SetProperty( shader.GetPropertyIndex("uLineWidth"), 2.0f );
266
267     static const Vector3 vertexData[] = { Vector3( 0.0f, 0.0f, 0.0f ),
268                                           Vector3( 0.5f, 0.0f, 1.0f ),
269                                           Vector3( 1.0f, 1.0f, 2.0f ),
270                                           Vector3( 0.0f, 0.0f, 3.0f ),
271                                           Vector3( 0.5f, 0.0f, 4.0f ),
272                                           Vector3( 1.0f, 1.0f, 5.0f ),
273                                           Vector3( 0.0f, 0.0f, 6.0f ),
274                                           Vector3( 0.5f, 0.0f, 7.0f ),
275                                           Vector3( 1.0f, 1.0f, 8.0f ),
276                                           Vector3( 0.0f, 0.0f, 9.0f ),
277                                           Vector3( 0.5f, 0.0f, 10.0f ),
278                                           Vector3( 1.0f, 1.0f, 11.0f ),
279                                           Vector3( 0.0f, 1.0f, 12.0f ),
280                                           Vector3( 0.0f, 1.0f, 13.0f ),
281                                           Vector3( 0.0f, 1.0f, 14.0f ),
282                                           Vector3( 0.0f, 1.0f, 15.0f )};
283
284     short unsigned int indexData[] = { 0, 2, 1, 3, 5, 4, 6, 8, 7, 9, 11, 10, 12, 13, 14, 12, 14, 15 };
285
286     //Create a vertex buffer for vertex positions and texture coordinates
287     Dali::Property::Map vertexFormat;
288     vertexFormat["aCoefficient"] = Dali::Property::VECTOR3;
289     Dali::PropertyBuffer vertexBuffer = Dali::PropertyBuffer::New( vertexFormat );
290     vertexBuffer.SetData( vertexData, sizeof(vertexData)/sizeof(vertexData[0]));
291
292     //Create the geometry
293     Dali::Geometry geometry = Dali::Geometry::New();
294     geometry.AddVertexBuffer( vertexBuffer );
295     geometry.SetIndexBuffer( indexData, sizeof(indexData)/sizeof(indexData[0]) );
296
297     Renderer renderer = Renderer::New( geometry, shader );
298     renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
299
300     Actor actor = Actor::New();
301     actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
302     actor.SetProperty( Actor::Property::POSITION, center );
303     actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
304     actor.AddRenderer( renderer );
305
306     Window window = mApplication.GetWindow();
307     window.Add( actor );
308
309     //Animation
310     Animation animation = Animation::New(5.0f);
311     KeyFrames k0 = KeyFrames::New();
312     k0.Add( 0.0f, Vector3( 0.0f,-radius*1.85, 0.0f ) );
313     k0.Add( 0.5f, Vector3( -radius*1.85, -radius*3.0f, 0.0f ) );
314     k0.Add( 1.0f, Vector3( 0.0f,-radius*1.85, 0.0f ) );
315     animation.AnimateBetween( Property( shader, shader.GetPropertyIndex("uPosition[1]") ),k0, AlphaFunction::EASE_IN_OUT_SINE );
316
317     k0 = KeyFrames::New();
318     k0.Add( 0.0f, Vector3( radius*1.85, 0.0f, 0.0f ) );
319     k0.Add( 0.5f, Vector3( radius*3.0f,-radius*1.85, 0.0f ) );
320     k0.Add( 1.0f, Vector3( radius*1.85,0.0f, 0.0f ) );
321     animation.AnimateBetween( Property(shader, shader.GetPropertyIndex("uPosition[4]")),k0, AlphaFunction::EASE_IN_OUT_SINE );
322
323     k0 = KeyFrames::New();
324     k0.Add( 0.0f, Vector3( 0.0f, radius*1.85, 0.0f ) );
325     k0.Add( 0.5f, Vector3( radius*1.85, radius*3.0f, 0.0f) );
326     k0.Add( 1.0f, Vector3( 0.0f, radius*1.85, 0.0f) );
327     animation.AnimateBetween( Property( shader, shader.GetPropertyIndex("uPosition[7]") ),k0, AlphaFunction::EASE_IN_OUT_SINE );
328
329     k0 = KeyFrames::New();
330     k0.Add( 0.0f, Vector3( -radius*1.85, 0.0f, 0.0f) );
331     k0.Add( 0.5f, Vector3(-radius*3.0f, radius*1.85, 0.0f) );
332     k0.Add( 1.0f, Vector3( -radius*1.85, 0.0f, 0.0f) );
333     animation.AnimateBetween( Property( shader, shader.GetPropertyIndex("uPosition[10]") ),k0, AlphaFunction::EASE_IN_OUT_SINE );
334
335     animation.AnimateBy( Property( actor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(-90.0f) ), Vector3::ZAXIS ) );
336     animation.SetLooping( true );
337     animation.Play();
338   }
339
340   void CreateQuadMorph( Vector3 center, float radius )
341   {
342     Shader shader = CreateShader( 16 );
343     shader.SetProperty( shader.GetPropertyIndex("uPosition[0]"), Vector3( -radius, -radius, 0.0f ) );
344     shader.SetProperty( shader.GetPropertyIndex("uPosition[1]"), Vector3( 0.0f, -radius, 0.0f ) );
345     shader.SetProperty( shader.GetPropertyIndex("uPosition[2]"), Vector3( radius, -radius, 0.0f ) );
346
347     shader.SetProperty( shader.GetPropertyIndex("uPosition[3]"), Vector3( radius, -radius, 0.0f ) );
348     shader.SetProperty( shader.GetPropertyIndex("uPosition[4]"), Vector3( radius, 0.0f, 0.0f ) );
349     shader.SetProperty( shader.GetPropertyIndex("uPosition[5]"), Vector3( radius, radius, 0.0f ) );
350
351     shader.SetProperty( shader.GetPropertyIndex("uPosition[6]"), Vector3( radius, radius, 0.0f ) );
352     shader.SetProperty( shader.GetPropertyIndex("uPosition[7]"), Vector3( 0.0f, radius, 0.0f ) );
353     shader.SetProperty( shader.GetPropertyIndex("uPosition[8]"), Vector3( -radius, radius, 0.0f ) );
354
355     shader.SetProperty( shader.GetPropertyIndex("uPosition[9]"), Vector3( -radius, radius, 0.0f ) );
356     shader.SetProperty( shader.GetPropertyIndex("uPosition[10]"), Vector3( -radius, 0.0f, 0.0f ) );
357     shader.SetProperty( shader.GetPropertyIndex("uPosition[11]"), Vector3( -radius, -radius, 0.0f ) );
358
359     shader.SetProperty( shader.GetPropertyIndex("uPosition[12]"), Vector3( -radius, -radius, 0.0f ) );
360     shader.SetProperty( shader.GetPropertyIndex("uPosition[13]"), Vector3( radius, -radius, 0.0f ) );
361     shader.SetProperty( shader.GetPropertyIndex("uPosition[14]"), Vector3( radius, radius, 0.0f ) );
362     shader.SetProperty( shader.GetPropertyIndex("uPosition[15]"), Vector3( -radius, radius, 0.0f ) );
363
364     static const Vector3 vertexData[] = { Dali::Vector3( 0.0f, 0.0f, 0.0f ),
365                                           Dali::Vector3( 0.5f, 0.0f, 1.0f ),
366                                           Dali::Vector3( 1.0f, 1.0f, 2.0f ),
367
368                                           Dali::Vector3( 0.0f, 0.0f, 3.0f ),
369                                           Dali::Vector3( 0.5f, 0.0f, 4.0f ),
370                                           Dali::Vector3( 1.0f, 1.0f, 5.0f ),
371
372                                           Dali::Vector3( 0.0f, 0.0f, 6.0f ),
373                                           Dali::Vector3( 0.5f, 0.0f, 7.0f ),
374                                           Dali::Vector3( 1.0f, 1.0f, 8.0f ),
375
376                                           Dali::Vector3( 0.0f, 0.0f, 9.0f ),
377                                           Dali::Vector3( 0.5f, 0.0f, 10.0f ),
378                                           Dali::Vector3( 1.0f, 1.0f, 11.0f ),
379
380                                           Dali::Vector3( 0.0f, 1.0f, 12.0f ),
381                                           Dali::Vector3( 0.0f, 1.0f, 13.0f ),
382                                           Dali::Vector3( 0.0f, 1.0f, 14.0f ),
383                                           Dali::Vector3( 0.0f, 1.0f, 15.0f ) };
384
385     short unsigned int indexData[] = { 0, 2, 1, 3, 5, 4, 6, 8, 7, 9, 11, 10, 12, 15, 14, 12, 14, 13 };
386
387     //Create a vertex buffer for vertex positions and texture coordinates
388     Dali::Property::Map vertexFormat;
389     vertexFormat["aCoefficient"] = Dali::Property::VECTOR3;
390     Dali::PropertyBuffer vertexBuffer = Dali::PropertyBuffer::New( vertexFormat );
391     vertexBuffer.SetData( vertexData, sizeof(vertexData)/sizeof(vertexData[0]));
392
393     //Create the geometry
394     Dali::Geometry geometry = Dali::Geometry::New();
395     geometry.AddVertexBuffer( vertexBuffer );
396     geometry.SetIndexBuffer( indexData, sizeof(indexData)/sizeof(indexData[0]) );
397
398     Renderer renderer = Renderer::New( geometry, shader );
399     renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
400
401     Actor actor = Actor::New();
402     actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
403     actor.SetProperty( Actor::Property::POSITION, center );
404     actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
405     actor.SetProperty( Actor::Property::COLOR,Vector4(1.0f,0.0f,0.0f,1.0f) );
406     actor.AddRenderer( renderer );
407
408     Window window = mApplication.GetWindow();
409     window.Add( actor );
410
411     //Animation
412     Animation animation = Animation::New( 5.0f );
413     KeyFrames k0 = KeyFrames::New();
414     k0.Add( 0.0f, Vector3( 0.0f, -radius, 0.0f ) );
415     k0.Add( 0.5f, Vector3( 0.0f, -radius*4.0f, 0.0f ) );
416     k0.Add( 1.0f, Vector3( 0.0f, -radius, 0.0f ) );
417     animation.AnimateBetween( Property(shader, shader.GetPropertyIndex("uPosition[1]")),k0, AlphaFunction::EASE_IN_OUT_SINE );
418
419     k0 = KeyFrames::New();
420     k0.Add( 0.0f, Vector3( radius, 0.0f, 0.0f ) );
421     k0.Add( 0.5f, Vector3( radius*4.0f, 0.0f, 0.0f ) );
422     k0.Add( 1.0f, Vector3( radius, 0.0f, 0.0f ) );
423     animation.AnimateBetween( Property(shader, shader.GetPropertyIndex("uPosition[4]")),k0, AlphaFunction::EASE_IN_OUT_SINE );
424
425     k0 = KeyFrames::New();
426     k0.Add( 0.0f, Vector3( 0.0f, radius, 0.0f ) );
427     k0.Add( 0.5f, Vector3( 0.0f, radius*4.0f, 0.0f ) );
428     k0.Add( 1.0f, Vector3( 0.0f, radius, 0.0f ) );
429     animation.AnimateBetween( Property(shader, shader.GetPropertyIndex("uPosition[7]")),k0, AlphaFunction::EASE_IN_OUT_SINE );
430
431     k0 = KeyFrames::New();
432     k0.Add( 0.0f, Vector3( -radius, 0.0f, 0.0f ) );
433     k0.Add( 0.5f, Vector3( -radius*4.0f,0.0f, 0.0f ) );
434     k0.Add( 1.0f, Vector3( -radius,  0.0f, 0.0f ) );
435     animation.AnimateBetween( Property(shader, shader.GetPropertyIndex("uPosition[10]")),k0, AlphaFunction::EASE_IN_OUT_SINE );
436
437     animation.AnimateBy( Property( actor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(90.0f) ), Vector3::ZAXIS ) );
438     animation.SetLooping( true );
439     animation.Play();
440   }
441
442   /**
443    * Main key event handler
444    */
445   void OnKeyEvent(const KeyEvent& event)
446   {
447     if( event.state == KeyEvent::Down && (IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ))  )
448     {
449       mApplication.Quit();
450     }
451   }
452
453 private:
454   Application&                mApplication;
455
456 };
457
458 int DALI_EXPORT_API main( int argc, char **argv )
459 {
460   Application application = Application::New( &argc, &argv );
461   AnimatedShapesExample test( application );
462   application.MainLoop();
463   return 0;
464 }