HW1: Poly-lines using 'Processing'
Summary
You need to create a small interactive program that draws lines (using the Midpoint Algorithm discussed in class), that connect mouse clicks. You will implement this using the 'Processing' platform. See 'Description' below for details.
Due date
Oct. 1 '08, by midnight (late Wed. night).
No extensions. Also, there is a penalty of 5% for each day you're late.
Score
10% of the total (HW1, Midterm, HW2, HW3 and Final are worth 10%, 15%, 10%, 30% and 35% respectively). 20% (of the 10%) extra credit is also
available - see below.
How to submit
Please use Blackboard to submit your work. For this homework, all you need to submit is a single Processing source file, with a '.pde' extension (eg. 'Tyler_HW1.pde') and a README file that explains how to run your program (esp. important if you are
implementing extra-credit code). If you are not familiar with how to submit via Blackboard, please see a TA/Grader and learn how. Email submissions will NOT be accepted.
Platforms
PC/Mac/Linux.
Description
The platform you will use is called 'Processing' (which is implemented using Java). Processing is enormously popular among CG hobbyists, artists, students and others, as it permits rapid implementation of multi-media projects that include user interaction, UI widgets, 2D and 3D graphics, image and video processing with audio.
Platforms
PC/Mac/Linux.
Description
The platform you will use is called 'Processing' (which is implemented using Java). Processing is enormously popular among CG hobbyists, artists, students and others, as it permits rapid implementation of multi-media projects that include user interaction, UI widgets, 2D and 3D graphics, image and video processing with audio.
Visit Processing and take a look at the amazing variety of demo programs online, and start studying the source code for the demos. More samples are here and doing a search will turn up even more. Processing comes with its own coding language, heavily reminescent of C, Java, JavaScript etc. It is a very simple language to learn (things tend to be verbose than terse as a result of the simplicity). Built-in calls provide core functionality, and third-party libraries, even more.
Download Processing for your machine (PC, Mac, Linux), and start studying the sample sources more. When learning a new programming language, it is a good idea to make small modifications to an existing program, run it, see what the effect is. After that you can start combining parts from existing programs to make new ones. This is a way to build up confidence towards writing your own programs from scratch. Once you are comfortable with the syntax and with writing/running Processing programs, you can start on your own HW1 .pde.
For HW1, here is what we expect when we run your program:
- an 800x800 window is displayed, with a black background.
- the user clicks multiple times randomly inside the window. A white 'poly-line' (sequence of connected straight lines) is incrementally drawn between adjacent mouse clicks, ie. as the clicks happen. Clicking four times will create a three-segment poly-line, for example.
- pressing the 'r' key anywhere on the window resets the drawing mode so that from the next click on, the previous step happens, ie a new poly-line (not connected with any existing ones) is generated. It is the equivalent of "lifting the pen up", putting it down elsewhere to start a new chain of lines. The existing poly-lines stay on (don't get erased), letting you build up simple figures over the canvas (background).
- there is no special mode for ending/exiting - the user simply stops clicking when they're done.
As you can see the core of the program consists of drawing a line between two (integer) locations in the window. Here is where your Midpoint Algorithm line drawing implementation will come into play. The use of the built-in line() call, eg. line(5,5,255,450) is NOT allowed!! The purpose of the HW is to get you to implement the Midpoint Algorithm for line drawing, that is why. Since each line consists of a sequence of 'lit' pixels, you need to use Processing's point() call as the setPixel(x,y) one mentioned in the lecture slides. Note - you need to "extend" the Midpoint Algorithm to the other 7 cases, in addition to the 'Region 1' case presented in class. Don't do the HW using Bresenham Algorithm or any other line drawing technique.
Here are some other useful Processing calls: mousePressed(), mouseReleased(), keyPressed(), etc. Likewise, built-in (global) variables mouseX, mouseY, key are needed to obtain current mouse coordinates and key presses.
DO NOT plagiarize code under any circumstance (porting existing code in other languages to Processing also falls under this category). You can study code online, but when it comes to coding, please do a "clean room implementation", ie. craft your own. If you're caught cheating, you'll get an 'F' ***FOR THE ENTIRE COURSE***. You can choose whether to take this risk or not (hint - we wouldn't!).
Have lots of fun with Processing and with your homework!
One last thing: learning Processing will also be helpful for you in the future, for other courses' assignments or for your own projects. It is a good alternative to Python for lightweight multimedia app development (simpler and less powerful than Python but useful nevertheless). It is also a nice alternative to OpenGL. Interestingly, OpenGL is itself available as a Processing library (extra download). As with Python, Java etc., lots of library add-ons amplify Processing's capabilities. You don't need to, but for extra power you can augment Processing programs with raw Java code (since Processing is itself built on top of Java). All of these taken together makes Processing a serious candidate for visual-oriented software development (including interactive art installations). Processing can even run on handhelds with JVMs! So many positives, just one notable drawback - Processing programs run slower compared to raw binaries.