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

Side by Side Diff: sky/examples/raw/painting.dart

Issue 1188823008: Resurrect painting.sky example as painting.dart. (Closed) Base URL: git@github.com:/domokit/mojo.git@master
Patch Set: as sky Created 5 years, 6 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 | « no previous file | no next file » | 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.PictureRecorder context = new sky.PictureRecorder(sky.view.width, 200.0);
11
12 sky.Paint paint = new sky.Paint();
13 sky.Point mid = new sky.Point(context.width / 2.0, context.height / 2.0);
14 double radius = math.min(mid.x, mid.y);
15
16 context.drawPaint(new sky.Paint()..color = const sky.Color(0xFFFFFFFF));
17
18 context.save();
19
20 context.translate(-mid.x/2.0, context.height*2.0);
21 context.clipRect(
22 new sky.Rect.fromLTRB(0.0, -context.height, context.width, radius));
23
24 context.translate(mid.x, mid.y);
25 paint.color = const sky.Color.fromARGB(128, 255, 0, 255);
26 context.rotate(math.PI/4.0);
27
28 sky.Gradient yellowBlue = new sky.Gradient.linear(
29 [new sky.Point(-radius, -radius), new sky.Point(0.0, 0.0)],
30 [const sky.Color(0xFFFFFF00), const sky.Color(0xFF0000FF)]);
31 context.drawRect(new sky.Rect.fromLTRB(-radius, -radius, radius, radius),
32 new sky.Paint()..setShader(yellowBlue));
33
34 // Scale x and y by 0.5.
35 var scaleMatrix = new Float32List.fromList([
36 0.5, 0.0, 0.0, 0.0,
37 0.0, 0.5, 0.0, 0.0,
38 0.0, 0.0, 0.0, 0.0,
39 0.0, 0.0, 0.0, 1.0,
40 ]);
41 context.concat(scaleMatrix);
42 paint.color = const sky.Color.fromARGB(128, 0, 255, 0);
43 context.drawCircle(0.0, 0.0, radius, paint);
44
45 context.restore();
46
47 context.translate(0.0, 50.0);
48 var builder = new sky.LayerDrawLooperBuilder()
49 ..addLayerOnTop(
50 new sky.DrawLooperLayerInfo()
51 ..setOffset(const sky.Point(150.0, 0.0))
52 ..setColorMode(sky.TransferMode.src)
53 ..setPaintBits(sky.PaintBits.all),
54 (sky.Paint layerPaint) {
55 layerPaint.color = const sky.Color.fromARGB(128, 255, 255, 0);
56 layerPaint.setColorFilter(new sky.ColorFilter.mode(
57 const sky.Color.fromARGB(128, 0, 0, 255), sky.TransferMode.srcIn));
58 layerPaint.setMaskFilter(new sky.MaskFilter.blur(
59 sky.BlurStyle.normal, 3.0, highQuality: true));
60 })
61 ..addLayerOnTop(
62 new sky.DrawLooperLayerInfo()
63 ..setOffset(const sky.Point(75.0, 75.0))
64 ..setColorMode(sky.TransferMode.src)
65 ..setPaintBits(sky.PaintBits.shader),
66 (sky.Paint layerPaint) {
67 sky.Gradient redYellow = new sky.Gradient.radial(
68 new sky.Point(0.0, 0.0), radius/3.0,
69 [const sky.Color(0xFFFFFF00), const sky.Color(0xFFFF0000)],
70 null, sky.TileMode.mirror);
71 layerPaint.setShader(redYellow);
72 // Since we're don't set sky.PaintBits.maskFilter, this has no effect.
73 layerPaint.setMaskFilter(new sky.MaskFilter.blur(
74 sky.BlurStyle.normal, 50.0, highQuality: true));
75 })
76 ..addLayerOnTop(
77 new sky.DrawLooperLayerInfo()..setOffset(const sky.Point(225.0, 75.0)) ,
78 (sky.Paint layerPaint) {
79 // Since this layer uses a DST color mode, this has no effect.
80 layerPaint.color = const sky.Color.fromARGB(128, 255, 0, 0);
81 });
82 paint.setDrawLooper(builder.build());
83 context.drawCircle(0.0, 0.0, radius, paint);
84
85 sky.view.picture = context.endRecording();
86 }
87
88 void main() {
89 sky.view.setBeginFrameCallback(beginFrame);
90 sky.view.scheduleFrame();
91 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698