Page 73 - AutoLISP и Visual LISP в среде AutoCAD
P. 73

);defun
                  ;******** Функция ДЕРЕВО ***************************
                  (defun Tree (x y a l / lst x1 y1 x2 y2 p s i a1)
                  (if (>= l 8) (progn
                     (setq x1 (+ x (* l (cos a)))) (setq y1 (+ y (* l
                     (sin a))))
                      (if (> l 100) (setq p 100) (setq p l )) (If (< p 40)
                        (progn
                             ;{Генерация листьев}
                             (if (> (Random) 0.5)
                                                  (setq col 94)
                                                  (setq col 70)
                             );if
                             (setq i 0)
                             (repeat 4
                                (setq lst '((0 . "LINE")(67 . 0)(8 . "0") (62 . col)
                                (10 x1 y1 0.0) (11 x2 y2 0.0)))
                                (setq new_lst (subst (list 10 (+ x i) (* y -1))
                                '(10 x1 y1 0.0) lst))
                                (setq new_lst (subst (list 11 x1 (* y1 -1))
                                '(11 x2 y2 0.0) new_lst))
                                (setq new_lst (subst (cons 62 col) '(62 . col) new_lst))
                                (entmake new_lst)
                                (setq i (1+ i))
                             );repeat
                        );progn
                        (progn
                               ;{Генерация веток}
                               (setq i 0)
                              (repeat (/ p 6)
                                  (setq lst '((0 . "LINE")(67 . 0)(8 . "0") (62 . 236)
                                  (10 x1 y1 0.0) (11 x2 y2 0.0)))
                                  (setq new_lst (subst (list 10 (+ x i) (* y -1))
                                  '(10 x1 y1 0.0) lst))
                                  (setq new_lst (subst (list 11 x1 (* y1 -1))
                                  '(11 x2 y2 0.0) new_lst))
                                  (entmake new_lst)
                                  (setq i (1+ i))
                              );repeat
                        );progn
                      );if
                        ;{Следующие ветки}
                        (setq i 0)
                        (repeat (1+ (- 9 (RRandom 9)))
                             (setq s ( + (RRandom (- l (/ l 6))) (/ l 6))) ;
                             ; {Угол наклона веток}
                             (setq a1 (+ a (* 1.6 (- 0.5 (Random)))))
                             (setq x1 (+ x (* s (cos a))))
                             (setq y1 (+ y (* s (sin a))))
                             (Tree x1 y1 a1 (- p 5 (RRandom 30)))
                             ;{Чем меньше вычитаем, тем пышнее дерево}
                        );repeat
                  );progn
                  );If

                  72
   68   69   70   71   72   73   74   75   76   77   78