6 void OvalPath (Graphics ctx, double xc, double yc, double xr, double yr)
10 ctx.Translate (xc, yc);
11 ctx.Scale (1.0, yr / xr);
13 ctx.Arc (0, 0, xr, 0, 2 * Math.PI);
19 void FillChecks (Graphics ctx, int x, int y, int width, int height)
24 Surface check = ctx.Target.CreateSimilar (Content.Color, 2 * CHECK_SIZE, 2 * CHECK_SIZE);
27 Graphics cr2 = new Graphics (check);
28 cr2.Operator = Operator.Source;
29 cr2.Color = new Color (0.4, 0.4, 0.4);
30 cr2.Rectangle (0, 0, 2 * CHECK_SIZE, 2 * CHECK_SIZE);
33 cr2.Color = new Color (0.7, 0.7, 0.7);
34 cr2.Rectangle (x, y, CHECK_SIZE, CHECK_SIZE);
37 cr2.Rectangle (x + CHECK_SIZE, y + CHECK_SIZE, CHECK_SIZE, CHECK_SIZE);
41 // Fill the whole surface with the check
42 SurfacePattern check_pattern = new SurfacePattern (check);
43 check_pattern.Extend = Extend.Repeat;
44 ctx.Source = check_pattern;
45 ctx.Rectangle (0, 0, width, height);
48 check_pattern.Destroy ();
53 void Draw3Circles (Graphics ctx, int xc, int yc, double radius, double alpha)
55 double subradius = radius * (2 / 3.0 - 0.1);
57 ctx.Color = new Color (1.0, 0.0, 0.0, alpha);
58 OvalPath (ctx, xc + radius / 3.0 * Math.Cos (Math.PI * 0.5), yc - radius / 3.0 * Math.Sin (Math.PI * 0.5), subradius, subradius);
61 ctx.Color = new Color (0.0, 1.0, 0.0, alpha);
62 OvalPath (ctx, xc + radius / 3.0 * Math.Cos (Math.PI * (0.5 + 2 / 0.3)), yc - radius / 3.0 * Math.Sin (Math.PI * (0.5 + 2 / 0.3)), subradius, subradius);
65 ctx.Color = new Color (0.0, 0.0, 1.0, alpha);
66 OvalPath (ctx, xc + radius / 3.0 * Math.Cos (Math.PI * (0.5 + 4 / 0.3)), yc - radius / 3.0 * Math.Sin (Math.PI * (0.5 + 4 / 0.3)), subradius, subradius);
70 void Draw (Graphics ctx, int width, int height)
72 double radius = 0.5 * Math.Min (width, height) - 10;
76 Surface overlay = ctx.Target.CreateSimilar (Content.ColorAlpha, width, height);
77 Surface punch = ctx.Target.CreateSimilar (Content.Alpha, width, height);
78 Surface circles = ctx.Target.CreateSimilar (Content.ColorAlpha, width, height);
80 FillChecks (ctx, 0, 0, width, height);
83 // Draw a black circle on the overlay
84 Graphics cr_overlay = new Graphics (overlay);
85 cr_overlay.Color = new Color (0.0, 0.0, 0.0);
86 OvalPath (cr_overlay, xc, yc, radius, radius);
89 // Draw 3 circles to the punch surface, then cut
90 // that out of the main circle in the overlay
91 Graphics cr_tmp = new Graphics (punch);
92 Draw3Circles (cr_tmp, xc, yc, radius, 1.0);
95 cr_overlay.Operator = Operator.DestOut;
96 cr_overlay.SetSourceSurface (punch, 0, 0);
99 // Now draw the 3 circles in a subgroup again
100 // at half intensity, and use OperatorAdd to join up
102 Graphics cr_circles = new Graphics (circles);
103 cr_circles.Operator = Operator.Over;
104 Draw3Circles (cr_circles, xc, yc, radius, 0.5);
105 // cr_circles.Destroy ();
107 cr_overlay.Operator = Operator.Add;
108 cr_overlay.SetSourceSurface (circles, 0, 0);
110 // cr_overlay.Destroy ();
112 ctx.SetSourceSurface (overlay, 0, 0);
127 Surface s = new ImageSurface (Format.ARGB32, 400, 400);
128 Graphics ctx = new Graphics (s);
129 Draw (ctx, 400, 400);
130 s.WriteToPng ("knockout.png");