Jump to content

Recommended Posts

Posted

Many years ago I tried to draw stereograms (like this: https://en.wikipedia.org/wiki/Autostereogram ). I used to use Lisp for drawing on AutoCAD’s screen, then I saved the resulted image. I remember at that time I was wondering if I could leave-out AutoCAD, to make AutoLisp to write the data directly into a bitmap file. It didn’t work, Lisp can’t write binary. But these days I returned to that (to writing files, not to stereograms). Lisp can’t write binary, but it can write ordinary text files. So after getting the file right, the rest is just a question of conversion.

I downloaded a free hex editor (https://mh-nexus.de/en/hxd/).

Now: I use Lisp from inside AutoCAD to write the text file. I open it with Notepad, copy/paste the data in the hex editor and from there I save the file with BMP extension. Here are two samples -converted to GIF with Irfanview (https://www.irfanview.com/) just for uploading in the Forum.

Saturn.gif   tree.gif

And here is a Lisp:

(defun c:bmp()
  (setq file (open "C:\\Users\\miklos.fuccaro\\Desktop\\MyBitmap.tXt" "W"))
  (setq null4 "00 00 00 00")

  
  ;		file header:
  (write-line "42 4d" file)		;Magic Bytes
  (write-line null4 file) 		;File size
  (write-line null4 file)		;Reserved 1+2	
  (write-line "36 00 00 00" file)	;Data offset	!

  ;		Image header:
  (write-line "28 00 00 00" file)	;Heder size
  (write-line "ff 00 00 00" file)	;image width	!
  (write-line "ff 00 00 00" file)	;image height	!
  (write-line "01 00" file)		;Color Planes
  (write-line "10 00" file)		;Bits / Pixel	!
  (write-line null4 file)		;No compressions
  (write-line null4 file)		;Image size
  (write-line null4 file)		;X pix per m
  (write-line null4 file)		;Y pix / m
  (write-line null4 file)		;Colors
  (write-line null4 file)		;Important colors
    
  ;		Pixel data:


  ;|
;		saturn
  (setq col1 "08 08" col2 "1d 00" col3 "ff 1c" cx 115 cy 100 rDisc 50 rX 97 rY 14 i 0)  
  (repeat 256
    (setq i (1+ i) j 0)
    (repeat 256
      (setq j (1+ j))
      (setq dx (- cx j) dy (- cy i) dx (* dx dx) dy (* dy dy))
      (setq onDisc (if (< (+ dx dy) (* rDisc rDisc)) 1 nil))
      (setq ell (+ (/ (* (- i cy) (- i cy)) (* rY rY 1.0)) (/ (* (- j cX) (- j cX)) (* rX rX 1.0))))
      (setq onEllipse (if (equal ell 1 0.4) 1 nil))
      (setq str (if onDisc col2 col1))
      (cond
	((and onEllipse (= str col1)) (setq str col3))
	((and onEllipse (= str col2) (< i cy)) (setq str col3))
	) 
      (write-line str file)
      )   
    )
|;

  ; tree
 (setq col1 "ff 2d" col2 "e0 03" col3 "00 1c" col4 "c0 09"r1 0.03 r2 0.65 i 256)  
  (repeat 256
    (setq i (1- i) j 0)
    (repeat 256
      (setq str (if (< i 200) col1 col4))
      (setq j (1+ j))
      (setq str (if (< (abs (- j 90)) (* (rem i (+ 45 (/ i 7))) r2)) col2 str))
      (setq str (if (< (abs (- j 90)) (* i r1)) col3 str))
      (write-line str file)
      )   
    )

  
  (close file)
  (princ "OK")
  (princ)
  )

 

  • Like 2
Posted (edited)

I am sure have seen read byte , in lisp. The attached may give you some ideas, its just something I had, not sure if it even works. There should be a write byte somewhere.

 

USERBLOCK.LSP:                                        ; Convert the byte(at "po" position and has "len" length") to sty [a decimal number-num, or list, or stream or string-str)
USERBLOCK.LSP:                                        ; po: the position of the byte
USERBLOCK.LSP:                                        ; len: the length of the reading byte
USERBLOCK.LSP:                                        ;the 14th~17th record position + 30 byte record the image position
USERBLOCK.LSP:             )                          ;the byte length of the image
USERBLOCK.LSP:                             )          ;the pointer position, every 4 byte record a RGB color

USERBLOCK.LSP

Edited by BIGAL
Posted

Thanks for that! There is a pretty long code to decipher, it will keep me busy for next few days (or weeks?)

Have a nice day!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...