René Nyffenegger's collection of things on the web
René Nyffenegger on Oracle - Most wanted - Feedback -
 

Sparks [Ming wrapper example]

See Export.
This flash movie was created with the following program.
Sparks.cpp
#include "SWFMovie.h"

int main() {
  int movie_width =400;
  int movie_height=400;

  Movie movie ("Sparks.swf", movie_width, movie_height);

  movie.BackgroundColor(10,20,30);

  Gradient gradient;
  gradient.Add(0.0, 0xff, 0xff, 0xff, 0xff);
  gradient.Add(1.0, 0xff, 0xff, 0xff,    0);

  int circle_radius=10;
  Shape shape;
  GradientFill gradient_fill = shape.GetRadial(gradient);
  gradient_fill.ScaleXYTo(
      float(circle_radius)/movie_width /2, 
      float(circle_radius)/movie_height/2);

  shape.Fill(gradient_fill);
  shape.Circle(circle_radius);

  MovieClip clip;
  clip.Add(shape);
  clip.NextFrame();
  movie.Export(clip, "Sparkle");

  Action as(
    "sparkles     = [];"
    "cnt_sparkles =20;"
    
    "function init_sparkle(s) {"
    "  var angle = Math.random() * 2.0 * Math.PI;"
    "  var vel   = Math.random() * 20.0;"
    "  s.x_vel=Math.sin(angle)*vel;"
    "  s.y_vel=Math.cos(angle)*vel;"
    "  s.x=_xmouse;"
    "  s.y=_ymouse;"
    "}"
    
    "function move_sparkle(s) {"
    "  s._x = s.x;"
    "  s._y = s.y;"
    "  s.y_vel += 4;"
    "  s.x = s.x+s.x_vel;"
    "  s.y = s.y+s.y_vel;"
    "  if (s.y>400) {"
    "    init_sparkle(s);"
    "  }"
    "}"
    
    "for(var i=0; i<cnt_sparkles; i++) {"
    "	 sparkles[i]=_root.attachMovie('Sparkle','some_counter'+i,i+10);"
    "  init_sparkle(sparkles[i]);"
    "  move_sparkle(sparkles[i]);"
    "}"
    "_root.onEnterFrame = function() {"
    "  for(var i=0; i<cnt_sparkles; i++){"
    "    move_sparkle(sparkles[i]);"
    "  }"
    "};"
  );

  movie.Add(as);

  return 0;
}
This is one of a series of examples that demonstrates the C++ ming wrapper classes. Other examples can be found here.