向选定对象添加随机颜色
我想要这个很久了,但我还没准备好。但在这里是BAM,在我找到随机数生成器之后,这是一个非常简单的代码。
它的作用:
要求选择实体并为其提供随机颜色!
很容易获得一个像样的概述。我发布了整个代码,随机代码上有一些版权问题,但如果我不把它放在这里,每个人都知道该网站:http://cat2.mit.edu/4.207/tutorials/alisp/random_01/random_01.html总有一天会失败,一切都会失去。
键入RCS以使用它
;; Function made by Marijn van den Heuvel
;; you can change the 10 160 to get different color range.
;; type rcs to use it.
(defun C:rcs(/)
(setq ss (ssget '((0 . "3dsolid"))))
(setq count 0)
(repeat (sslength ss)
(setq ent (ssname ss count))
(setq r (rand 10 160))
(setq g (rand 10 160))
(setq b (rand 10 160))
(command "chprop" ent "" "color" "truecolor"
(strcat (itoa r) "," (itoa g) "," (itoa b) )
"")
(setq count (1+ count))
);end repeat
);end function
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; ;;;;
;;;; Copyright (c) Jun. 1996 by Takehiko Nagakura. ;;;;
;;;; All rights reserved. ;;;;
;;;; ;;;;
;;;; Do not copy, use, modify or distribute this software ;;;;
;;;; without written permission by Nagakura. Nagakura will;;;;
;;;; not be responsible for any consequence of its use. ;;;;
;;;; ;;;;
;;;; Takehiko Nagakura(e-mail: takehiko@mit.edu) ;;;;
;;;; Massachusetts Institute of Technology ;;;;
;;;; 77 Massachusetts Ave. 10-472M, Cambridge, MA 02139;;;;
;;;; ;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; Last updated Feb 28, 2005 by TN for true color sample
;;;; Last updated Dec 29, 1996 by TN
;; The following pseudo-random number generator was
;; adopted from Kernighan and Ritchie's "C Programming Language"
;; second edition, p46.
;; If you want to use a random number in your program, you can just
;; copy this whole program into your program and use the function,
;; (rand min max)
;; as described below. It works, but do not ask me why this code
;; can generate fairly good randomness. If you are curious
;; to know it, some discussion on peudo-random number generator
;; is found in Paul Kohut's web page,
;; http://xarch.tu-graz.ac.at/~rurban/news/comp.cad.autocad/rand.lsp.html.
;; functions and their descriptions
;;
;; (rand16) : generates a random number between 1 and 32767,
;; that is, a positive 16 bit integer
;; (rand min max) : generates a random number between min and max.
;; Min and max must be an integer between 0 and 32767.
;; (c:demo) : demo function to generate random points
(setq *SeedRand* nil) ; initialize the global
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun rand16 ( / s )
; when this is used for the first time, initialize the seed
; from the system clock.
(if (null *SeedRand*)
(progn
(setq s (getvar "date"))
(setq *SeedRand* (fix (* 86400 (- s (fix s)))))
) ; progn
) ; if
; To generate a psudo-sandom number sequence
; I use the routine described in Kernighan and Ritchie's
; "C Programming Language" second edition, p46
(setq *SeedRand* (+ (* *SeedRand* 1103515245) 12345))
; trim off the bits left of the 16th bits
(logand (/ *SeedRand* 65536) 32767)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; generates a random number between min and max.
; min and max must be a non-negative integer smaller than 32678.
(defun rand (min max / r16 range quotient remainder result)
(setq r16 (rand16)) ; random number smaller than 32678
(setq range (+ 1 (- max min))) ; number of integers to be produced
(setq quotient (/ r16 range)) ; result in non-neg. integer
(setq remainder (- r16 (* quotient range)))
(setq result (+ min remainder))
result
)
; test it
; (rand 5 7)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:demo ( / x y n)
(command "plan" "")
(command "cmdecho" 0)
(command "zoom" "window"
(list -10000 -10000) (list 40000 40000))
(command "pdmode" 65)
(command "pdsize" -2)
(repeat 500
(setq x (rand16) ) (setq y (rand16))
(command "point" (list x y ))
;AutoCAD takes color numbers between 1 and 255
(setq n (rand 1 255))
(command "chprop" (entlast) "" "color" n "")
;(print (list x y n))
))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:demo2 ( / x y n)
(command "plan" "")
(command "cmdecho" 0)
(command "zoom" "window"
(list -10000 -10000) (list 40000 40000))
(command "pdmode" 65)
(command "pdsize" -2)
(repeat 500
(setq x (rand16) ) (setq y (rand16))
(command "point" (list x y ))
;AutoCAD true color uses numbers between 1 and 255 for rgb channels
;I use 100-160 range to make pastel colors.
(setq r (rand 160 255))
(setq g (rand 160 255))
(setq b (rand 160 255))
(command "chprop" (entlast) "" "color" "truecolor"
(strcat (itoa r) "," (itoa g) "," (itoa b) )
"")
;(print (list x y n))
))
页:
[1]