OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2016 Google, Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #include "gm.h" | |
9 | |
10 /* | |
11 * Draw 50 semi-transparent circles with pseudo-random positions, radii, and | |
12 * colors, using the default blend mode (SRC OVER). Use of SkRandom with | |
13 * default seed means results SHOULD be identical across multiple platforms. | |
14 */ | |
15 DEF_SIMPLE_GM(bubbles, canvas, 512, 512) { | |
16 canvas->clear(SK_ColorWHITE); | |
17 | |
18 SkPaint p; | |
19 p.setAntiAlias(true); | |
20 | |
21 SkRandom rand; | |
22 | |
23 auto pos_min = SkIntToScalar(0); | |
24 auto pos_max = SkIntToScalar(511); | |
25 auto radius_min = SkIntToScalar(0); | |
26 auto radius_max = SkIntToScalar(128); | |
27 auto color_min = SkIntToScalar(0); | |
28 auto color_max = SkIntToScalar(255); | |
29 | |
30 const int NUM_BUBBLES = 50; | |
31 for (int i = 0; i < NUM_BUBBLES; i++) { | |
32 auto cx = rand.nextRangeScalar(pos_min, pos_max); | |
33 auto cy = rand.nextRangeScalar(pos_min, pos_max); | |
34 auto radius = rand.nextRangeScalar(radius_min, radius_max); | |
35 | |
36 auto a = (U8CPU)128; | |
37 auto r = (U8CPU)rand.nextRangeScalar(color_min, color_max); | |
38 auto g = (U8CPU)rand.nextRangeScalar(color_min, color_max); | |
39 auto b = (U8CPU)rand.nextRangeScalar(color_min, color_max); | |
40 p.setColor(SkColorSetARGB(a, r, g, b)); | |
41 | |
42 canvas->drawCircle(cx, cy, radius, p); | |
43 } | |
44 } | |
OLD | NEW |