Author Topic: Can lisp create rgb-color chart  (Read 4542 times)

0 Members and 1 Guest are viewing this topic.

bchapman

  • Guest
Can lisp create rgb-color chart
« on: February 09, 2013, 09:35:44 PM »
Anyone ever try to do this:

Create a true color chart using lisp. I know there's 256^3 rgb color possibilities out there.... for 16,194,277 options....

Can lisp create a node, or object, offset it a little distance, and change the color by one number automatically.  It would be roughly 4024 rows high, 4024 columns wide. Could cad even pull this off?

node 1 = 256,256,256
node 2 = 256,256,255
node 3 = 256,256,254

Or perhaps increase the color spacing to make the changes more severe like:

256,256,256
256,256,250
etc

Just a thought...

RGUS

  • Newt
  • Posts: 106
Re: Can lisp create rgb-color chart
« Reply #1 on: February 10, 2013, 01:37:07 AM »
Wish it could... but my take a 96 inch monitor!

bchapman

  • Guest
Re: Can lisp create rgb-color chart
« Reply #2 on: February 10, 2013, 02:31:45 AM »
lol... think I'm gonna try to figure this one out... think this would be cool

Lee Mac

  • Seagull
  • Posts: 12924
  • London, England
Re: Can lisp create rgb-color chart
« Reply #3 on: February 10, 2013, 07:18:03 AM »
Since there are three variables: (R,G,B) the chart should be three dimensional - i.e. a cube.

Here are programs for the three planes of such a cube:

RG Plane:
Code: [Select]
(defun c:rgsquare ( / c x y )
    (setq c 16776960)
    (repeat (setq x 256)
        (repeat (setq y 256)
            (entmake (list '(0 . "POINT") (list 10 x y) (cons 420 c)))
            (setq y (1- y)
                  c (- c 256)
            )
        )
        (setq x (1- x))
    )
    (princ)
)

GB Plane:
Code: [Select]
(defun c:gbsquare ( / c x y )
    (setq c 65535)
    (repeat (setq x 256)
        (repeat (setq y 256)
            (entmake (list '(0 . "POINT") (list 10 x y) (cons 420 c)))
            (setq y (1- y)
                  c (1- c)
            )
        )
        (setq x (1- x))
    )
    (princ)
)

RB Plane:
Code: [Select]
(defun c:rbsquare ( / c x y )
    (setq c 16711935)
    (repeat (setq x 256)
        (repeat (setq y 256)
            (entmake (list '(0 . "POINT") (list 10 x y) (cons 420 c)))
            (setq y (1- y)
                  c (1- c)
            )
        )
        (setq x (1- x)
              c (- c 65280)
        )
    )
    (princ)
)

And here is a program to generate the cube itself, though I don't have the computing power to generate 16,777,216 points in AutoCAD...

Code: [Select]
(defun c:rgbcube ( / c x y z )
    (setq c 16777215)
    (repeat (setq x 256)
        (repeat (setq y 256)
            (repeat (setq z 256)
                (entmake (list '(0 . "POINT") (list 10 x y z) (cons 420 c)))
                (setq z (1- z)
                      c (1- c)
                )
            )
            (setq y (1- y))
        )
        (setq x (1- x))
    )
    (princ)
)

Alternatively, combining all three planes:



Code: [Select]
(defun c:rgbchart ( / c x y z )
    (setvar 'pdmode 0)
    (setq c 16776960)
    (repeat (setq x 256)
        (setq x (1- x))
        (repeat (setq y 256)
            (setq y (1- y))
            (entmake (list '(0 . "POINT") (list 10 x y 0) (cons 420 c)))
            (setq c (- c 256))
        )
    )
    (setq c 65535)
    (repeat (setq y 256)
        (setq y (1- y))
        (repeat (setq z 256)
            (setq z (1- z))
            (entmake (list '(0 . "POINT") (list 10 0 y z) (cons 420 c)))
            (setq c (1- c))
        )
    )
    (setq c 16711935)
    (repeat (setq x 256)
        (setq x (1- x))
        (repeat (setq z 256)
            (setq z (1- z))
            (entmake (list '(0 . "POINT") (list 10 x 0 z) (cons 420 c)))
            (setq c (1- c))
        )
        (setq c (- c 65280))
    )
    (command "_.-view" "_neiso" "_.zoom" "_e")
    (princ)
)
« Last Edit: February 10, 2013, 08:02:43 AM by Lee Mac »

gile

  • Gator
  • Posts: 2520
  • Marseille, France
Re: Can lisp create rgb-color chart
« Reply #4 on: February 10, 2013, 11:22:10 AM »
Hi,
Quote
And here is a program to generate the cube itself, though I don't have the computing power to generate 16,777,216 points in AutoCAD...
Generating 16,777,216 points in AutoCAD is certainly not a so good idea...

Here's my attempt for the rgb planes (Lee's rgbchart):
Code - Auto/Visual Lisp: [Select]
  1. (defun c:rgbPlanes (/ i j)
  2.   (setvar 'pdmode 0)
  3.   (repeat (setq i 256)
  4.     (setq i (1- i))
  5.     (repeat (setq j 256)
  6.       (setq j (1- j))
  7.       (entmakex (list '(0 . "point") (list 10 i j 0) (cons 420 (+ (lsh i 16) (lsh j 8)))))
  8.       (entmakex (list '(0 . "point") (list 10 i 0 j) (cons 420 (+ (lsh i 16) j))))
  9.       (entmakex (list '(0 . "point") (list 10 0 i j) (cons 420 (+ (lsh i 8) j))))
  10.     )
  11.   )
  12.   (command "_view" "_neiso")
  13.   (princ)
  14. )

The same with F#
 (EDIT: replaced "doc.SendStringToExecute("_-view _neiso ", false, false, false);" with a more efficient statement.
Code - F#: [Select]
  1. [<CommandMethod("rgbplanes")>]
  2. let rgbPlanes () =
  3.     let doc = Application.DocumentManager.MdiActiveDocument
  4.     let db = doc.Database
  5.     Application.SetSystemVariable("pdmode", 0)
  6.     use tr = db.TransactionManager.StartTransaction()
  7.     let ms = db.CurrentSpaceId.GetObject(OpenMode.ForWrite) :?> BlockTableRecord
  8.     let addPoint x y z =
  9.         let pt = new DBPoint(new Point3d(float x, float y, float z))
  10.         pt.Color <- Color.FromRgb(byte x, byte y, byte z)
  11.         ms.AppendEntity(pt) |> ignore
  12.         tr.AddNewlyCreatedDBObject(pt, true)
  13.     for i in 0 .. 255 do
  14.         for j in 0 .. 255 do
  15.             addPoint i j 0
  16.             addPoint i 0 j
  17.             addPoint 0 i j
  18.     use view = new ViewTableRecord()
  19.     view.CenterPoint <- Point2d.Origin;
  20.     view.Height <- 600.
  21.     view.ViewDirection <- new Vector3d(1., 1., 1.);
  22.     ed.SetCurrentView(view)
  23.     tr.Commit()
« Last Edit: February 10, 2013, 11:52:51 AM by gile »
Speaking English as a French Frog

Lee Mac

  • Seagull
  • Posts: 12924
  • London, England
Re: Can lisp create rgb-color chart
« Reply #5 on: February 10, 2013, 11:25:46 AM »
Here's my attempt for the rgb planes (Lee's rgbchart):

Nice gile - I thought there might be a way to make it more succinct  :-)

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Can lisp create rgb-color chart
« Reply #6 on: February 10, 2013, 01:10:38 PM »
Did AutoDESK ever update grdraw or grvecs to accept RGB colors?  -David
R12 Dos - A2K

Lee Mac

  • Seagull
  • Posts: 12924
  • London, England
Re: Can lisp create rgb-color chart
« Reply #7 on: February 10, 2013, 01:11:54 PM »
Did AutoDESK ever update grdraw or grvecs to accept RGB colors?  -David

Not that I am aware of...

gile

  • Gator
  • Posts: 2520
  • Marseille, France
Re: Can lisp create rgb-color chart
« Reply #8 on: February 10, 2013, 01:18:55 PM »
A DesignScript implementation.
The code is quite concise but it runs very slow...

Code: [Select]
import("ProtoGeometry.dll");

class PointColor
{
    Point : Point;
    constructor ByCoordinates(x : int, y : int, z : int)
    {
        Point = Point.ByCoordinates(x, y, z);
        Point.Color = Color.ByARGB(0, x, y, z);
    }
}

pointsRG = PointColor.ByCoordinates((0..255)<1>, (0..255)<2>, 0);
pointsRB = PointColor.ByCoordinates((0..255)<1>, 0, (0..255)<2>);
pointsGB = PointColor.ByCoordinates(0, (0..255)<1>, (0..255)<2>);

Speaking English as a French Frog

bchapman

  • Guest
Re: Can lisp create rgb-color chart
« Reply #9 on: February 10, 2013, 09:37:42 PM »
You experts (aka geniuses) make this stuff seem too easy lol.  My CPU almost processed the 3d Cube per your code LEE but I couldn't resist clicking...crashed it where you see below. Going to try again when I don't want to click on anything lol.



Since there are three variables: (R,G,B) the chart should be three dimensional - i.e. a cube.

Here are programs for the three planes of such a cube:

RG Plane:
Code: [Select]
(defun c:rgsquare ( / c x y )
    (setq c 16776960)
    (repeat (setq x 256)
        (repeat (setq y 256)
            (entmake (list '(0 . "POINT") (list 10 x y) (cons 420 c)))
            (setq y (1- y)
                  c (- c 256)
            )
        )
        (setq x (1- x))
    )
    (princ)
)

GB Plane:
Code: [Select]
(defun c:gbsquare ( / c x y )
    (setq c 65535)
    (repeat (setq x 256)
        (repeat (setq y 256)
            (entmake (list '(0 . "POINT") (list 10 x y) (cons 420 c)))
            (setq y (1- y)
                  c (1- c)
            )
        )
        (setq x (1- x))
    )
    (princ)
)

RB Plane:
Code: [Select]
(defun c:rbsquare ( / c x y )
    (setq c 16711935)
    (repeat (setq x 256)
        (repeat (setq y 256)
            (entmake (list '(0 . "POINT") (list 10 x y) (cons 420 c)))
            (setq y (1- y)
                  c (1- c)
            )
        )
        (setq x (1- x)
              c (- c 65280)
        )
    )
    (princ)
)

And here is a program to generate the cube itself, though I don't have the computing power to generate 16,777,216 points in AutoCAD...

Code: [Select]
(defun c:rgbcube ( / c x y z )
    (setq c 16777215)
    (repeat (setq x 256)
        (repeat (setq y 256)
            (repeat (setq z 256)
                (entmake (list '(0 . "POINT") (list 10 x y z) (cons 420 c)))
                (setq z (1- z)
                      c (1- c)
                )
            )
            (setq y (1- y))
        )
        (setq x (1- x))
    )
    (princ)
)

Alternatively, combining all three planes:



Code: [Select]
(defun c:rgbchart ( / c x y z )
    (setvar 'pdmode 0)
    (setq c 16776960)
    (repeat (setq x 256)
        (setq x (1- x))
        (repeat (setq y 256)
            (setq y (1- y))
            (entmake (list '(0 . "POINT") (list 10 x y 0) (cons 420 c)))
            (setq c (- c 256))
        )
    )
    (setq c 65535)
    (repeat (setq y 256)
        (setq y (1- y))
        (repeat (setq z 256)
            (setq z (1- z))
            (entmake (list '(0 . "POINT") (list 10 0 y z) (cons 420 c)))
            (setq c (1- c))
        )
    )
    (setq c 16711935)
    (repeat (setq x 256)
        (setq x (1- x))
        (repeat (setq z 256)
            (setq z (1- z))
            (entmake (list '(0 . "POINT") (list 10 x 0 z) (cons 420 c)))
            (setq c (1- c))
        )
        (setq c (- c 65280))
    )
    (command "_.-view" "_neiso" "_.zoom" "_e")
    (princ)
)

bchapman

  • Guest
Re: Can lisp create rgb-color chart
« Reply #10 on: February 10, 2013, 09:42:17 PM »
Hey Gile, how do I run the script below?

Thanks!

A DesignScript implementation.
The code is quite concise but it runs very slow...

Code: [Select]
import("ProtoGeometry.dll");

class PointColor
{
    Point : Point;
    constructor ByCoordinates(x : int, y : int, z : int)
    {
        Point = Point.ByCoordinates(x, y, z);
        Point.Color = Color.ByARGB(0, x, y, z);
    }
}

pointsRG = PointColor.ByCoordinates((0..255)<1>, (0..255)<2>, 0);
pointsRB = PointColor.ByCoordinates((0..255)<1>, 0, (0..255)<2>);
pointsGB = PointColor.ByCoordinates(0, (0..255)<1>, (0..255)<2>);

gile

  • Gator
  • Posts: 2520
  • Marseille, France
Re: Can lisp create rgb-color chart
« Reply #11 on: February 11, 2013, 12:48:11 AM »
Quote
Hey Gile, how do I run the script below?

You have to download and install DesignScript (AutoCAD 2013 64 bits on Windows 7 only).
Speaking English as a French Frog