Flutter Engine
The Flutter Engine
Octopus_Generator.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.
4
5REG_FIDDLE(Octopus_Generator, 256, 256, false, 0) {
6#include <random>
7
8void paintOctopus(int x, int 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](SkScalar min, SkScalar max) -> SkScalar {
28 return std::uniform_real_distribution<SkScalar>(min, max)(rng);
29 };
30 const auto randOpaqueColor = [&rng]() -> SkColor {
31 return std::uniform_int_distribution<uint32_t>(0, 0xFFFFFF)(rng) | 0xFF000000;
32 };
33
34 for (int i = 0; i < 400; ++i) {
35 paintOctopus(randScalar(0, 256), randScalar(0, 256),
36 randScalar(6, 12), randOpaqueColor(), canvas);
37 }
38}
39} // END FIDDLE
REG_FIDDLE(Octopus_Generator, 256, 256, false, 0)
#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
float SkScalar
Definition: extension.cpp:12
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