Archive for the ‘ CG ’ Category

Merry Christmas!

DSC05512

…and a happy new year, from my family to yours.

Arduino + Electronic Brick Chassis V1.1 + Electronic Brick LCD 16*2 + below code = above image.

// It's an Arduino LCD Christmas
// AK Eric - 2009-12-24
#include <LiquidCrystal.h>

LiquidCrystal lcd(10, 11, 12, 13, 14, 15, 16);

void setup(){
    lcd.begin(16, 2);
    lcd.clear();
    lcd.print("MERRY CHRISTMAS!");
    lcd.setCursor(0,1);
    lcd.print(" www.AKEric.com");     
}

void loop(){
}

Got the Electronic Brick

ElectronicBrick01

The Electronic Brick Kit

Recently at the Maker Shed I found the ‘Electronic Brick‘ starter kit for Arduino.

The Electronic Brick kit is made by Seeed Studio, (yes, that’s three e’s) you can find it on their homepage here as well.  Online docs (pdf) are available for it.  In addition to the components in the kit, they sell many others that plug into it.

In a nutshell, it provides a shield for the Arduino, and a bunch of modular plug+play components allowing you to easily prototype simple electronics.  The docs show how to integrate these components with Arduino’s programming language.  Which is based on Wiring (implemented in C/C++), which in turn is very similar to Processing (Java).

I’d been looking for something like this for some time:  I’ve been wanting to make some more interesting things with my Arduino, but trying to by hand solder all the required components takes more time and know-how than I want to currently invest.  Plug+play = good.  And a nice project over the Christmas break :)

Arduino01

The Arduino!

Compare Jython and Java swing authoring

Since I’m teaching myself Java, and recently installed Jython, I thought it would be interesting to compare the two for authoring swing UI’s.  To aid in this development, I got the PyDev plugin for Eclipse installed, allowing for me to use Eclipse as an IDE for Jython and Python, nice.  FYI, I am by no means an expert at swing, or Java.  But the examples do work :)

Both examples display identical “Hello World!” window.

Here’s the Jython:

# texttest.py
from javax.swing import *
from java.awt import *

class TextTest(JFrame):
    def __init__(self):
        JFrame.__init__(self, "TextTest")
        self.setSize(256, 128)
        self.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
        pane = HelloPane()
        self.add(pane)
        self.setVisible(True)

class HelloPane(JPanel):
    def paintComponent(self, comp):
        f = Font("Arial", Font.PLAIN, 32)
        comp.setFont(f)
        comp.drawString("Hello World!", 32, 64)

if __name__ == "__main__":
    tt = TextTest()

And here’s the Java:

// TextTest.java
import javax.swing.*;
import java.awt.*;

public class TextTest extends JFrame {
    public TextTest() {
        super("TextTest");
        setSize(256, 128);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        HelloPane pane = new HelloPane();
        add(pane);
        setVisible(true);
    }

    public static void main(String[] arguments) {
        TextTest frame = new TextTest();
    }
}

class HelloPane extends JPanel {
    public void paintComponent(Graphics comp) {
        Graphics2D comp2D = (Graphics2D)comp;
        Font f = new Font("Arial", Font.PLAIN, 32);
        comp2D.setFont(f);
        comp2D.drawString("Hello World!", 32, 64);
    }
}

Jython

jythonAs I delve deeper into my new ‘Learning Java Book‘, I continue to miss Python more and more.  Not that I don’t find Java an impressive language; it’s amazing what us humans can come up with.  But considering I learned Python first, Java (and every other languange I’ve ran into) seem… less desirable in comparison.  I know them’s fightin’ words in some parts, but hey, this is my blog.

I’d known about Jython for some time, but it finally clicked in my head:  Why not try it?  It’s Java, but it acts like Python.  After an easy download and installation, I fired up it’s ‘jython.bat’ file (on WinXP) and there before me was the Python (er… I mean Jython) prompt.  It was an eerie feeling using an interactive  Jython shell to import ‘javax.swing’ and make a simple UI, but it worked flawlessly.  And so much easier than having to jump through all those Java hoops requiring you to make extraneous classes, etc.

From an online tutorial:

jythonShell

Thus creates:

jythonWindow

I’m not sure where Jython will take me, but it sure makes me warm up to Java more :)  Next step will be to get it running in Eclipse

Two new books added to the library…

Got to make use of some 40% off coupons at Barnes & Nobel today:

  • Algorithms in a Nutshell : I’d been eying this book for a while now, finally took the plunge.  I’m particularly interested in their chapters about convex hull generation, and path-finding AI.  The problem-solving techniques in general I find quite fascinating.
  • Visualizing Data : By Ben Fry, one of the co-creators of Processing.  I find this interesting not only in the code-examples behind displaying data to the screen, but the processes behind finding and parsing the data in the first place.  Also serves as a good bridge between Processing and Java, with examples of running Processing in Eclipse (see my post here).