Flutter Engine
The Flutter Engine
pong2.cpp
Go to the documentation of this file.
1// Copyright 2020 Google LLC.
2// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
4REG_FIDDLE_ANIMATED(pong2, 512, 256, false, 0, 10) {
5static SkScalar PingPong(double t, SkScalar period, SkScalar phase,
6 SkScalar ends, SkScalar mid) {
7 double value = ::fmod(t + phase, period);
8 double half = period / 2.0;
9 double diff = ::fabs(value - half);
10 return SkDoubleToScalar(ends + (1.0 - diff / half) * (mid - ends));
11}
12
13void draw(SkCanvas* canvas) {
14 float bX = PingPong(frame * duration, 2.5f, 0.0f, 0, 1) * 472 + 20;
15 float bY = PingPong(frame * duration, 2.0f, 0.4f, 0, 1) * 200 + 28;
16
17 SkPaint p;
18 p.setColor(SK_ColorWHITE);
19 p.setAntiAlias(true);
20
21 canvas->clear(SK_ColorBLACK);
22 canvas->drawRect(SkRect::MakeXYWH(492, bY - 15, 10, 30), p);
23 canvas->drawRect(SkRect::MakeXYWH(10, bY - 15, 10, 30), p);
24 canvas->drawCircle(bX, bY, 5, p);
25
26 const float intervals[] = { 12, 6 };
27 p.setStrokeWidth(5);
28 p.setPathEffect(SkDashPathEffect::Make(intervals, std::size(intervals), 0));
29 canvas->drawLine({256,0}, {256, 256}, p);
30}
31} // END FIDDLE
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
#define SkDoubleToScalar(x)
Definition: SkScalar.h:64
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition: aaclip.cpp:27
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint &paint)
Definition: SkCanvas.cpp:2700
void clear(SkColor color)
Definition: SkCanvas.h:1199
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
Definition: SkCanvas.cpp:2707
static sk_sp< SkPathEffect > Make(const SkScalar intervals[], int count, SkScalar phase)
double duration
Definition: examples.cpp:30
double frame
Definition: examples.cpp:31
float SkScalar
Definition: extension.cpp:12
uint8_t value
static float PingPong(double time, float period, float phase, float ends, float mid)
Definition: TimeUtils.h:37
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
REG_FIDDLE_ANIMATED(pong2, 512, 256, false, 0, 10)
Definition: pong2.cpp:4
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659