Options
These globals are now defined:
double duration; // The requested duration of the animation. double frame; // A value in [0, 1] of where we are in the animation.
This global is now defined:
GrBackendRenderTarget backEndRenderTarget;
GrBackendTexture backEndTextureRenderTarget;
Optional source image
These globals are now defined:
SkBitmap source; sk_sp<SkImage> image; GrBackendTexture backEndTexture; // GPU Only.
Note:
Adding comments with SK_FOLD_START and SK_FOLD_END creates foldable code
blocks.
These blocks will be folded by default and are useful for highlighting specific lines of code.
You can also use the keyboard shortcuts Ctrl+S and Ctrl+E in the code editor to set them.
These blocks will be folded by default and are useful for highlighting specific lines of code.
You can also use the keyboard shortcuts Ctrl+S and Ctrl+E in the code editor to set them.
xxxxxxxxxx
67
SkPoint conic(SkPoint p0, SkPoint p1, SkPoint p2, float w, float t) {
float s = 1 - t;
return {((s * s * p0.x()) + (2 * s * t * w * p1.x()) + (t * t * p2.x())) /
((s * s) + (w * 2 * s * t) + (t * t)),
((s * s * p0.y()) + (2 * s * t * w * p1.y()) + (t * t * p2.y())) /
((s * s) + (w * 2 * s * t) + (t * t))};
}
void draw(SkCanvas* canvas) {
canvas->clear(SkColorSetARGB(255, 255, 255, 255));
SkPaint paint;
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(2.5);
SkPoint center = {256, 256};
float r = 192;
SkRect oval = {center.x() - r, center.y() - r, center.x() + r, center.y() + r};
canvas->drawOval(oval, paint);
float startAngle = 0;
float sweepAngle = 179;
SkPath arc;
arc.arcTo(oval, startAngle, sweepAngle, false);
paint.setStrokeWidth(5);
paint.setColor(SkColorSetARGB(255, 0, 0, 255));
canvas->drawPath(arc, paint);
SkPaint pointPaint;
pointPaint.setAntiAlias(true);
pointPaint.setStrokeWidth(8);
pointPaint.setStrokeCap(SkPaint::kRound_Cap);
pointPaint.setColor(SkColorSetARGB(255, 0, 255, 0));
float finalAngle = startAngle + sweepAngle;
float middleAngle = startAngle + 0.5f * sweepAngle;
float weight = cos(SkDegreesToRadians(sweepAngle) / 2);
SkPoint p0 = {r * SkScalarCos(SkDegreesToRadians(startAngle)),
r * SkScalarSin(SkDegreesToRadians(startAngle))};
float d = r / weight;
SkPoint p1 = {d * SkScalarCos(SkDegreesToRadians(middleAngle)),
d * SkScalarSin(SkDegreesToRadians(middleAngle))};
SkPoint p2 = {r * SkScalarCos(SkDegreesToRadians(finalAngle)),
r * SkScalarSin(SkDegreesToRadians(finalAngle))};
p0 += center;
p1 += center;
p2 += center;
const int N = 8;
for (int i = 0; i <= N; ++i) {
SkPoint p = conic(p0, p1, p2, weight, (float)i / N);
canvas->drawPoint(p.x(), p.y(), pointPaint);
}
pointPaint.setColor(SkColorSetARGB(255, 255, 0, 0));
canvas->drawPoint(p0.x(), p0.y(), pointPaint);
canvas->drawPoint(p1.x(), p1.y(), pointPaint);
canvas->drawPoint(p2.x(), p2.y(), pointPaint);
SkPath weightedQuadratic;
weightedQuadratic.moveTo(p0);
weightedQuadratic.conicTo(p1, p2, weight);
paint.setColor(SK_ColorCYAN);
paint.setStrokeWidth(1);
canvas->drawPath(weightedQuadratic, paint);
}