Showing posts with label wpf. Show all posts
Showing posts with label wpf. Show all posts

Monday, 16 February 2009

EvoLisa "Viewer"

This post is related to Roger Alsing's EvoLisa (or GenArt, if you prefer) genetic algorithm. If you aren't familiar with it, read the FAQ and check out the Image Gallery.

Here's how it looks "in action": the image on the left is the 'source', on the right is the evolving polygon 'dna' (it gets gradually better as the dna evolves):

Actually that image is probably too complex to be a great example, sorry.

Anyway, that's old news. This post is because I've added a little piece of code to the 'ecosystem': a viewer for the .DNA files that also lets you save a high-resolution JPG copy. It was inspired by a couple of comments asking about exporting the images.

This is what the DNA Viewer looks like - on the left is a Xaml rendering, on the right is an Image. They both look the same - the interesting bit is comparing the code that generates each of them

The Image is generated by the existing Renderer class in Roger's source (which is also the logic used to save the JPG); the Canvas version uses a new (although very similar) WpfRenderer class. From that it was trivial to create the XamlRenderer which outputs a .xaml file which can be used to view the GenArt creation in Silverlight!


You can download a GeneticDNAViewer_1.0.zip (16Kb) ZIPped exe to play with, or the WpfApplication itself can be reconstructed with the original source and these c# files:
Window1.xaml, Window1.xaml.cs, WpfRenderer.cs and XamlRenderer.

You can test it by unZIPping operahouse6.dna.zip and opening the .dna file inside. I've uploaded a 3200x2032 copy of the image on Flickr to demonstrate the high-resolution output.

FYI, the relative file sizes are:
- operahouse6.dna 51.4Kb
- scene.xaml 17Kb
- operahouse6.jpg 371Kb

p.s. Roger has posted subsequent performance-related posts on EvoLisa, but I'm not sure he's released the source for them yet.

UPDATE [17-Feb-09] another example:
Opera House by day .DNA 49Kb (ZIPped 17Kb)
Opera House by day (Silverlight 17Kb)
Opera House by day (Flickr 1920x1440 162Kb)



While I was testing the new 'DNA', I added SvgRenderer as well (needs updated Window1.xaml.cs). At first it didn't seem to work (left image) because I couldn't figure out how to make the background black. Decided to draw a big black rectangle behind the rest (bit of a hack, but it works). You can view operahouse_day.svg.xml (21Kb) in Firefox.

Thursday, 15 January 2009

DeepZoom "Viewer"

My MIX09 Silverlight entry - exploDZ hasn't exactly set the voting world on fire :)

However I still think it's a useful concept, so a Wpf version is now available for download at deepzoompublisher.com/Viewer (zip).



It's pretty simple - open local or remote Deep Zoom Composer Xml output and browse around its contents. You can always try the Silverlight version too - here's a test Url to get started http://deepzoompublisher.com/ClientBin/Cities/dzc_output.xml

Wednesday, 2 April 2008

Loose Xaml (WPF and data binding)

Inspired by a no-longer-working (?) demo of Avalon Xaml (from 2004/05) by Joe Marini, I've put together this Loose Xaml sample blog reader with an RSS.XML feed from this blog.

It works in a browser, if you download the files (Xaml & rss) and run locally, or just check the screenshot:


The code is only 43 lines of markup (with breaks for readability!) - no C# or VB in sight.

I think exercises like this serve two purposes:

Firstly, helps to understand the databinding concepts in WPF
  <Canvas.Resources>
<XmlDataProvider x:Key="NewsData" Source="rss.xml" XPath="rss/channel" />
</Canvas.Resources>
<Canvas.DataContext>
<Binding Source="NewsData" XPath="rss/channel" />
</Canvas.DataContext>
also
Text="{Binding Source={StaticResource NewsData},XPath=description}"
and
    <StackPanel Margin="5" Width="500"
DataContext="{Binding ElementName=NewsList,Path=SelectedItem}">
<TextBlock DockPanel.Dock="Top" Text="Article Description:"/>
<TextBlock Margin="10" TextWrapping="Wrap" Name="SelectedItemDetails"
Text="{Binding XPath=description}" />
</StackPanel>
Secondly, helps structure your thinking around a UI that sits atop 'data services'
Quite a lot can be accomplished with Xaml markup - I think it would be interesting to see just how complex an 'application' could be created in a single Xaml file, using only databinding (and whatever server-side services you needed). WCF/REST could play a role (Syndication services... where's that link?).

The sandbox that loose Xaml sits in does present some problems... you can only load files from the origin, so no referencing RSS feeds from other servers. A middle-man pass-through (or other side-step) could get around that, however. It would seem trivial to create a fairly neat Gmail (or other service) reader; basically anything that publishes RSS (or any Xml, really). What is not clear to me just yet is whether it would be do-able to write a complete mail client, for example, following the same principles...


p.s. It's interesting to see how the databinding syntax changed, from "*Bind(XPath=author)" to "{Binding XPath=description}". Notice also how
TextContentText
XmlDataSourceXmlDataProvider
IDName
FlowPanelFlowDocument (?)
TextTextBlock
I think it's kinda cool to see the tools evolve like that - same now with Silverlight...

UPDATE: If you are wanting to use a datasource from ASMX or SVC, this post on XmlNamespaceManager will be useful. Once you start adding namespaces, the SelectedItem method I've used will break, and you'll want to read this post explaining the intricacies of {Binding} to Xml and the selected item.