NetRexx students,
While we're waiting for the course to start, here's another example for self-study, using the UI template I posted previously. I think this shows off the concise power of NetRexx. Ciao, Mitch Gould -- -- 1. Carefully choose class and file name: HSBSpace.nrx -- Note: I try to use 8.3 name conventions. -- -- Draws a color wheel, using the powerful Hue Saturation -- Brightness (HSB) color model. (Note that to display the -- entire color space, the user would need to increment and -- decrement the "brite" brightness property, and have the -- wheel redisplayed.) The reticule is intended for color -- selection by other modules. -- HFP, Example 2.x -- v 0.01 July 17, 1998 -- 2. Faster performance. Options Binary -- 3. Import packages, if necessary. -- 4. Declare class. Class HSBSpace Adapter Extends Frame Implements WindowListener -- 5. Assign properties. Properties Inheritable -- Background. ui = Color(50, 50, 70) -- Brightness. brite = float 1 -- Would be nice to proper-case the float keyword, but -- NetRexx 1.40's case-insensitivity fails with this. -- -- Radius. radius = Int -- Delta theta, the angular increment. deltheta = Int 10 -- Temp x , y values. xinitial = Int yinitial = Int xpoint = float ypoint = float xorigin = float yorigin = float -- End of props -- 6. Main method (ignored when loaded by a browser). Method main(tx=String[]) Static -- Declare win explcitly as a frame. win = Frame -- Construct the window frame. win = HSBSpace("Hues" Rexx(tx)) -- Set its size. win.resize(400, 400) -- Show it. win.setVisible(1) -- Implicit end of main method. -- 7. Construct "This" HSBSpace object. Method HSBSpace(tx=String) -- Set background color. This.setBackground(ui) -- Add a listener for standard events -- (specifically, window events). addWindowListener(This) howwide = 400 -- Better to set howwide using getSize(). This.brite = brite This.radius = Int ((howwide - 40) / 2) This.xinitial = Int ((howwide - 2 * radius) / 2) This.yinitial = Int ((howwide - 2* radius) / 2) This.xorigin = xinitial + this.radius This.yorigin = yinitial + this.radius This.xpoint = this.xorigin This.ypoint = this.yorigin -- Implicit end of main method. -- 8. Intercept standard events: paint, update, and close. Method paint(Region=Graphics) Region.fillOval(xinitial - 50, yinitial - 50, - 2 * radius + 100, 2 * radius + 100) paintSpectralArc(Region) drawReticule(Region) -- Implicit end of paint method. Method update(Region=Graphics) -- Used to reduce flickering. paint(Region) -- Implicit end of update. Method windowClosing(Event=WindowEvent) terminate(Event) -- Implicit end of close method. -- 9. Provide custom methods for standard events. Method paintSpectralArc(Region = Graphics) -- Called whenever the object is displayed, or -- redisplayed (following overlap from some window). sat = Int sat = 2 * radius Loop Until sat <= 0 hue = int 0 Loop Until hue >= 360 hue = hue + 10 hh = float (hue /360) ss = float (sat / (2 * radius)) brite = this.brite Region.setColor(Color.getHSBColor(hh, ss, brite)) xtemp = Int (xinitial + (2 * radius - sat) / 2) ytemp = Int (yinitial + (2 * radius - sat) / 2) Region.fillArc(xtemp, ytemp, sat, sat, hue, 10) End sat = sat - 10 End Method drawReticule(Region = Graphics) -- Samll circle to indicate current color selection. If (this.brite > 0.5) Then Region.setColor(Color.black) Else Region.setColor(Color.white) -- Implicit End If xint = Int (xpoint - 2) yint = Int (ypoint - 2) ovwidth = Int 2 Region.drawOval(xint, yint, ovwidth, ovwidth) Method terminate(Event=WindowEvent) -- The dispose method collects garbage. Event.getWindow().Dispose() Exit -- Implicit end of terminate method. ---- List Archive: http://www.FindMail.com/list/netrexx-course/ To Subscribe: e-mail to [hidden email] To Unsubscribe: e-mail to [hidden email] -- Start a FREE E-Mail List at http://www.MakeList.com ! |
Free forum by Nabble | Edit this page |