Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: gm/lighting.cpp

Issue 1870133003: Make some GMs animate (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Actually use the timer Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gm/dashcircle.cpp ('k') | gm/stringart.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "gm.h" 8 #include "gm.h"
9 #include "SkAnimTimer.h"
9 #include "SkLightingImageFilter.h" 10 #include "SkLightingImageFilter.h"
10 #include "SkOffsetImageFilter.h" 11 #include "SkOffsetImageFilter.h"
11 #include "SkPoint3.h" 12 #include "SkPoint3.h"
12 13
13 #define WIDTH 330 14 #define WIDTH 330
14 #define HEIGHT 660 15 #define HEIGHT 660
15 16
16 namespace skiagm { 17 namespace skiagm {
17 18
18 class ImageLightingGM : public GM { 19 class ImageLightingGM : public GM {
19 public: 20 public:
20 ImageLightingGM() { 21 ImageLightingGM()
22 : fAzimuth(SkIntToScalar(kStartAzimuth)) {
21 this->setBGColor(0xFF000000); 23 this->setBGColor(0xFF000000);
22 } 24 }
23 25
24 protected: 26 protected:
25 27
26 SkString onShortName() override { 28 SkString onShortName() override {
27 return SkString("lighting"); 29 return SkString("lighting");
28 } 30 }
29 31
30 SkISize onISize() override { 32 SkISize onISize() override {
(...skipping 19 matching lines...) Expand all
50 checkPaint.setColor(sk_tool_utils::color_to_565(0xFF202020)); 52 checkPaint.setColor(sk_tool_utils::color_to_565(0xFF202020));
51 for (int y = 0; y < HEIGHT; y += 16) { 53 for (int y = 0; y < HEIGHT; y += 16) {
52 for (int x = 0; x < WIDTH; x += 16) { 54 for (int x = 0; x < WIDTH; x += 16) {
53 canvas->save(); 55 canvas->save();
54 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); 56 canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
55 canvas->drawRect(SkRect::MakeXYWH(8, 0, 8, 8), checkPaint); 57 canvas->drawRect(SkRect::MakeXYWH(8, 0, 8, 8), checkPaint);
56 canvas->drawRect(SkRect::MakeXYWH(0, 8, 8, 8), checkPaint); 58 canvas->drawRect(SkRect::MakeXYWH(0, 8, 8, 8), checkPaint);
57 canvas->restore(); 59 canvas->restore();
58 } 60 }
59 } 61 }
60 SkPoint3 pointLocation = SkPoint3::Make(0, 0, SkIntToScalar(10)); 62 SkScalar cosAzimuth;
61 SkScalar azimuthRad = SkDegreesToRadians(SkIntToScalar(225)); 63 SkScalar sinAzimuth = SkScalarSinCos(SkDegreesToRadians(fAzimuth), &cosA zimuth);
64
65 SkPoint3 spotTarget = SkPoint3::Make(SkIntToScalar(40), SkIntToScalar(40 ), 0);
66 SkPoint3 spotLocation = SkPoint3::Make(spotTarget.fX + 70.7214f * cosAzi muth,
67 spotTarget.fY + 70.7214f * sinAzi muth,
68 spotTarget.fZ + SkIntToScalar(20) );
69 SkScalar spotExponent = SK_Scalar1;
70
71 SkPoint3 pointLocation = SkPoint3::Make(spotTarget.fX + 50 * cosAzimuth,
72 spotTarget.fY + 50 * sinAzimuth,
73 SkIntToScalar(10));
62 SkScalar elevationRad = SkDegreesToRadians(SkIntToScalar(5)); 74 SkScalar elevationRad = SkDegreesToRadians(SkIntToScalar(5));
63 SkPoint3 distantDirection = SkPoint3::Make(SkScalarMul(SkScalarCos(azimu thRad), 75
76 SkPoint3 distantDirection = SkPoint3::Make(SkScalarMul(cosAzimuth,
64 SkScalarCos(eleva tionRad)), 77 SkScalarCos(eleva tionRad)),
65 SkScalarMul(SkScalarSin(azimu thRad), 78 SkScalarMul(sinAzimuth,
66 SkScalarCos(eleva tionRad)), 79 SkScalarCos(eleva tionRad)),
67 SkScalarSin(elevationRad)); 80 SkScalarSin(elevationRad));
68 SkPoint3 spotLocation = SkPoint3::Make(SkIntToScalar(-10),
69 SkIntToScalar(-10),
70 SkIntToScalar(20));
71 SkPoint3 spotTarget = SkPoint3::Make(SkIntToScalar(40), SkIntToScalar(40 ), 0);
72 SkScalar spotExponent = SK_Scalar1;
73 SkScalar cutoffAngle = SkIntToScalar(15); 81 SkScalar cutoffAngle = SkIntToScalar(15);
74 SkScalar kd = SkIntToScalar(2); 82 SkScalar kd = SkIntToScalar(2);
75 SkScalar ks = SkIntToScalar(1); 83 SkScalar ks = SkIntToScalar(1);
76 SkScalar shininess = SkIntToScalar(8); 84 SkScalar shininess = SkIntToScalar(8);
77 SkScalar surfaceScale = SkIntToScalar(1); 85 SkScalar surfaceScale = SkIntToScalar(1);
78 SkColor white(0xFFFFFFFF); 86 SkColor white(0xFFFFFFFF);
79 SkPaint paint; 87 SkPaint paint;
80 88
81 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 10, 60, 65)); 89 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 10, 60, 65));
82 SkImageFilter::CropRect fullSizeCropRect(SkRect::MakeXYWH(0, 0, 100, 100 )); 90 SkImageFilter::CropRect fullSizeCropRect(SkRect::MakeXYWH(0, 0, 100, 100 ));
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 ks , 150 ks ,
143 sh ininess, 151 sh ininess,
144 in put, 152 in put,
145 cr ))->unref(); 153 cr ))->unref();
146 drawClippedBitmap(canvas, paint, 220, y); 154 drawClippedBitmap(canvas, paint, 220, y);
147 155
148 y += 110; 156 y += 110;
149 } 157 }
150 } 158 }
151 159
160 bool onAnimate(const SkAnimTimer& timer) override {
161 static const SkScalar kDesiredDurationSecs = 15.0f;
162
163 fAzimuth = kStartAzimuth + timer.scaled(360.0f/kDesiredDurationSecs, 360 .0f);
164 return true;
165 }
166
152 private: 167 private:
168 static const int kStartAzimuth = 225;
169
153 SkBitmap fBitmap; 170 SkBitmap fBitmap;
171 SkScalar fAzimuth;
154 172
155 typedef GM INHERITED; 173 typedef GM INHERITED;
156 }; 174 };
157 175
158 ////////////////////////////////////////////////////////////////////////////// 176 //////////////////////////////////////////////////////////////////////////////
159 177
160 DEF_GM(return new ImageLightingGM;) 178 DEF_GM(return new ImageLightingGM;)
161 } 179 }
OLDNEW
« no previous file with comments | « gm/dashcircle.cpp ('k') | gm/stringart.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698