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
28
static SkScalar PingPong(double t, SkScalar period, SkScalar phase,
SkScalar ends, SkScalar mid) {
double value = ::fmod(t + phase, period);
double half = period / 2.0;
double diff = ::fabs(value - half);
return SkDoubleToScalar(ends + (1.0 - diff / half) * (mid - ends));
}
void draw(SkCanvas* canvas) {
canvas->clear(SK_ColorBLACK);
float ballX = PingPong(frame * duration, 2.5f, 0.0f, 0.0f, 1.0f);
float ballY = PingPong(frame * duration, 2.0f, 0.4f, 0.0f, 1.0f);
SkPaint p;
p.setColor(SK_ColorWHITE);
p.setAntiAlias(true);
float bX = ballX * 472 + 20;
float bY = ballY * 200 + 28;
if (canvas->recordingContext()) {
canvas->drawRect(SkRect::MakeXYWH(236, bY - 15, 10, 30), p);
bX -= 256;
} else {
canvas->drawRect(SkRect::MakeXYWH(10, bY - 15, 10, 30), p);
}
canvas->drawCircle(bX, bY, 5, p);
}