Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
CanvasLineSegment Class Reference
Inheritance diagram for CanvasLineSegment:
MMObject

Public Member Functions

 CanvasLineSegment (SkRandom *random, const LineSegmentParams &params)
 
 ~CanvasLineSegment () override=default
 
void draw (SkCanvas *canvas) override
 
void animate (double nanos) override
 
- Public Member Functions inherited from MMObject
virtual ~MMObject ()=default
 
virtual void draw (SkCanvas *canvas)=0
 
virtual void animate (double)=0
 

Detailed Description

Definition at line 170 of file MotionMarkSlide.cpp.

Constructor & Destructor Documentation

◆ CanvasLineSegment()

CanvasLineSegment::CanvasLineSegment ( SkRandom random,
const LineSegmentParams params 
)
inline

Definition at line 172 of file MotionMarkSlide.cpp.

172 {
173 int circle = random->nextRangeU(0, 3);
174
175 static constexpr SkColor kColors[] = {
176 0xffe01040, 0xff10c030, 0xff744cba, 0xffe05010
177 };
178 fColor = kColors[circle];
179 fLineWidth = std::pow(random->nextF(), 12) * 20 + 3;
180 fOmega = random->nextF() * 3 + 0.2f;
181 float theta = random->nextRangeF(0, 2*SK_ScalarPI);
182 fCosTheta = std::cos(theta);
183 fSinTheta = std::sin(theta);
184 fStart = params.fCircleCenters[circle] + SkPoint::Make(params.fCircleRadius * fCosTheta,
185 params.fCircleRadius * fSinTheta);
186 fLength = params.fLineMinimum;
187 fLength += std::pow(random->nextF(), 8) * params.fLineLengthMaximum;
188 fSegmentDirection = random->nextF() > 0.5 ? -1 : 1;
189 }
uint32_t SkColor
Definition: SkColor.h:37
#define SK_ScalarPI
Definition: SkScalar.h:21
float nextF()
Definition: SkRandom.h:55
float nextRangeF(float min, float max)
Definition: SkRandom.h:64
uint32_t nextRangeU(uint32_t min, uint32_t max)
Definition: SkRandom.h:80
const EmbeddedViewParams * params
const DlColor kColors[]
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173

◆ ~CanvasLineSegment()

CanvasLineSegment::~CanvasLineSegment ( )
overridedefault

Member Function Documentation

◆ animate()

void CanvasLineSegment::animate ( double  nanos)
inlineoverridevirtual

Implements MMObject.

Definition at line 207 of file MotionMarkSlide.cpp.

207 {
208 fLength += std::sin(time_counter_value(nanos, 100) * fOmega);
209 }

◆ draw()

void CanvasLineSegment::draw ( SkCanvas canvas)
inlineoverridevirtual

Implements MMObject.

Definition at line 193 of file MotionMarkSlide.cpp.

193 {
195 paint.setAntiAlias(true);
196 paint.setColor(fColor);
197 paint.setStrokeWidth(fLineWidth);
199
200 SkPoint end = {
201 fStart.fX + fSegmentDirection * fLength * fCosTheta,
202 fStart.fY + fSegmentDirection * fLength * fSinTheta
203 };
204 canvas->drawLine(fStart, end, paint);
205 }
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint &paint)
Definition: SkCanvas.cpp:2700
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
const Paint & paint
Definition: color_source.cc:38
glong glong end
float fX
x-axis value
Definition: SkPoint_impl.h:164
float fY
y-axis value
Definition: SkPoint_impl.h:165

The documentation for this class was generated from the following file: