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

Side by Side Diff: sky/sdk/lib/example/raw/painting.dart

Issue 1210173004: Move examples to //sky/sdk/example (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 5 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 | « sky/sdk/lib/example/raw/launcher.dart ('k') | sky/sdk/lib/example/raw/pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 import 'dart:sky' as sky;
6 import 'dart:math' as math;
7 import 'dart:typed_data';
8
9 void beginFrame(double timeStamp) {
10 sky.Size size = new sky.Size(sky.view.width, sky.view.height);
11 sky.PictureRecorder recorder = new sky.PictureRecorder();
12 sky.Canvas canvas = new sky.Canvas(recorder, size);
13
14 sky.Paint paint = new sky.Paint();
15 sky.Point mid = size.center(sky.Point.origin);
16 double radius = size.shortestSide / 2.0;
17
18 canvas.drawPaint(new sky.Paint()..color = const sky.Color(0xFFFFFFFF));
19
20 canvas.save();
21
22 canvas.translate(-mid.x/2.0, sky.view.height*2.0);
23 canvas.clipRect(
24 new sky.Rect.fromLTRB(0.0, -sky.view.height, sky.view.width, radius));
25
26 canvas.translate(mid.x, mid.y);
27 paint.color = const sky.Color.fromARGB(128, 255, 0, 255);
28 canvas.rotate(math.PI/4.0);
29
30 sky.Gradient yellowBlue = new sky.Gradient.linear(
31 [new sky.Point(-radius, -radius), new sky.Point(0.0, 0.0)],
32 [const sky.Color(0xFFFFFF00), const sky.Color(0xFF0000FF)]);
33 canvas.drawRect(new sky.Rect.fromLTRB(-radius, -radius, radius, radius),
34 new sky.Paint()..setShader(yellowBlue));
35
36 // Scale x and y by 0.5.
37 var scaleMatrix = new Float32List.fromList([
38 0.5, 0.0, 0.0, 0.0,
39 0.0, 0.5, 0.0, 0.0,
40 0.0, 0.0, 0.0, 0.0,
41 0.0, 0.0, 0.0, 1.0,
42 ]);
43 canvas.concat(scaleMatrix);
44 paint.color = const sky.Color.fromARGB(128, 0, 255, 0);
45 canvas.drawCircle(sky.Point.origin, radius, paint);
46
47 canvas.restore();
48
49 canvas.translate(0.0, 50.0);
50 var builder = new sky.LayerDrawLooperBuilder()
51 ..addLayerOnTop(
52 new sky.DrawLooperLayerInfo()
53 ..setOffset(const sky.Offset(150.0, 0.0))
54 ..setColorMode(sky.TransferMode.src)
55 ..setPaintBits(sky.PaintBits.all),
56 (sky.Paint layerPaint) {
57 layerPaint.color = const sky.Color.fromARGB(128, 255, 255, 0);
58 layerPaint.setColorFilter(new sky.ColorFilter.mode(
59 const sky.Color.fromARGB(128, 0, 0, 255), sky.TransferMode.srcIn));
60 layerPaint.setMaskFilter(new sky.MaskFilter.blur(
61 sky.BlurStyle.normal, 3.0, highQuality: true));
62 })
63 ..addLayerOnTop(
64 new sky.DrawLooperLayerInfo()
65 ..setOffset(const sky.Offset(75.0, 75.0))
66 ..setColorMode(sky.TransferMode.src)
67 ..setPaintBits(sky.PaintBits.shader),
68 (sky.Paint layerPaint) {
69 sky.Gradient redYellow = new sky.Gradient.radial(
70 new sky.Point(0.0, 0.0), radius/3.0,
71 [const sky.Color(0xFFFFFF00), const sky.Color(0xFFFF0000)],
72 null, sky.TileMode.mirror);
73 layerPaint.setShader(redYellow);
74 // Since we're don't set sky.PaintBits.maskFilter, this has no effect.
75 layerPaint.setMaskFilter(new sky.MaskFilter.blur(
76 sky.BlurStyle.normal, 50.0, highQuality: true));
77 })
78 ..addLayerOnTop(
79 new sky.DrawLooperLayerInfo()..setOffset(const sky.Offset(225.0, 75.0) ),
80 (sky.Paint layerPaint) {
81 // Since this layer uses a DST color mode, this has no effect.
82 layerPaint.color = const sky.Color.fromARGB(128, 255, 0, 0);
83 });
84 paint.setDrawLooper(builder.build());
85 canvas.drawCircle(sky.Point.origin, radius, paint);
86
87 sky.view.picture = recorder.endRecording();
88 }
89
90 void main() {
91 sky.view.setBeginFrameCallback(beginFrame);
92 sky.view.scheduleFrame();
93 }
OLDNEW
« no previous file with comments | « sky/sdk/lib/example/raw/launcher.dart ('k') | sky/sdk/lib/example/raw/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698