#!/usr/bin/perl -w # # Copyright 2000 by Michael Coyle # Released under GPL. # # Call it with: # [an error occurred while processing this directive] # # Get the file name from the browser... $file_name = $ENV{'QUERY_STRING'}; # Open the file... open (EP, $file_name); # Print to the browser... print "Content-Type: text/html \n\n"; # Load the file and keep spitting it out to the browser... while () { chomp; print "$_ "; } # Close the file and go home... close EP #!/usr/bin/perl -w # # Copyright 2000 by Michael Coyle # Released under GPL. # # Call it with: # [an error occurred while processing this directive] # # Get the file name from the browser... $file_name = $ENV{'QUERY_STRING'}; # Open the file... open (EP, $file_name); # Print to the browser... print "Content-Type: text/html \n\n"; # Load the file and keep spitting it out to the browser... while () { chomp; print "$_ "; } # Close the file and go home... close EP

3D
3D Photo Gallery (Part 1)
3D Photo Gallery (Part 2)

Audio
Poor Man's MIDI
Make A Metronome
iPod Tricks (Part 1)
iPod Tricks (Part 2)
iPod Tricks (Part 3)
Laugh Track Machine
Audio Player with Reverb
Shepard Melody
RB Phone Home
Build a Drum Machine

Custom Controls and Windows
Double Click Listbox
Draggable Metal Window
Double Click Canvas
Custom Buttons
Custom Buttons Part II
iTunes-style Listboxes
Custom Controls


General RB
Scrolling Windows
Using Mesage Dialogs
Case-Sensitive Word Finder
Introduction to Stacks
Wiggle Window
JPEG in PDF
Listbox Checkboxes
Background Applications
Listbox Auto-Find
Virtual Volumes
Time Tracker
Software Distribution (Part 1)
Software Distribution (Part 2)
Software Distribution (Part 3)
Software Distribution (Part 4)
Exceptions
Tips and Tricks
Text Clippings Made Easy

Graphics
Drawing a Simple Gradient
The SpriteSurface: Space Game
Image Spinner
Cropping Graphics (Part 1)
Cropping Graphics (Part 2)
Cropping Graphics (Part 3)
Cropping Graphics (Part 4)
Shimmer Graphics
Lissajous Figures
Simple Screen Capture
Vector Graphics
Kaleidoscope Images
Stegonography
Spirals!
Image Table
RB Magnifying Lens
Screen Capture
Color Picker Tutorial

Hacks
Ghost Grab
Speedy Mouse Extension
iTunes Plugins
iTunes Skinner

Mac OS X
Global Hot Key Event (Carbon Events)
Login Welcomer (Carbon Events)
Add/Remove Buttons
Resizable Sheets
Mac OS X Preferences Window
Using Sheets in REALbasic
Build a Bundle (Part 1)
Build a Bundle (Part 2)
Dock Your Passwords
Mac OS X Debugging
REALbasic Mac OS X Icon Tutorial
Animate Your Dock
RB and the Command Line

Menus
Window Menu
Templates Menu
Listbox Menu

Novelty
Guessing Game
Calendar Trivia
Tile Mixer
Zip Code Finder
Happy Valentine's Day
Merlin Simulator (Part 1)
Merlin Simulator (Part 2)
Merlin Simulator (Part 3)
Buzzword Machine
AppleSoft BASIC

Printing
Print to PDF

Registration
Registration Code Validation
Network Registration Codes

Resources
Picture Extractor (Part 1)
Picture Extractor (Part 2)

Serial
Caller ID (Part 1)
Caller ID (Part 2)
Caller ID (Part 3)

Speech
Speech Recognition

Socket Communication
Easy Peer-to-Peer File Sharing
MacPAD Version Checking
Display Web Image In Canvas
HTML IMG Tags
Version Tracking
Even Smarter Instant Messaging
Web Tiler
JavaScript and REALbasic
Stock Ticker (Part I)
Stock Ticker (Part 2)
AIM Mate

XML Manipulation
Simple XML Introduction

Video
Big Brother Video Capture

Note: All articles without a byline were written by Erick Tejkowski. When cleaning the site I removed them because the code differed from page to page, and I have yet to put them back in.

resexc2.gif (20k)




REALbasic for Dummies
by Erick Tejkowski

$19.99 @ Amazon





Files are in Stuffit 6.5 or earlier, or ZIP format.
Download Stuffit Expander

Tell us about a bad link.

Drawing Spirals
02-21-02




Today we'll look at how to draw a spiral with REALbasic. In the process, we will also learn an important secret of top programmers: let someone else do the work!

Intro

A friend once told me that the best programmers are lazy ones. His point wasn't that lazy employees were better than hard workers. Rather, "lazy" coders are often better, because they know how to work smarter not harder.

This week we'll look at how to draw a spiral. Rather than calculate the formula to do this task, we will adapt a Visual Basic spiral example. Because of its close similarity to REALbasic, Visual Basic code is often a great source for programming ideas. The web is littered with thousands of Visual Basic code examples that are ripe for the taking.

For the first step in this week's tutorial, look at a Visual Basic spiral code example. Try to read through the code and see if you can guess how it might translate to REALbasic. Some hints might help you decipher this example:

  • Focus your attention on the Form_Paint subroutine. It is equivalent to the Paint event of REALbasic's Canvas control.
  • The coordinate system for drawing Visual Basic graphics works like REALbasic, with the origin in the top left corner of the Canvas.
  • Ditch the Declare statements. We don't need them.

Build the Interface and Add the Code

This week's example is simple to create. Launch REALbasic, open Window1 and add a Canvas and a Slider control to it. Double click the Canvas to open the Code Editor and place the following code in its Paint event:

	  
  dim x,y,n,xmid,ymid as integer
  dim angle, radius as double
  dim lastx,lasty as integer
  
  
  XMid = Me.Width / 2
  YMid = Me.Height / 2
  lastx=XMid
  lasty=YMid
  g.foreColor = rgb(255,255,255)
  g.fillrect 0,0,me.width,me.height
  g.foreColor = rgb(0,100,0)
  g.penwidth = slider1.value
  g.penheight = slider1.value
  
  For n = 1 To 1000
    Angle = n * 0.1
    Radius = Radius + Angle * 0.01
    x = XMid + Cos(Angle) * Radius
    y = YMid - Sin(Angle) * Radius
    g.drawline x,y,lastx,lasty
    
    lastx = x
    lasty = y
  next
  
	

Finally, add the following line of code to the ValueChanged event of Slider1.

	Canvas1.refresh 
	

That's it! Select Debug-Run to test your work. Then, go back and compare your code with the Visual Basic version. Can you figure out how we replaced the drawing commands from Visual Basic with the drawing commands of REALbasic? We also added a little fanciness to the project to make it a tad more interactive. The slider control changes the width of our pen which draws with a green color.

Your final result should look something like this:

spiral.jpg (39k)

Conclusion

As you can see, borrowing code has its benefits. This example was easy, but calculating a formula for drawing sprials is not something that immediately comes to mind for most people. With a little mental work, you can adapt existing code examples to suit your needs. And, never forget the programmer's motto : "REUSE CODE!". If you don't believe me on this one, take a look at the DLL folder in Windows some time. Download the finished product here and see you next week!






Please support ResExcellence by Visiting our Sponsors. One click makes a difference.


Download REALbasic and create your own software!

#!/usr/bin/perl -w # # Copyright 2000 by Michael Coyle # Released under GPL. # # Call it with: # [an error occurred while processing this directive] # # Get the file name from the browser... $file_name = $ENV{'QUERY_STRING'}; # Open the file... open (EP, $file_name); # Print to the browser... print "Content-Type: text/html \n\n"; # Load the file and keep spitting it out to the browser... while () { chomp; print "$_ "; } # Close the file and go home... close EP #!/usr/bin/perl -w # # Copyright 2000 by Michael Coyle # Released under GPL. # # Call it with: # [an error occurred while processing this directive] # # Get the file name from the browser... $file_name = $ENV{'QUERY_STRING'}; # Open the file... open (EP, $file_name); # Print to the browser... print "Content-Type: text/html \n\n"; # Load the file and keep spitting it out to the browser... while () { chomp; print "$_ "; } # Close the file and go home... close EP