blob: da791ddff8afc0fa1247e5d8cfc45cf9da52a15e [file] [log] [blame]
Hal Canary6c8422c2020-01-10 15:22:09 -05001// 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.
3#include "tools/fiddle/examples.h"
4REG_FIDDLE(Octopus_Generator, 256, 256, false, 0) {
5void paintOctopus(int x, int y, int size_base, SkColor color, SkCanvas* canvas) {
6 SkPaint paint;
7 paint.setAntiAlias(true);
8 paint.setColor(color);
9 int radius = 3 * size_base;
10 canvas->drawCircle(x, y, radius, paint);
11 for (int leg = 0; leg < 8; ++leg) {
12 canvas->drawCircle(x - radius + (2 * radius / 7.5 * leg),
13 y + radius - pow(abs(4 - leg), 2), size_base / 2 + 2, paint);
14 }
Brian Osman788b9162020-02-07 10:36:46 -050015 paint.setColor(SkColorSetRGB(std::min(255u, SkColorGetR(color) + 20),
16 std::min(255u, SkColorGetG(color) + 20),
17 std::min(255u, SkColorGetB(color) + 20)));
Hal Canary6c8422c2020-01-10 15:22:09 -050018 canvas->drawCircle(x - size_base, y + size_base, size_base / 2, paint);
19 canvas->drawCircle(x + size_base, y + size_base, size_base / 2, paint);
20}
21
22void draw(SkCanvas* canvas) {
23 SkRandom rand;
24
25 for (int i = 0; i < 400; ++i) {
26 paintOctopus(rand.nextRangeScalar(0, 256), rand.nextRangeScalar(0, 256),
27 rand.nextRangeScalar(6, 12), rand.nextU() | 0xFF0000000, canvas);
28 }
29}
30} // END FIDDLE