-
-
Notifications
You must be signed in to change notification settings - Fork 360
IFS Common Lisp implementation #722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
7151153
f233beb
1cdbf03
adc2294
68cf274
78045ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
;;;; Iterated Function System implementation | ||
|
||
(defstruct (point (:constructor make-point (x y))) x y) | ||
|
||
(defun chaos-game (iterations shape-points) | ||
"Plays a chaos game with a certain shape for a determined amount of iterations" | ||
(loop | ||
repeat iterations | ||
for rand-point = (svref shape-points (random (length shape-points))) | ||
for point = (make-point (random 1.0) (random 1.0)) ; starting point | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this creates a new There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, there must be something here that I don't understand, because the code clearly works. I'm fine with it then. |
||
then (make-point | ||
(* 0.5 (+ (point-x rand-point) (point-x point))) | ||
(* 0.5 (+ (point-y rand-point) (point-y point)))) ; every subsequent point | ||
collect point)) | ||
|
||
(defparameter *shape-points* | ||
(map | ||
'vector | ||
(lambda (e) (apply #'make-point e)) | ||
;; the backquote allows us to selectively evaluate (sqrt 0.75) with the comma | ||
`((0 0) (0.5 ,(sqrt 0.75)) (1 0)))) | ||
|
||
;; output the data to the "out.dat" file | ||
(with-open-file (out "out.dat" :direction :output :if-exists :supersede) | ||
(flet ((format-point (p) | ||
;; this is not very clean, but it's the simplest way to insert a tab into a string. | ||
(format nil "~f~c~f" (point-x p) #\tab (point-y p)))) | ||
(format out "~{~a~%~}" (map 'list #'format-point (chaos-game 10000 *shape-points*))))) |
Uh oh!
There was an error while loading. Please reload this page.