TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: MP on December 15, 2008, 08:56:41 PM

Title: I'd like to make a point
Post by: MP on December 15, 2008, 08:56:41 PM
In short, the function uses grvecs to draw a multi colored sphere at the specified point, using the radius and colors1 and 2 if supplied. The radius value, if provided, is treated like the pdsize variable. The colors are treated per the grvecs function. If passed nils for radius, color1 and color2 it resorts to defaults, which are 1/100 screen size, red and green respectively.

Why: I needed visual confirmation of points generated by a program I was writing, but I didn't want to create any temporary entities. So I quickly bashed this out (hasn't been optimized yet).

Quick examples:

      ;; default 1/100 screensize, default red, default green
      (grpoint (getpoint "Pick a point: ") nil nil nil)

      ;; default 1/100 screensize, yellow, blue
      (grpoint (getpoint "Pick a point: ") nil 2 5)

      ;; 1/200 screensize, yellow, yellow
      (grpoint (getpoint "Pick a point: ") -0.5 2 2)

Code: [Select]
(defun GrPoint ( point radius color1 color2 / i j k angles )

    (setq radius
        (if (numberp radius)
            (if (minusp radius)
                (* (/ (abs radius) 100.0) (getvar "viewsize"))
                radius
            )
            (* 0.01 (getvar "viewsize"))
        )
    )

    (setq
        color1 (if (eq 'int (type color1)) color1 1)
        color2 (if (eq 'int (type color2)) color2 3)
        j      0.05
        k      (/ j 2.0)
        i      (- j)
    )

    (repeat (fix (/ 1.0 j))
        (setq angles
            (cons
                (+ k (* 0.5 pi (setq i (+ i j))))
                angles
            )
        )
    )

    (mapcar
       '(lambda ( args / point color start_angle angles )
            (setq
                point       (car args)
                color       (cadr args)
                start_angle (caddr args)
                angles      (cadddr args)
            )
            (grvecs
                (apply 'append
                    (mapcar
                       '(lambda ( incr_angle )
                            (list
                                color
                                point
                                (polar
                                    point
                                    (+ start_angle incr_angle)
                                    radius
                                )
                            )


                        )
                        (cadddr args)
                    )
                )
            )
        )
        (list
            (list point color1 (* 0.0 pi) angles)
            (list point color2 (* 0.5 pi) angles)
            (list point color1 (* 1.0 pi) angles)
            (list point color2 (* 1.5 pi) angles)
        )
    )

    point ;; return the original point to the caller

)

Sorry, don't have time to document this better or clean up the local vars. Will do down the road when I've more time.

Later dudes.
Title: Re: I'd like to make a point
Post by: Slim© on December 15, 2008, 09:13:08 PM
Nice job!!! Did something similar a few years ago, but this is better.
Title: Re: I'd like to make a point
Post by: kdub_nz on December 15, 2008, 11:15:10 PM

Nicely bashed together Michael.
Title: Re: I'd like to make a point
Post by: MP on December 16, 2008, 01:11:34 AM
Thanks guys, dirty but did the job.
Title: Re: I'd like to make a point
Post by: ronjonp on December 16, 2008, 10:21:42 AM
Thanks guys, dirty but did the job.

I'm hope someday to write "dirty" code like you  :-P
Title: Re: I'd like to make a point
Post by: MP on December 16, 2008, 10:36:57 AM
{shrug} Thanks Ron, I've got nothing on you. :)








































Except maybe 50 lbs. :(
Title: Re: I'd like to make a point
Post by: Maverick® on December 17, 2008, 12:09:45 AM

Except maybe 50 lbs. :(

Put your head on his shoulder?  :-D
Title: Re: I'd like to make a point
Post by: MP on December 17, 2008, 09:01:54 AM

Except maybe 50 lbs.

Put your head on his shoulder?

would take a LOT of tequila to get me to that point (http://www.theswamp.org/screens/mp/oh.gif)

















yes, I know what you meant: I can still get thru the door :P