2013-09-19 15:32:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gm.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkPath.h"
|
|
|
|
|
|
|
|
// Reproduces https://code.google.com/p/chromium/issues/detail?id=279014
|
|
|
|
|
2013-09-19 17:21:39 +00:00
|
|
|
static const int kWidth = 640;
|
|
|
|
static const int kHeight = 480;
|
2013-09-19 15:32:22 +00:00
|
|
|
static const SkScalar kAngle = 0.305f;
|
|
|
|
|
|
|
|
// Renders a string art shape.
|
|
|
|
// The particular shape rendered can be controlled by adjusting kAngle, from 0 to 1
|
|
|
|
|
|
|
|
class StringArtGM : public skiagm::GM {
|
|
|
|
public:
|
|
|
|
StringArtGM() {}
|
|
|
|
|
|
|
|
protected:
|
2014-04-30 13:20:45 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2013-09-19 15:32:22 +00:00
|
|
|
return SkString("stringart");
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2013-09-19 15:32:22 +00:00
|
|
|
return SkISize::Make(kWidth, kHeight);
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2013-09-19 15:32:22 +00:00
|
|
|
SkScalar angle = kAngle*SK_ScalarPI + SkScalarHalf(SK_ScalarPI);
|
2013-09-19 17:21:39 +00:00
|
|
|
SkScalar size = SkIntToScalar(SkMin32(kWidth, kHeight));
|
2013-09-19 15:32:22 +00:00
|
|
|
SkPoint center = SkPoint::Make(SkScalarHalf(kWidth), SkScalarHalf(kHeight));
|
|
|
|
SkScalar length = 5;
|
|
|
|
SkScalar step = angle;
|
|
|
|
|
|
|
|
SkPath path;
|
|
|
|
path.moveTo(center);
|
|
|
|
|
|
|
|
while (length < (SkScalarHalf(size) - 10.f))
|
|
|
|
{
|
|
|
|
SkPoint rp = SkPoint::Make(length*SkScalarCos(step) + center.fX,
|
|
|
|
length*SkScalarSin(step) + center.fY);
|
|
|
|
path.lineTo(rp);
|
|
|
|
length += SkScalarDiv(angle, SkScalarHalf(SK_ScalarPI));
|
|
|
|
step += angle;
|
|
|
|
}
|
|
|
|
path.close();
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setColor(0xFF007700);
|
|
|
|
|
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
DEF_GM( return new StringArtGM; )
|