backport this one too
[mono.git] / mcs / class / System.Drawing / Samples / General / hering.cs
1 //
2 // hering.cs 
3 // Creates image for Hering illusion.
4 // Converted to C# from Xr demo application.
5 //
6 // Author:
7 //   Alexandre Pigolkine(pigolkine@gmx.de)
8 // 
9 //
10 // Copyright (C) Ximian, Inc.  http://www.ximian.com
11 //
12 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
13 //
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
21 // 
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
24 // 
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 //
33
34 using System;
35 using System.Drawing;
36 using System.Drawing.Imaging;
37 using System.Drawing.Drawing2D;
38  
39 namespace MonoSamples.System.Drawing
40 {
41         public class Hering
42         {
43                 public static void Main (String[] args) {
44
45                         float width = 400.0F;
46                         float height = 800.0F;
47                         Bitmap bmp = new Bitmap ((int) width, (int) height);
48                         Graphics gr = Graphics.FromImage (bmp);
49                         gr.Clear (Color.White);
50
51                         int LINES = 32;
52                         float MAX_THETA  = (.80F * 90.0F);
53                         float THETA  = (2 * MAX_THETA / (LINES-1));
54
55                         GraphicsState oldState = gr.Save ();
56
57                         Pen blackPen = new Pen (Color.Black, 2.0F);
58                         gr.TranslateTransform (width / 2.0F, height / 2.0F);
59                         gr.RotateTransform (MAX_THETA);
60                         for ( int i = 0; i < LINES; i++) {
61                                 gr.DrawLine (blackPen, -2.0F * width, 0.0F, 2.0F * width, 0.0F);
62                                 gr.RotateTransform (-THETA);
63                         }
64
65                         gr.Restore (oldState);
66
67                         Pen redPen = new Pen (Color.Red, 6F);
68                         gr.DrawLine (redPen, width / 4F, 0F, width / 4F, height);
69                         gr.DrawLine (redPen, 3F * width / 4F, 0F, 3F * width / 4F, height);
70
71                         /* save image in all the formats */   
72                         bmp.Save ("hering.png", ImageFormat.Png);
73                         Console.WriteLine ("output file hering.png");
74                         bmp.Save ("hering.jpg", ImageFormat.Jpeg);
75                         Console.WriteLine ("output file hering.jpg");
76                         bmp.Save ("hering.bmp", ImageFormat.Bmp);
77                         Console.WriteLine ("output file hering.bmp");
78                 }
79         }
80 }