René Nyffenegger's collection of things on the web | |
René Nyffenegger on Oracle - Most wanted - Feedback
- Follow @renenyffenegger
|
Nested movie clips [Ming wrapper example] | ||
This example nests three movie clips into yet another.
This flash movie was created with the following program. NestedMovieClips.cpp
#include "SWFMovie.h" #include <cmath> #include <vector> typedef std::vector<Character_*> CharacterVec; /* Creates a MovieClip, puts characters of cv onto new clip and rotates them */ MovieClip MC(CharacterVec& cv, int radius, int frames) { MovieClip clip; std::vector<DisplayItem> vec_icv; for (CharacterVec::iterator icv = cv.begin(); icv != cv.end(); icv++) { vec_icv.push_back(clip.Add(**icv)); } int nof_characters = cv.size(); for (int cur_frame=0;cur_frame<frames;cur_frame++) { for (int cur_character=0;cur_character<nof_characters; cur_character++) { float angle = (float(cur_frame)/frames + float(cur_character)/nof_characters) *2*3.14156; int x = (int) (sin(angle) * radius); int y = (int) (cos(angle) * radius); vec_icv[cur_character].MoveTo(x,y); } clip.NextFrame(); } return clip; } /* WARNING: Memory Leak ahead */ Shape* rect(byte r, byte g, byte b, int len) { Shape* shape = new Shape; shape->FillStyle(r,g,b); //shape.MoveTo(x,y); shape->Line( len, 0); shape->Line( 0, len); shape->Line(-len, 0); shape->Line( 0,-len); return shape; } CharacterVec rects(byte r, byte g, byte b, int nof) { CharacterVec shapes; for (int i=0; i<nof;i++) { shapes.push_back(rect(r+ std::rand() % 80, g+std::rand() % 80,b+std::rand() % 80, 10)); } return shapes; } int main() { Movie movie ("NestedMovieClips.swf", 400, 400); movie.BackgroundColor(0x33, 0x33, 0x33); CharacterVec four_red___shapes = rects(175, 0, 0, 4); CharacterVec five_blue__shapes = rects( 0, 0, 175, 5); CharacterVec nine_green_shapes = rects( 0, 175, 0, 9); MovieClip clip_red = MC(four_red___shapes, 30, 30); MovieClip clip_blue = MC(five_blue__shapes, 20, 40); MovieClip clip_green= MC(nine_green_shapes, 40, 10); CharacterVec color_clips; color_clips.push_back(&clip_red ); color_clips.push_back(&clip_blue ); color_clips.push_back(&clip_green); MovieClip mcColerVec = MC(color_clips, 140, 100); //DisplayItem idm = movie.Add(MC(color_clips, 140, 100)); DisplayItem idm = movie.Add(mcColerVec); idm.MoveTo(200, 200); // Move clips to middle of screen movie.NextFrame(); return 0; } This is one of a series of examples that demonstrates the C++ ming wrapper classes. Other examples can be found here.
|