Flutter Engine
The Flutter Engine
Functions
Octopus_Generator_Animated.cpp File Reference
#include "tools/fiddle/examples.h"
#include <random>

Go to the source code of this file.

Functions

 REG_FIDDLE_ANIMATED (Octopus_Generator_Animated, 256, 256, false, 0, 4)
 

Function Documentation

◆ REG_FIDDLE_ANIMATED()

REG_FIDDLE_ANIMATED ( Octopus_Generator_Animated  ,
256  ,
256  ,
false  ,
,
 
)

Definition at line 5 of file Octopus_Generator_Animated.cpp.

5 {
6#include <random>
7
8void paintOctopus(float x, float y, int size_base, SkColor color, SkCanvas* canvas) {
10 paint.setAntiAlias(true);
11 paint.setColor(color);
12 int radius = 3*size_base;
13 canvas->drawCircle(x, y, radius, paint);
14 for (int leg = 0; leg < 8; ++leg) {
15 canvas->drawCircle(x - radius + (2*radius/7.5*leg),
16 y + radius - pow(abs(4-leg), 2), size_base/2 + 2, paint);
17 }
18 paint.setColor(SkColorSetRGB(std::min(255u, SkColorGetR(color) + 20),
19 std::min(255u, SkColorGetG(color) + 20),
20 std::min(255u, SkColorGetB(color) + 20)));
21 canvas->drawCircle(x-size_base, y+size_base, size_base/2, paint);
22 canvas->drawCircle(x+size_base, y+size_base, size_base/2, paint);
23}
24
25void draw(SkCanvas* canvas) {
26 std::default_random_engine rng;
27 const auto randScalar = [&rng](float min, float max) -> float {
28 return std::uniform_real_distribution<float>(min, max)(rng);
29 };
30 const auto randInt = [&rng](int min, int max) -> int {
31 return std::uniform_int_distribution<int>(min, max)(rng);
32 };
33 const auto randOpaqueColor = [&rng]() -> SkColor {
34 return std::uniform_int_distribution<uint32_t>(0, 0xFFFFFF)(rng) | 0xFF000000;
35 };
36
37 for (int i = 0; i < 400; ++i) {
38 float x = randScalar(0, 256);
39 float y = randScalar(0, 256);
40 int s = randInt(6, 12);
41 SkColor c = randOpaqueColor();
42 float radius = randScalar(0, 40);
43 float angle = (randScalar(0, 1) + frame) * 6.28319;
44 x += radius * cos(angle);
45 y += radius * sin(angle);
46 paintOctopus(x, y, s, c, canvas);
47 }
48}
49} // END FIDDLE
#define SkColorGetR(color)
Definition: SkColor.h:65
#define SkColorGetG(color)
Definition: SkColor.h:69
uint32_t SkColor
Definition: SkColor.h:37
#define SkColorSetRGB(r, g, b)
Definition: SkColor.h:57
#define SkColorGetB(color)
Definition: SkColor.h:73
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition: aaclip.cpp:27
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
Definition: SkCanvas.cpp:2707
const Paint & paint
Definition: color_source.cc:38
DlColor color
double frame
Definition: examples.cpp:31
struct MyStruct s
static float max(float r, float g, float b)
Definition: hsl.cpp:49
static float min(float r, float g, float b)
Definition: hsl.cpp:48
double y
double x
SIN Vec< N, float > abs(const Vec< N, float > &x)
Definition: SkVx.h:707