Lab #6: Graphical and Network Applications in REBOLAssigned: Thu 4 April 2002
Due: Thu 11 April 2002
- Problem description
- Part 1: Graphic Effect Iterator
- Part 2: Headline "Heads-up" E-mailer
- General issues
Problem descriptionIn this assignment you'll be using the REBOL language demonstrated this week in class to do some graphical and internet programming. You can find the REBOL system on the Collins 411 lab machines under the Start menu (Start/Programs/REBOL/REBOL, to put it in REBOL refinement style). You'll want to have access to both background documentation on REBOL and to some of the sample or demo scripts provided with the implementation. Here are some handy resources:
- REBOL documentation page
You can find all the on-line documentation from here, including especially ...
- The REBOL Language Manual
This is the full story description of the language. As mentioned in class, it isn't an especially formal description, but with this and soem experimentation you should be able to get along well.
- Quick Introduction to REBOL
This is a much shorter tour of REBOL; start here to get a reminder of the main features, but class lectures were drawn more from the longer manual above.
A list of docs on the graphical aspects of programming in REBOL, i.e., REBOL/View.
- Beginner's Guide to REBOL Visual Interfaces
A quick run-down on GUI elements in REBOL/View.
- How to Create Custom Buttons
A handy guide to making your app's buttons look better than the defaults.
Part 1: Graphic Effect IteratorFor this part of the assignment, you should make a REBOL application (i.e., a script you can run from the "desktop") which displays a button and an image in a window. The button, when pressed, should apply some graphic effect to the image, and should do so repeatedly with repeated button presses (i.e., if the effect is to lighten the image, repeated presses would make the image lighter and lighter). You need only have one built-in image and one built-in effect, but of course you may make the application more sophisitcated if you like (i.e., load images from the web or from files, choose different effects, etc.). Once you get the basic application done, other stuff should be pretty easy (and fun!) to add.
Strategy: Look at the standard REBOL demo application (demonstrated in class) called "Gel": this loads an image and allows a user to apply effects in a moving window to a sub-part of the image. Your app in some sense is just a sub-set of this, but note that you'll apply your effect to the whole image (so you don't need to even handle the moving window). Also, you may wish to write the resulting image (after the effect) out to a file: it's not clear whether this will be necessary as an intermediate step in doing multiple applications of the effect (experiment!).
Feel free to grab any old image as your initial image, and if you re-write the file, remember to keep a copy of the original.
Part 2: Headline "Heads-up" E-mailerFor this part of the assignment, you should make a REBOL application (i.e., a script you can run from the "desktop") which allows you to e-mail the headlines from a web page to a friend (for now, the "friend" should be you). More specifically, upon activating the script (or pressing a button, if you want to use a GUI), your program should read in the content of a popular news site's main web page (I recommend slashdot.org), search through the text for (say) the top 5 headlines, then e-mail these to a friend with an appropriate subject line.
Strategy: Print the headlines out to a text field until you have the rest of the application working: this way you won't clog up anyone's e-mail (i.e., your own) with failed attempts. In fact, you can develop the application mostly from the REBOL console, only adding a GUI (optional) and the real mail target at the end.
How do you find the headlines? Read the source code (i.e., html file) for the given website, looking for the headlines and see if you can identify some preceding text. For example, the headlines at Slashdot (http://www.slashdot.org) seem to be preceded by the tag <FONT FACE="arial,helvetica" SIZE="4" COLOR="#FFFFFF">. You can search for this using the simple find function (recall examples from lecture or here in the REBOL docs) or you can use more sophisticated parsing techniques (see this section of the manual on parsing).
General issuesHow to write a script?
In lecture we concentrated on some demos of graphical applications and on using the interactive console for REBOL; in order to do the assignments you'll also need to know how to write a REBOL script. You can find information on scripting from the REBOL language manual.
You can edit your scripts from the REBOL desktop by clicking the local icon, then open the editor by double-clicking on a text file icon. After you save your script to the "local" directory (careful, I don't think it's the default), you need to edit the "index.r" file to have an icon show up for it.
Where to keep your stuff?
You'll want to keep your scripts, image files, etc., on your H drive until your ready to demo. You can copy them into your REBOL desktop area during development, but you should then remove them again afterwards, so as to avoid having them left out for other people to read or use.
In order to read files such as images using the http protocol, you need to keep them in your public_html folder on your gemini or hudson account. You also need to make sure their permissions are enabled to allow global reads (they should be by default if you create them in your public_html directory).
In order to actually read in a file, look at the gel.r example in the demos folder on the REBOL desktop.
How the heck do I apply an effect to an image??
OK, this one took some time to figure out, but here goes:
- First, you'll have a layout which holds all the "faces" in your GUI; one of these will be your button, another will be the image in question.
- The face which is your image needs to be named, as a variable, within your layout, like this:layout [ ... myimage: image ... ... ]
- Now, the action of your button will be a code block which should do two things: first, it should append the effect list of the image with a new "copy" of the effect in question: append myimage/effect [blur] (or whatever, i.e., different than blur if you like). Next, it needs to show the image: show myimage (this can just follow the first part in the block, but you may put them on separate lines for clarity).