1cb93a386Sopenharmony_ci// Copyright 2020 Google LLC. 2cb93a386Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. 3cb93a386Sopenharmony_ci#include "tools/fiddle/examples.h" 4cb93a386Sopenharmony_ciREG_FIDDLE(SkPath_cubicTo_example, 512, 512, false, 0) { 5cb93a386Sopenharmony_ci/* 6cb93a386Sopenharmony_ci If the starting point is (x0, y0), then this curve is defined as the 7cb93a386Sopenharmony_ci paramentric curve as `t` goes from 0 to 1: 8cb93a386Sopenharmony_ci s := 1 - t 9cb93a386Sopenharmony_ci x := (s * s * s * x0) + 10cb93a386Sopenharmony_ci (3 * s * s * t * x1) + 11cb93a386Sopenharmony_ci (3 * s * t * t * x2) + 12cb93a386Sopenharmony_ci (t * t * t * x3) 13cb93a386Sopenharmony_ci y := (s * s * s * y0) + 14cb93a386Sopenharmony_ci (3 * s * s * t * y1) + 15cb93a386Sopenharmony_ci (3 * s * t * t * y2) + 16cb93a386Sopenharmony_ci (t * t * t * y3) 17cb93a386Sopenharmony_ci 18cb93a386Sopenharmony_ci*/ 19cb93a386Sopenharmony_civoid draw(SkCanvas* canvas) { 20cb93a386Sopenharmony_ci canvas->clear(SkColorSetARGB(255, 255, 255, 255)); 21cb93a386Sopenharmony_ci SkFont font(nullptr, 32); 22cb93a386Sopenharmony_ci 23cb93a386Sopenharmony_ci SkPaint paint; 24cb93a386Sopenharmony_ci paint.setAntiAlias(true); 25cb93a386Sopenharmony_ci paint.setStyle(SkPaint::kStroke_Style); 26cb93a386Sopenharmony_ci paint.setStrokeWidth(5); 27cb93a386Sopenharmony_ci 28cb93a386Sopenharmony_ci SkPoint a{128, 64}; 29cb93a386Sopenharmony_ci SkPoint b{448, 448}; 30cb93a386Sopenharmony_ci SkPoint c{64, 448}; 31cb93a386Sopenharmony_ci SkPoint d{384, 64}; 32cb93a386Sopenharmony_ci 33cb93a386Sopenharmony_ci SkPath threeSegments; 34cb93a386Sopenharmony_ci threeSegments.moveTo(a); 35cb93a386Sopenharmony_ci threeSegments.lineTo(b); 36cb93a386Sopenharmony_ci threeSegments.lineTo(c); 37cb93a386Sopenharmony_ci threeSegments.lineTo(d); 38cb93a386Sopenharmony_ci 39cb93a386Sopenharmony_ci canvas->drawPath(threeSegments, paint); 40cb93a386Sopenharmony_ci 41cb93a386Sopenharmony_ci paint.setColor(SkColorSetARGB(255, 0, 0, 255)); 42cb93a386Sopenharmony_ci SkPath cubicCurve; 43cb93a386Sopenharmony_ci cubicCurve.moveTo(a); 44cb93a386Sopenharmony_ci cubicCurve.cubicTo(b, c, d); 45cb93a386Sopenharmony_ci canvas->drawPath(cubicCurve, paint); 46cb93a386Sopenharmony_ci 47cb93a386Sopenharmony_ci SkPaint textPaint; 48cb93a386Sopenharmony_ci textPaint.setColor(SkColorSetARGB(255, 0, 255, 0)); 49cb93a386Sopenharmony_ci textPaint.setAntiAlias(true); 50cb93a386Sopenharmony_ci canvas->drawString("a", a.x(), a.y(), font, textPaint); 51cb93a386Sopenharmony_ci canvas->drawString("b", b.x(), b.y(), font, textPaint); 52cb93a386Sopenharmony_ci canvas->drawString("c", c.x() - 20, c.y(), font, textPaint); 53cb93a386Sopenharmony_ci canvas->drawString("d", d.x(), d.y(), font, textPaint); 54cb93a386Sopenharmony_ci} 55cb93a386Sopenharmony_ci} // END FIDDLE 56