TestWindow(int w, int h, char const* const* files, int fileCount, bool doCircles, bool doFade, ShapeFactory fact, int repeat) : GXWindow(w, h) { fDoOpaque = true; fStartTime = GTime::GetMSec(); fCounter = 0; GRandom rand; fBitmapCount = 0; fBitmaps = new GBitmap[fileCount]; for (int i = 0; i < fileCount; ++i) { if (GReadBitmapFromFile(files[i], &fBitmaps[i])) { fBitmapCount += 1; if (doCircles) { fill_circle(fBitmaps[i]); } } else { fprintf(stderr, "failed to decode %s\n", files[i]); } } fShapeCount = fBitmapCount * repeat; fShapes = new Shape*[fShapeCount]; float speed = 300; for (int i = 0; i < fShapeCount; ++i) { fShapes[i] = fact(fBitmaps[i % fBitmapCount], w/2, h/2); fShapes[i]->setup(rand.nextF() * speed, rand.nextF() * speed, doFade ? rand.nextF() : 0); } }
PolyShape(const GBitmap& bm, int x, int y) : Shape(x, y) { fCount = gRand.nextRange(3, 20); fPts = new GPoint[fCount]; float scaleX = bm.width() * .5f; float scaleY = bm.height() * .5f; for (int i = 0; i < fCount; ++i) { float angle = i * 2 * 3.14159265359 / fCount; float sv, cv; cv = cos_sin(angle, &sv); fPts[i].set(scaleX * sv, scaleY * cv); } fPaint.setRGB(gRand.nextF(), gRand.nextF(), gRand.nextF()); }
Shape(float x, float y) : fX(x), fY(y), fA(1) { fPrevTime = GTime::GetMSec(); if (gRand.nextF() > 0.5) { fFlipX = -1; } else { fFlipX = 1; } if (gRand.nextF() > 0.5) { fFlipY = -1; } else { fFlipY = 1; } fScale = 1; if (gAnimateScale) { fDScale = (gRand.nextF() * 2 - 1) * 0.5f; } else { fDScale = 0; } fRad = 0; fDRad = gAnimateRad ? gRand.nextF() * 0.05f : 0; }
TriShape(const GBitmap& bm, int x, int y) : Shape(x, y) { for (int i = 0; i < 3; ++i) { rand_pt(&fPts[i]); } fPaint.setRGB(gRand.nextF(), gRand.nextF(), gRand.nextF()); }
RectShape(const GBitmap& bm, int x, int y) : Shape(x, y) { fRect.setXYWH(x, y, bm.width(), bm.height()); fRect.offset(-fRect.centerX(), -fRect.centerY()); fPaint.setRGB(gRand.nextF(), gRand.nextF(), gRand.nextF()); }
static void rand_pt(GPoint* p) { p->set((gRand.nextF() * 2 - 1) * 100, (gRand.nextF() * 2 - 1) * 100); }
static GColor rand_color() { return GColor::MakeARGB(0.5f, gRand.nextF(), gRand.nextF(), gRand.nextF()); }