Browse code
moving
Ed Langley authored on 29/10/2020 20:24:05
Showing 2 changed files
Showing 2 changed files
... | ... |
@@ -10,11 +10,11 @@ |
10 | 10 |
((cells :initarg :cells :accessor cells :type (array integer (* *))) |
11 | 11 |
(distance :initarg :distance :accessor distance :type integer))) |
12 | 12 |
|
13 |
-;(declaim (ftype (function ((vector integer 3) integer) (vector rational 3)) intercept-coordinate)) |
|
13 |
+;;(declaim (ftype (function ((vector integer 3) integer) (vector rational 3)) intercept-coordinate)) |
|
14 | 14 |
(defun intercept-coordinate (point distance &optional out-point) |
15 |
- ;(declare (inline) (optimize (speed 3))) |
|
15 |
+ (declare (inline) (optimize (speed 3))) |
|
16 | 16 |
(when (null out-point) |
17 |
- ;(break) |
|
17 |
+ ;(break) |
|
18 | 18 |
(setf out-point (vector 0 0 0))) |
19 | 19 |
(let ((a (elt point 0)) (b (elt point 1)) (c (elt point 2))) |
20 | 20 |
(setf (elt out-point 0) distance) |
... | ... |
@@ -23,7 +23,7 @@ |
23 | 23 |
out-point)) |
24 | 24 |
|
25 | 25 |
(defun run-plane (plane point-cb) |
26 |
- ;(declare (optimize (speed 3))) |
|
26 |
+ (declare (optimize (speed 3))) |
|
27 | 27 |
(let ((a (distance plane)) |
28 | 28 |
(points (cells plane))) |
29 | 29 |
(destructuring-bind (b-bound c-bound) (array-dimensions points) |
... | ... |
@@ -84,12 +84,12 @@ |
84 | 84 |
(point (or extracted-point (extract-projected-point point obj-dist out-point)))) |
85 | 85 |
(let ((d_o (c-distance origin point))) |
86 | 86 |
(values (if (<= d_o radius) |
87 |
- (ceiling (* (/ (sqrt (- r_sqr |
|
88 |
- (expt d_o |
|
89 |
- 2))) |
|
90 |
- radius) |
|
91 |
- #. (expt 2 7))) |
|
92 |
- 0) |
|
87 |
+ (ceiling (* (/ (sqrt (- r_sqr |
|
88 |
+ (expt d_o |
|
89 |
+ 2))) |
|
90 |
+ radius) |
|
91 |
+ #. (expt 2 7))) |
|
92 |
+ 0) |
|
93 | 93 |
point)))))) |
94 | 94 |
|
95 | 95 |
(defun make-interesting-cb (origin radius) |
... | ... |
@@ -157,19 +157,19 @@ |
157 | 157 |
finally (return val)))))) |
158 | 158 |
|
159 | 159 |
(defun array-to-pgm (arr) |
160 |
- ;(declare (optimize (speed 3))) |
|
160 |
+ ;;(declare (optimize (speed 3))) |
|
161 | 161 |
(with-output-to-string (s) |
162 | 162 |
(destructuring-bind (height width) (array-dimensions arr) |
163 | 163 |
(format s "P2~%~3d ~3d~%~d~%" |
164 | 164 |
width height |
165 | 165 |
(1+ (reduce #'max (make-array (* width height) :displaced-to arr))))) |
166 | 166 |
(loop with (x-bound y-bound) = (array-dimensions arr) |
167 |
- for x from 0 to (1- x-bound) |
|
168 |
- do (loop for y from 0 to (1- y-bound) |
|
169 |
- for val = (aref arr x y) |
|
170 |
- do (princ val s) |
|
171 |
- do (princ #\space s)) |
|
172 |
- do (terpri s)))) |
|
167 |
+ for x from 0 to (1- x-bound) |
|
168 |
+ do (loop for y from 0 to (1- y-bound) |
|
169 |
+ for val = (aref arr x y) |
|
170 |
+ do (princ val s) |
|
171 |
+ do (princ #\space s)) |
|
172 |
+ do (terpri s)))) |
|
173 | 173 |
|
174 | 174 |
(defmacro defshape (render-func origin radius &rest args) |
175 | 175 |
`(make-instance 'shape |
... | ... |
@@ -181,29 +181,31 @@ |
181 | 181 |
(defun main (&rest args) |
182 | 182 |
(declare (ignore args)) |
183 | 183 |
;;(sb-profile:profile intercept-coordinate c-distance) |
184 |
- (let ((the-plane (make-instance 'plane |
|
185 |
- :cells (make-array '(512 512)) |
|
186 |
- :distance 50)) |
|
187 |
- (lparallel:*kernel* (lparallel:make-kernel 8))) |
|
188 |
- |
|
189 |
- (labels ((100- (x) (- x 100)) |
|
190 |
- (random-coord () (100- (random 200)))) |
|
191 |
- (time |
|
192 |
- (run-plane the-plane |
|
193 |
- (apply #'combine-shapes |
|
194 |
- (loop for _ from 0 to 100 |
|
195 |
- collect (defshape make-donut-cb |
|
196 |
- (vector (1+ (random 50)) |
|
197 |
- (random-coord) |
|
198 |
- (random-coord)) |
|
199 |
- (+ 3 (random 30)) |
|
200 |
- 3)))))) |
|
201 |
- |
|
202 |
- (with-open-file (s "/tmp/spheres.pgm" :direction :output :if-exists :supersede) |
|
203 |
- (write-sequence (array-to-pgm (cells the-plane)) |
|
204 |
- s)) |
|
205 |
- nil) |
|
206 |
- ;(sb-profile:report) |
|
184 |
+ (loop for img-num from 0 to 1 |
|
185 |
+ do |
|
186 |
+ (let ((the-plane (make-instance 'plane |
|
187 |
+ :cells (make-array '(1024 1024)) |
|
188 |
+ :distance 50)) |
|
189 |
+ (lparallel:*kernel* (lparallel:make-kernel 7))) |
|
190 |
+ |
|
191 |
+ (labels ((100- (x) (- x 100)) |
|
192 |
+ (random-coord () (100- (random 200)))) |
|
193 |
+ (time |
|
194 |
+ (run-plane the-plane |
|
195 |
+ (apply #'combine-shapes |
|
196 |
+ (loop for x from 0 to 100 by 20 |
|
197 |
+ append (loop for y from 0 to 100 by 20 |
|
198 |
+ collect |
|
199 |
+ (defshape make-sphere-cb |
|
200 |
+ (vector 30 x y) |
|
201 |
+ 10))))))) |
|
202 |
+ |
|
203 |
+ (with-open-file (s (format nil "/tmp/spheres.~d.pgm" img-num) |
|
204 |
+ :direction :output :if-exists :supersede) |
|
205 |
+ (write-sequence (array-to-pgm (cells the-plane)) |
|
206 |
+ s)) |
|
207 |
+ nil)) |
|
208 |
+ ;(sb-profile:report) |
|
207 | 209 |
) |
208 | 210 |
|
209 | 211 |
;(loop with (x-bound y-bound) = (array-dimensions (cells the-plane)) |