Terje Isaksen Developer blog

2010-02-14 (Sunday)

Projects: WPF Artist Phase One

Filed under: Developing,Project — Terje Isaksen @ 00:08
Tags: , , , ,

There is an artform which basically is when people throw paint, (“Abstract Expressionist – Kinetic Abstraction”, example: http://www.ecomall.com/zatar/) and this of course can be done with a computer as well.

Sample

"Art" made by this piece of code



WPF:

<Window x:Class="Graph.Window1"
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 Title="Window1" >
 <DockPanel LastChildFill="True">
 <StackPanel DockPanel.Dock="Top" Orientation="Horizontal"></StackPanel>
 <Grid x:Name="deGrid" DockPanel.Dock="Bottom" Background="AntiqueWhite" Height="800" Width="1600">

 </Grid>
 </DockPanel>
</Window>

Code behind:

using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace Graph
{
 /// <summary>
 /// Interaction logic for Window1.xaml
 /// </summary>
 public partial class Window1 : Window
 {
 DispatcherTimer timer = new DispatcherTimer();
 Random R = new Random(  );
 bool running = false;

 public Window1() {
 InitializeComponent();
 timer.Interval = TimeSpan.FromMilliseconds( 500 );
 timer.Tick += new EventHandler( timer_Tick );
 timer.Start();
 }

 private void timer_Tick( object sender , EventArgs e ) {
 Polyline imgNew = GetDrawing();
 this.deGrid.Children.Add( imgNew );
 this.deGrid.UpdateLayout();
 }

 Byte RandomByte() {
 Byte u = 0;  bool b = byte.TryParse( R.Next( 255 ).ToString() , out u );
 return u;
 }

 Color GetColor()  {
 byte A = RandomByte(); byte R = RandomByte();  byte G = RandomByte();   byte B = RandomByte();
 return Color.FromArgb( A , R , G , B );
 }

 Polyline GetDrawing(  ) {
 Color drawColor = GetColor();
 Brush drawBrush =  new SolidColorBrush(drawColor);
 Polyline u = new Polyline();
 u.StrokeThickness = R.Next(10);
 u.Stroke = drawBrush;

 double x0 = R.NextDouble() * deGrid.Width ;
 double y0 = R.NextDouble() * deGrid.Height ;
 double I = R.NextDouble() * 10000 ;

 for (int i=0; i<I; i++) {
 Point p = new Point( x0 , y0 );  u.Points.Add(p);

 x0 = x0 + R.Next( R.Next(10) ) - R.Next( R.Next(10) );
 if (x0<0) { x0 = 0; }  if (x0>deGrid.Width ) { x0 = deGrid.Width; }

 y0 = y0 + R.Next( R.Next(10) ) - R.Next( R.Next(10) );
 if (y0<0) { y0 = 0; }  if (y0>deGrid.Height) { y0 = deGrid.Height;}
 }
 u.ClipToBounds = true;
 return u;
 }

 }
}

If you become a well known artist using this software, please let me know. 😀

Blog at WordPress.com.