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.
3 #include "tools/fiddle/examples.h"
4 REG_FIDDLE_ANIMATED(Octopus_Generator_Animated, 256, 256, false, 0, 4) {
paintOctopus(int x,int y,int size_base,SkColor color,SkCanvas * canvas)5 void 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 }
15 paint.setColor(SkColorSetRGB(std::min(255u, SkColorGetR(color) + 20),
16 std::min(255u, SkColorGetG(color) + 20),
17 std::min(255u, SkColorGetB(color) + 20)));
18 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
draw(SkCanvas * canvas)22 void draw(SkCanvas* canvas) {
23 SkRandom rand;
24
25 for (int i = 0; i < 400; ++i) {
26 float x = rand.nextRangeScalar(0, 256);
27 float y = rand.nextRangeScalar(0, 256);
28 float s = rand.nextRangeScalar(6, 12);
29 SkColor c = rand.nextU() | SkColorSetARGB(255, 0, 0, 0);
30 float radius = rand.nextRangeScalar(0, 40);
31 float angle = (rand.nextRangeScalar(0, 1) + frame) * 6.28319;
32 x += radius * cos(angle);
33 y += radius * sin(angle);
34 paintOctopus(x, y, s, c, canvas);
35 }
36 }
37 } // END FIDDLE
38