Ask the Box

29 sep 06

"Let's see some of your programming skills. What's your favorite program you have created."

My programs invariably consist of loops, random number generation, a few variables, and about 20 lines of code -- I've never written anything that could properly be considered a "program" (furthermore, I've never compiled anything in my life). The closest thing was probably my Python script that randomly chooses an image from a bank, randomly sizes it, and then prints eight of them on a randomly chosen background color. The design changed, because the differently-sized images took up different amounts of space, and sometimes pushed each other off the screen. Here, I'll stick it back on the server and set it up again (page will launch in a new window -- when it does, hit `reload` a few times). It makes for some nice designs -- the best things are always accidental, I find.

Actually, that's quite good, now that I look at it again. Sort of sad that I took down teeheehee.net, in its old form. But, I guess I was tired of it. I can't just have the same site sitting there for very long, for some reason. I'm sure "Ask the Box" is a temporary thing, just like everything else I've done. We'll see, I guess. Anyway, it's a Python script that generates HTML based on some loops and random numbers. I'll only reprint for you the lines that have some active Python in them, and omit the static print statements, which only spit out HTML.

The first significant line imports an object or library (or something) that enables Python to produce random-seeming integers.


	import random

This next bit initializes two variables with random integers within some bounds, and then another variable with a string represting an HTML color; which color depends on what value `background` ended up with:


	othernumber = random.randint(1,11)
	background = random.randint(1,20)
	
	if background == 1: 
		othercolor = "#735E5E"
	
	if background == 2:
		othercolor = "#735E64"
		

...etc (different colors, all the way down to 20).

Print out some CSS with `othercolor` as the link colors:


	print "a:link { color:"+str(othercolor)+"; }"
	print "a:hover { background-color:"+str(othercolor)+"; }" 

Body background color to match:


	print "<body bgcolor="+str(othercolor)+">"

The following loops some code eight times. Initialize `number` to a random integer between 50 and 500 (these are the jpg dimensions). What image is displayed is dependent on what `othernumber` ended up as in the beginning; it can be any number between 1 and 11. So, this generates a filename, since all of the images in the directory are named 1.jpg, 2.jpg, 3.jpg, etc. Then, the image's dimensions are chosen with `number`:


	turd = 1
	while turd < 9:
		number = random.randint(50,500)
		print "<img src="+str(othernumber)+".jpg"
		print "width="+str(number)+" height="+str(number)+">"
		turd = turd + 1	

The variable names are really horrible and confusing. Not `turd`, particularly -- that's just for the loop, and it's obvious as such. But all of that `othernumber`, `number`, `othercolor` stuff is horrid. But, it works. You asked for it.

Another neat thing I wrote was the "Dada Phrase Generator". I originally did it in BASIC in 1999 or so, and then had a friend translate it into JavaScript for me. This is what it does (page launches in a new window), with HTML and graphics added. Again, be sure to reload a lot. If you want to see the script itself, just `view source` on that page -- it's embedded in the HTML doc.

What makes that program impressive isn't the programming, but the "grammar hacking" I was able to do (set up creative parts of speech that fit together nicely). But then, there's always my JavaScript/CSS experiment (new window) of a few days ago -- `view source` if you want to see the shizzle.

When I was 10-13, I was obsessed with "IF...THEN" statements in Microsoft BASIC, and would use them to make quiz programs that didn't evaluate your score, as well as really crippled interactive fiction.

When I was even littler (8 or so), I would fool around with Logo, and tell it to draw things based on a few loop-tricks I learned.

There's always the eternal:


	10 INPUT "What is your name: ";A$
	20 PRINT "Hello ";A$
	

...and of course A$ always ends up as something like Faglord Dicksuck.

Ask a Question