Tuesday, 19 August 2008

Just draw something on the f-ing screen

I don't believe that computers have got better over the past 40 years.

Case in point: I've spent at least 2 hours trying to debug a Gtk program which is supposed to plot some dots on the screen. Like this sort of thing in barely remembered ZX Spectrum BASIC:

10 FOR F = 0 TO 2*PI STEP 0.1
20 PLOT SIN(F)*200+100, COS(F)*200+100

The Gtk program is 20 times longer than this. And refuses to draw anything except a black window.

Computers have got worse in many ways since my first computer.


My angry late-night programming rant makes it to reddit.

Ob-awesome Wikipedia page of the week: List of 8 bit computer hardware palettes.


Chris said...

There is hope - http://processing.org/

Yaron Minsky said...

I'm not sure how much consolation it is, but the graphics module, for all its limitations, is fairly lightweight. Not quite as lightweight as your ZX program, but a lot better than GTK...

Prophet5 said...

I don't think that computers got worse, but the level of entry into programming is much higher now.

My first computer was a TI99/4A, which didn't even have graphics commands. But the default mode was also the BASIC shell.

On the other hand it is much easier now to learn stuff with all the open source around. No more typing in pages of code from a magazine.

Sanny Sanoff said...

Typing in from the magazine is what brought up many programmers those years. Program which you typed with your fingers forces you to really do something with it before you press reset.

Avik Das said...

I'm not sure about this day and age, what with everyone having a Facebook or a blog, but just a couple of years ago, web design was a fun and easy springboard to programming. That's how I started.

schlenk said...

GTK+, wrong tool for the job.

Try this in Tcl/Tk(or use labtk from ocaml, same thing)

package require Tk
package require math::constants
pack [canvas .c ] -expand 1 -fill both

for {set f 0.0} {$f < 2*$::math::constants::pi} {set f [expr {$f + 0.1}]} {
set x [expr {sin($f)*200+100}]
set y [expr {cos($f)*200+100}]
.c create rectangle $x $y $x $y

or nicer with plottools...

Andrew Bent said...

Have you tried Mono and GTK#? I imagine this would make things easier for you.

Google said...

From reddit:

"What stunning naivette. Both on the part of the article and the comments here. Throw a childish temper tantrum when you try to do the first thing with a computer. "Wah! My toy is broken!" Well, why don't you just throw it across the room and shatter it on the wall, then?

FYI: GTK is intended as more of a widgets/toolkit. Run (a) any language that will use SDL, where drawing a line or a pixel really is that simple, or, (b) Run QBasic on DOSBox. There. And change your dydee."

Richard Jones said...

To Andrew Bent:

I'm actually using ocaml + lablgtk, although that's not relevant to the problem.

Michael said...

I pretty much agree with you, as proramming languages have gotten better, the amount of fun I have with them compared to what I did with GW-Basic and QBasic does not grow at the same rate.

I really wonder if we can hook kids in the right age range when the barrier for entry of various things keep going up and more and more knowledge of various libraries are required.

Who seriously recommended SDL? SDL Parachute deployed! Oh noes!

Brian said...

Try http://www.scipy.org/ and/or http://matplotlib.sourceforge.net/

Ruben said...

You could check out FreeBASIC http://www.freebasic.net/about

jasper said...

I agree, if you use the right libraries, it does not need to be that hard.

I disagree that computer languages have improved. Simply too few languages learn from lisp. S-expressions are the natural way to express things, and they allow for macros.

Flying Frog Consultancy Ltd. said...

This is precisely the problem that our Smoke Vector Graphics product solved.

durandal said...

That precise frustration is why I wrote PNGwriter.


It does not do exactly what you want here (plots to a file rather than to the screen) but the motivation is the same.



kordless said...

I was just talking to a coworker about this a few days ago. His son did an internship in the office, and we were talking about trying to draw stuff on the screen quickly like you could with basic back in the day.

Nowadays the screen is managed by complicated code, so you are forced into using something that has a window you can draw in. On the Mac, you can use a program called NodeBox, which uses Python as it's base language.

I'm sure there are similar programs out for Windows. Perhaps someone can suggest one?

doswheeler said...

I dunno about that. I had my Commodore 64 fired up yesterday and was playing with it for a while. I remember thinking to myself, boy PCs have come a LONG ways!


delibaltas said...

We had the same first computer!!

Super said...

I know what you mean. I suffered similar frustration when trying out libSDL and finding it doesn't have a function for simply plotting a pixel.

Nowadays I occasionally use FreeBasic for prototyping graphics routines. I hate using Basic, but at least you can just do SCREEN 13 and start PSETing.

Luke Crook said...

Your example in Lisp, using lispbuilder-sdl.


desrt said...

the only annoying part about it is that python doesn't have support for iterating over floats -- so you have to use ints and convert.

for example:

import math, gtk

class Plot (gtk.Window):
__gtype_name__ = 'Plot'

def do_expose_event (self, event):
cr = self.window.cairo_create ()

for i in range (0, 201):
f = (i / 100.0) * math.pi
cr.line_to (math.sin (f) * 100 + 200, math.cos (f) * 100 + 200)


Plot ().show ()
gtk.main ()

Richard Jones said...

Thanks desrt and many others for the examples and positive comments.

I should say that the silly BASIC code in the posting is just an example. The real function I'm trying to plot is Barry Martin's Attractor a.k.a. hopalong.

I just wanted to show the wife how these were generated from such simple code ...

Well ... that idea turned into a bit of a saga.

I also hoped to turn this into a fast, parallel hopalong explorer, where my new 8-core AMD machine could actually get some exercise visualizing how the attractor changes as you change the input A/B/C parameters in real time. Of course that requires a serious programming language - C or OCaml - and a proper graphics toolkit to handle the user interaction - hence Gtk.

julian.lawton said...

Seeing as this is turning into 'list every graphics library /language you can think of' I'd like to throw in :

Context Free - http://www.contextfreeart.org/
Similar to processing and Nodebox in concept

Shoes (Ruby) - code.whytheluckystiff.net/shoes/
Does full apps but an attempt at creating a simple slimmed down app framework.

Or from the same chap, Hackety Hack ('whither art thou basic').

I'd second the recommendation for Nodebox - while it is OS X only (due to it extending a lot from Cocoa's drawing APIs) there is a cut-down beta Java version, which is good enough for simple drawing, and searching turns up a Linux/Qt port in progress.