-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.lisp
More file actions
98 lines (78 loc) · 1.99 KB
/
utils.lisp
File metadata and controls
98 lines (78 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
;;
;; Lire - utils
;;
;; Move this section to new file
;;
;; Lire-user
;;
(in-package :cl-user)
;; Graham's alambda
(defmacro alambda (parms &body body)
`(labels ((self ,parms ,@body))
#'self))
;; end
(in-package :lire)
(defun get-time ()
(/ (get-internal-real-time)
internal-time-units-per-second))
;;;
;; Evaly
;;;
(defun e-eval (form &optional echo)
(when echo
(format t "Evaluating new form:~%")
(format t " IN >>>~% ~s~%" form))
(ignore-errors
(let ((result (eval form)))
(when echo
(format t " OUT <<<~% ~s~%" result))
result)))
(defun function-symbol-p (symbol)
(e-eval
`(not (null (ignore-errors (and (symbolp ',symbol)
(symbol-function ',symbol)))))))
;;;
;; Math
;;;
(defun lerp (from to amount)
(+ from (* (- to from) amount)))
(defmacro snap-to-grid (what)
`(setf ,what
(let ((half (/ *grid-size* 2)))
(round (- ,what (- (mod (+ ,what half) *grid-size*) half))))))
;;;
;; Color
;;;
(defun hsv-to-rgb (h s v)
(let* ((c (* v s))
(x (* c (- 1 (abs (- (mod (/ h 60) 2) 1)))))
(m (- v c))
(rgb-n (cond ((<= 0 h 60) (list c x 0))
((<= 60 h 120) (list x c 0))
((<= 120 h 180) (list 0 c x))
((<= 180 h 240) (list 0 x c))
((<= 240 h 300) (list x 0 c))
((<= 300 h 360) (list c 0 x)))))
(mapcar (lambda (x) (+ x m)) rgb-n)))
;;;
;; Lists
;;;
(defun flatten (l &key (test #'atom))
(cond ((null l) nil)
((funcall test l) (list l))
(t (loop for a in l nconc (flatten a :test test)))))
;;;
;; Saving-lisp
;;;
(defun save-lisp ()
"Make exebutable"
#+sbcl
(sb-ext:save-lisp-and-die
(concatenate 'string
"builds/Lire-" (software-type) ".exe")
:toplevel (lambda ()
(format t "Image loaded.~%")
(run-lire :threaded nil))
:executable t
;:application-type :gui
))