jsyedidia / nugraphdraw

A graph drawing application. An example PyObjC application re-written in Nu. Original by Aaron Hillegass, ported to Nu by Jonathan Yedidia.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NuGraphDraw

Jonathan Yedidia, May 31, 2008.

This project is a port from PyObjC to Nu, with enhancements, of Aaron Hillegass' 
"GraphLaughs" application. 

Pre-requisites are Mac OS X Leopard and the Nu programming language, developed by
Tim Burks and available at http://programming.nu. Build this application in XCode.

"GraphLaughs" was described in the June 8, 2006 post of the Big Nerd Ranch weblog
at http://weblog.bignerdranch.com. You can download the source at
http://weblog.bignerdranch.com/pythonex/GraphLaughs.tgz.

This type of application shows off some of the advantages of a dynamic language like Nu.
One can let the user extend the application at run-time with his own scripts.

Aaron wrote that "The Python bridge (PyObjC) is still a bit mysterious to me, 
but I can see that they have done a great job leveraging the dynamic nature of 
both languages to make it easy to work with."

I believe the Nu version is a significant improvement over the PyObjC version.
Nu and Objective-C can inter-operate in a completely seamless way, and there are
no mysteries, because Nu was designed from the start to work with Cocoa and Objective-C.

There are two versions of the application here. GraphDraw_Mixed is a mixed Nu and
objective-C application, which demonstrates how Objective-C and Nu classes can
be included in the same application, and inter-operate. This version is closer
to Hillegass' original. 

GraphDraw_Nu, on the other hand, is written completely in Nu. I've also added
some hooks for you to use in the Nu console (or the textView where you put
your scripts.) You can call up the console with command-L. You can access the view 
with the global variable $view or access the graph with the global variable $graph. 
You can change the colors of the nodes, edges, or background, or change the size of 
the nodes or the width of the edges. 

For example, try this in the Nu console, after evaluating the initial script:
($view setNodeSize:20)
($view setEdgeColor:(NSColor greenColor))

The defaults, which can be found in main.nu, are:
edgeColor: (NSColor whiteColor)
nodeColor: (NSColor redColor)
backgroundColor: (NSColor darkGrayColor)
edgeWidth: 0.9
nodeSize: 6

Of course, it's even more fun to change the graph by re-writing the default script.
Try changing some of the "magic numbers" like one or both of the 180's, the 300, or the 10.

If you are interested in seeing more Cocoa applications written in Nu, go to the
the git repository at
git://github.com/timburks/cocoa-programming-with-nu.git, or look at other examples
posted by Tim Burks at github.com or the examples that come bundled with Nu.


TODO:
Parens-matching in the scriptTextView.
Better descriptions of script errors.

If you are interested in fixing these problems, or otherwise improving the application,
please fork the repository, then improve it, and then send me a pull request.

Thanks,
Jonathan Yedidia

About

A graph drawing application. An example PyObjC application re-written in Nu. Original by Aaron Hillegass, ported to Nu by Jonathan Yedidia.


Languages

Language:Nu 63.6%Language:Objective-C 36.4%