status_t Butterfly::StartSaver(BView* view, bool preview) { view->SetLowColor(0, 0, 0); view->FillRect(view->Bounds(), B_SOLID_LOW); view->SetDrawingMode(B_OP_ALPHA); view->SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_OVERLAY); view->SetLineMode(B_ROUND_CAP, B_ROUND_JOIN); if (!preview) view->SetPenSize(2.0); SetTickSize(20000); // Set fBase to a random radian value scaled by 1000. The scaling produces // more interesting results. srand48(system_time()); fBase = drand48() * 2 * M_PI * 1000; // calculate transformation BRect bounds = view->Bounds(); fScale = MIN(bounds.Width(), bounds.Height()) * 0.1f; fTrans.Set(bounds.Width() * 0.5f, bounds.Height() * 0.5f); fBounds = bounds; fLast[0] = _Iterate(); fLast[1] = _Iterate(); fLast[2] = _Iterate(); return B_OK; }
void Butterfly::Draw(BView* view, int32 frame) { if (frame == 1024) { // calculate bounding box ( (-5.92,-5.92) to (5.92, 5.92) ) fBounds.Set(-5.92f * fScale + fTrans.x, -5.92f * fScale + fTrans.y, 5.92f * fScale + fTrans.x, 5.92f * fScale + fTrans.y); } if ((frame & 3) == 0) { // fade out view->SetHighColor(0, 0, 0, 4); view->FillRect(fBounds); } // create a color from a hue of (fBase * 15) degrees view->SetHighColor(_HueToColor(fBase * 15)); BPoint p = _Iterate(); // cubic Hermite interpolation from fLast[1] to fLast[2] // calculate tangents for a Catmull-Rom spline //(these values need to be halved) BPoint m1 = fLast[2] - fLast[0]; // tangent for fLast[1] BPoint m2 = p - fLast[1]; // tangent for fLast[2] // draw Bezier from fLast[1] to fLast[2] with control points // fLast[1] + m1/3, fLast[2] - m2/3 m1.x /= 6; m1.y /= 6; m2.x /= 6; m2.y /= 6; BPoint control[4] = { fLast[1], fLast[1] + m1, fLast[2] - m2, fLast[2] }; view->StrokeBezier(control); fLast[0] = fLast[1]; fLast[1] = fLast[2]; fLast[2] = p; }
void TraceCollection::ReverseIterate(Visitor& visitor) const { _Iterate(visitor, true); }
void TraceCollection::Iterate(Visitor& visitor) const { _Iterate(visitor, false); }