void Leaves::Draw(BView* view, int32 frame) { float scale = fLeafSize / kLeafWidth / (kMaximumLeafSize * 2); scale *= view->Bounds().Width(); scale += scale * drand48() * fSizeVariation / 100.; BAffineTransform transform; transform.TranslateBy(-kLeafWidth / 2, -kLeafHeight / 2); // draw the leaf centered on the point transform.RotateBy(drand48() * 2. * M_PI); if ((rand() & 64) == 0) transform.ScaleBy(-1., 1.); // flip half of the time transform.ScaleBy(scale); transform.TranslateBy(_RandomPoint(view->Bounds())); BPoint center = transform.Apply(BPoint(kLeafWidth / 2, kLeafHeight / 2)); BPoint gradientOffset = BPoint(60 * scale, 80 * scale); BGradientLinear gradient(center - gradientOffset, center + gradientOffset); int color = (rand() / 7) % kColorCount; gradient.AddColor(kColors[color][0], 0.f); gradient.AddColor(kColors[color][1], 255.f); BShape leafShape; leafShape.MoveTo(transform.Apply(kLeafBegin)); for (int i = 0; i < kLeafCurveCount; ++i) { BPoint control[3]; for (int j = 0; j < 3; ++j) control[j] = transform.Apply(kLeafCurves[i][j]); leafShape.BezierTo(control); } leafShape.Close(); view->PushState(); view->SetDrawingMode(B_OP_ALPHA); view->SetHighColor(0, 0, 0, 50); for (int i = 2; i >= 0; --i) { view->SetOrigin(i * 0.1, i * 0.3); view->SetPenSize(i * 2); view->StrokeShape(&leafShape); } view->PopState(); view->FillShape(&leafShape, gradient); }
void LeafView::Draw(BRect updateRect) { float scale = Bounds().Width() / kLeafWidth; BAffineTransform transform; transform.ScaleBy(scale); // BGradientRadial gradient(BPoint(kLeafWidth * 0.75, kLeafHeight * 1.5), // kLeafWidth * 2); BGradientLinear gradient(B_ORIGIN, transform.Apply(BPoint(kLeafWidth, kLeafHeight))); rgb_color lightBlue = make_color(6, 169, 255); rgb_color darkBlue = make_color(0, 50, 126); gradient.AddColor(darkBlue, 0.0); gradient.AddColor(lightBlue, 255.0); // build leaf shape BShape leafShape; leafShape.MoveTo(transform.Apply(kLeafBegin)); for (int i = 0; i < kNumLeafCurves; ++i) { BPoint controlPoints[3]; for (int j = 0; j < 3; ++j) controlPoints[j] = transform.Apply(kLeafCurves[i][j]); leafShape.BezierTo(controlPoints); } leafShape.Close(); PushState(); SetDrawingMode(B_OP_ALPHA); SetHighColor(0, 0, 0, 50); for (int i = 2; i >= 0; --i) { SetOrigin(i * 0.1, i * 0.3); SetPenSize(i * 2); StrokeShape(&leafShape); } PopState(); FillShape(&leafShape, gradient); }