FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
TABLE OF CONTENTS
May 07, 2007

Graphic Objects

(Page 5 of 5)

Fancier Graphic Objects

Listing Six contains definitions of four more complicated types of graphic objects. The point differs slightly from simple in that it expects the object to which it's attached to contain a list of at least two numbers. These become the x and y coordinates of the point. Gobs like this one are useful simulations of movement when you put several in one window.

(defgob 'point
  #'nilfn
  #.'(lambda (val window scale)
     (point window
       (* (car val) scale) (* (cadr val) scale))))
       
(setq dialmin 0 dialmax 100)

(defgob 'dial #'(lambda (val window scale) (circle window (* 50 scale) (* 50 scale) (* 48 scale))) #'(lambda (val window scale) (let ((theta (+ pi (' pi (div (- val dialmin) (- dialmax dialmin))))) (r (* 48 scale)) (x1 (* 50 scale)) (y1 (* 50 scale)))

(line window x1 y1 (+ x1 (* r (cos theta))) (+ y1 (* r (sin theta))))))) (defgob 'function #'nilfn #'(lambda (vals window scale) (plotcurve window (sort vals #'(lambda (x y) (< (car x) (car y)))) scale)))

(defgob 'parametric #'nilfn #'(lambda (vals window scale) (plotcurve window vals scale)))

(defun plotcurve (window points scale) (unless < (length points) 2) (let ((p1 (car points)) (p2 (cadr points))) (line window (* (car p1) scale) (* (- 100 (cadr p1)) scale) (* (car p2) scale) (* (- 100 (cadr p2)) scale))) (plotcurve window (cdr points) scale)))

Listing Six: Graphic object.

The second gob in Listing Six is the long-awaited dial. This version is reduced to its essentials, consisting only of a circle and a line. In actual use, dials have sort of minimum and maximum range -- here, dialmin and dialmax are by first set to 0 and 100, repectively. This range occupies the top 180 degrees of the dial, a situation easily altered by changing the culation of theta.

Finally, note that the dial, like all gobs for which size is an issue, is designed to fit by default into a 100-x-100 square, so that's how big it will be with scale 1.

The remaining gobs, function and parametric, assume that they are attached to an entry containing a list of (x,y) pairs. The only difference between the two is the order in which they connect these points: A function connects the order of increasing x coordinates; and a parametric connects them in the order in which they occur. Gobs like these take only slightly more effort to make than the simple gob, but a whole screen full of them working at runtime is a striking sight.

The graphic objects we've seen are really very simple. The point of this article is that making more complex ones does not mean starting over from scratch. When an interface is written in the style presented here, making it more sophisticated is largely a process of elaboration.

Previous Page | 1 Introduction | 2 Tiny Database Program | 3 Demons | 4 Simple Graphic Objects | 5 Fancier Graphic Objects
TOP 5 ARTICLES
No Top Articles.
DR. DOBB'S CAREER CENTER
Ready to take that job and shove it? open | close
Search jobs on Dr. Dobb's TechCareers
Function:

Keyword(s):

State:  
  • Post Your Resume
  • Employers Area
  • News & Features
  • Blogs & Forums
  • Career Resources

    Browse By:
    Location | Employer | City
  • Most Recent Posts:
    MEDIA CENTER  more
    NetSeminar
    Modernize your Development by Moving Build and Code Quality Upstream
    Moderated by Jon Erickson, Editor-in-Chief of Dr. Dobb's, this interactive panel discussion brings industry experts Anders Wallgren, CTO of Electric Cloud and Gwyn Fisher, CTO of Klocwork together for a candid discussion of the cost savings, productivity and quality benefits that can be achieved by stabilizing builds and code quality as early in the development cycle as possible.

    The reality of today's development environment - geographically distributed teams, the use of Agile development practices, increasing application complexity, etc. - is straining the viability of the traditional coding, build and release process. To stay ahead of the curve, development teams are modernizing their approach to dealing with these issues, and as a result are achieving new levels of development productivity. Register for the webcast.
    Date: Wednesday, July 15, 2009
    Time: 11 am PT/2 pm ET
    Modernize your Development by Moving Build and Code Quality Upstream
    Moderated by Jon Erickson, Editor-in-Chief of Dr. Dobb's, this interactive panel discussion brings industry experts Anders Wallgren, CTO of Electric Cloud and Gwyn Fisher, CTO of Klocwork together for a candid discussion of the cost savings, productivity and quality benefits that can be achieved by stabilizing builds and code quality as early in the development cycle as possible.

    The reality of today's development environment - geographically distributed teams, the use of Agile development practices, increasing application complexity, etc. - is straining the viability of the traditional coding, build and release process. To stay ahead of the curve, development teams are modernizing their approach to dealing with these issues, and as a result are achieving new levels of development productivity. Register for the webcast.
    Date: Wednesday, July 15, 2009
    Time: 11 am PT/2 pm ET
                                   
    INFO-LINK

    Resource Links: