Author Archives: admin

Clojure GUI demo of Asteroids Game

Clojure GUI Demo of Asteroids

Zach Tellman has done a masterful job on the Penumbra library – another example of this is the Asteroids game.

You can see the code on git hub here. You can click here to launch via web start.

Clojure GUI Demo of Asteroids game

Clojure GUI Demo of LED Timer

Webstart Launch of Clojure GUI demo of LED Timer

 

U2 sang a song called ‘Stuck in a Moment’. You can ponder this as you watch this LCD timer demo by icyrock.

You can launch it via web start here. You can see the code here.

Clojure GUI Demo of LED Timer

Clojure GUI Demo of 3D Teapot

Launch Webstart of Clojure 3D GUI Demo of a Pot of Tea

 

George Orwell had lots to say on what made the perfect cup of tea. You can ponder this too whilst you watch Zach Tellerman’s Clojure 3D teapot demo.

Click this link to launch. You can view the source code here.

Clojure 3D GUI Demo of a Pot of Tea

 

Clojure GUI Demo of Game of Life

 

Get creature URLs here.

Alex Miller created a Clojure demo of Game of Life.

Dave Ray ported it to his Seesaw Clojure Swing library.

You can start it via webstart here. The code is available on github here.

Clojure GUI Demo of a Fractal Tree

Launch Clojure GUI demo of Fractal Tree

Did you know that ferns are fractal in nature? You can represent them using a recursive algorithm. What better way to run such an algorithm, than in Clojure on your own JVM at home:

Image of a Fractal Tree in Clojure

This one was originally written by Stuart Halloway here.

You can start it via web start here.  You can view the code here.

Clojure GUI Demo of Black-Scholes

Launch Clojure GUI demo of Black Scholes

If you’ve not heard of Black Scholes don’t fear. The equation exists in the world of Financial Services, in particular Options trading. It’s purpose is to calculate a price for a set of options given a model of a financial market containing derivative instruments.

clojure-black-scholes screenshot

 

Paul Legatohas written up a fantastic post on writing a GUI Demo for Scholes Black in Clojure.

You can start it via web start here. You can view the code here.

Clojure GUI Demo of Tetris (via Web Start)

Launch Clojure GUI demo of Tetris

Tetris is an old favourite, that I first played on a friend’s Nintendo Entertainment system. This version come to us from Alex Yakushev via Clojure.

Screenshot of the Clojure GUI demo of tetris

You can play it via the following Web Start link. You can see the code on github here.

The game was originally written by Alexey Pajitnov when working for the Soviet Government. He named it after the Greek word tetra, meaning four, and his favourite game tennis.

The great thing about Alex Y’s writing style is that he puts heaps of effort into sequentially explaining what he is trying to say. You can see more of this when he talks about sockets in Clojure

Clojure GUI Web Start Demo of Snake (The Game)

Launch Clojure GUI Demo of Snake

This is a Clojure demo of the game of Snake, probably best known for its inclusion on the Nokia phone, and also played on the Commodore 64.

Screenshot

You can start it via web start here. You can view the source code here.

This version was written by Stuart Halloway here, and included in his excellent book Programming Clojure.

Clojure GUI demo of Pong

Launch Clojure GUI Demo of Pong

This is a Clojure demo of pong available via Java Web Start. You can see it by clicking the link here.
Clojure GUI Pong Game screenshot

You can see the source code here.

This is a fork from Juan Manuel Gimeno on Github who in turn forked it from Caesar Canassa’s repository on bitbucket.

His blog post launching it is here. (It’s a fun story – couple of mates and some beers on a Saturday night get hacking, upload a demo the following day.) Top work boys!

My intention was to add Java Web start to enable it to be demoed to a wider audience and promote the clojure community.

Applets in Clojure and Counterclockwise

Has anybody looked at Applets since 1997 and Java 1.1? Why would you want to do this?

There are a couple of reasons:

  1. Clojure rocks. You want to show people online what your Clojure code is doing, without having them read the code, or interact with another servlet through a browser.
  2. The reality is that the tooling and libraries for the JVM are superior to Flash and Javascript, and will probably remain so for some time.

Isn’t Clojurescript Cooler?

Yes – but at this point in time is less ‘production ready’ than the main Clojure release.

But haven’t people done this online already?

They have. But there is no good lifecycle for testing it in Counterclockwise (or your REPL of choice).  There is no way to change the code and easily debug it,  without going through a full code->compile->deploy cycle.

In Eclipse for Java Applets, you can just extend the Applet, and then right-click and select ‘run as Applet’. In Clojure (as these examples show) you can also extend the Applet. But there is no easy way to ‘Run as Applet’. Simply executing the Clojure code doesn’t start it either.

So what does the basic Applet look like?

SimpleSwingApplet.clj
(ns demo.applet.SimpleSwingApplet
      (:import
        (javax.swing JApplet JPanel JLabel JFrame))
      (:gen-class
        :post-init post-init
        :extends javax.swing.JApplet))

(defn -post-init [this]
  (def jpanel (JPanel.))
  (.add jpanel (JLabel. "This is my first applet"))
  (.setContentPane this jpanel))

Now that’s what the other two blogs had. Great – but if you run that on your Clojure REPL, you’ll get a big fat nothing. So this is where we start adding value.

Here is what we’ll add to make it run in Counterclockwise (or your REPL of choice).

SimpleSwingAppletRunner.clj
(ns game.applet.SimpleSwingAppletRunner
  (:import
        (javax.swing JApplet JPanel JLabel JFrame)))

;------
(compile 'game.applet.SimpleSwingApplet)

(defn -main [s]
  (let [applet (new demo.applet.SimpleSwingApplet)]
    (doto (JFrame. "MyApplet")
      (.add (.getContentPane applet))
      (.pack)
      (.setLocationByPlatform true)
      (.setDefaultCloseOperation JFrame/EXIT_ON_CLOSE)
      (.setVisible true))     
    ))

(-main "s")

Basically we instantiate the Applet and then get the contentPane which we pass to a newly created a Frame.