diff --git a/terranostra.lisp b/terranostra.lisp index ea802f5..b8cd071 100644 --- a/terranostra.lisp +++ b/terranostra.lisp @@ -87,6 +87,7 @@ (defun create-mountains (world &optional (montaneity 2)) "Create mountains and hills. Montaneity determines number and height." + ;;XXX Takes too long to calculate if world size > 100 (do ((n 0 (1+ n)) (npeaks (random (* (/ montaneity 500) (* (length world) (length world)))))) @@ -96,24 +97,31 @@ (defun create-peak (xcoord ycoord height montaneity world) "Create a mountain peak at the specified location" + ;;TODO Can I make this more computationally efficient? + (unless (< (patch-alt (coord xcoord ycoord world)) height) + (return-from create-peak)) (format t "~&Creating a peak of ~Sm at ~S/~S" height xcoord ycoord) (setf (patch-alt (coord xcoord ycoord world)) height) + ;; Process concentric squares in increasing distance from the peak (do ((dist 1 (1+ dist)) (levelp NIL)) (levelp) (setf levelp T) (do ((x (- xcoord dist) (1+ x))) ((> x (+ xcoord dist))) (do* ((y (- ycoord dist) (1+ y)) + ;; Get the current patch and its center-side neighbour (p (coord x y world) (coord x y world)) (np (when p (neighbour p (dir2patch x y xcoord ycoord) world)) (when p (neighbour p (dir2patch x y xcoord ycoord) world)))) ((> y (+ ycoord dist))) + ;; Only calculate existing patches that haven't been done yet (when (and p (or (= (abs (- xcoord x)) dist) (= (abs (- ycoord y)) dist))) (let ((new-alt (- (patch-alt np) (random (* montaneity 5))))) + ;; Eventually, a hill levels out (when (and (> new-alt *base-height*) (> new-alt (patch-alt p))) (setf (patch-alt p) new-alt) @@ -123,7 +131,7 @@ "Create valleys through streams. Aqueousness determines their number." (do* ((n 0 (1+ n)) (size (length world)) (x (random size) (random size)) (y (random size) (random size)) - (nstreams (random (* (/ aqueousness 100) (* size size))))) + (nstreams (random (* (/ aqueousness 500) (* size size))))) ((= n nstreams)) (format t "~&Creating a stream from ~S/~S" x y) (create-stream x y world))) diff --git a/terranostra.lisp b/terranostra.lisp index ea802f5..b8cd071 100644 --- a/terranostra.lisp +++ b/terranostra.lisp @@ -87,6 +87,7 @@ (defun create-mountains (world &optional (montaneity 2)) "Create mountains and hills. Montaneity determines number and height." + ;;XXX Takes too long to calculate if world size > 100 (do ((n 0 (1+ n)) (npeaks (random (* (/ montaneity 500) (* (length world) (length world)))))) @@ -96,24 +97,31 @@ (defun create-peak (xcoord ycoord height montaneity world) "Create a mountain peak at the specified location" + ;;TODO Can I make this more computationally efficient? + (unless (< (patch-alt (coord xcoord ycoord world)) height) + (return-from create-peak)) (format t "~&Creating a peak of ~Sm at ~S/~S" height xcoord ycoord) (setf (patch-alt (coord xcoord ycoord world)) height) + ;; Process concentric squares in increasing distance from the peak (do ((dist 1 (1+ dist)) (levelp NIL)) (levelp) (setf levelp T) (do ((x (- xcoord dist) (1+ x))) ((> x (+ xcoord dist))) (do* ((y (- ycoord dist) (1+ y)) + ;; Get the current patch and its center-side neighbour (p (coord x y world) (coord x y world)) (np (when p (neighbour p (dir2patch x y xcoord ycoord) world)) (when p (neighbour p (dir2patch x y xcoord ycoord) world)))) ((> y (+ ycoord dist))) + ;; Only calculate existing patches that haven't been done yet (when (and p (or (= (abs (- xcoord x)) dist) (= (abs (- ycoord y)) dist))) (let ((new-alt (- (patch-alt np) (random (* montaneity 5))))) + ;; Eventually, a hill levels out (when (and (> new-alt *base-height*) (> new-alt (patch-alt p))) (setf (patch-alt p) new-alt) @@ -123,7 +131,7 @@ "Create valleys through streams. Aqueousness determines their number." (do* ((n 0 (1+ n)) (size (length world)) (x (random size) (random size)) (y (random size) (random size)) - (nstreams (random (* (/ aqueousness 100) (* size size))))) + (nstreams (random (* (/ aqueousness 500) (* size size))))) ((= n nstreams)) (format t "~&Creating a stream from ~S/~S" x y) (create-stream x y world))) diff --git a/visualize.R b/visualize.R index 4dceb27..2fad993 100644 --- a/visualize.R +++ b/visualize.R @@ -17,7 +17,8 @@ } } -jpeg(paste0(world, "_iso.jpg"), width=720, height=720) +l = 720*(length(w)/100) +jpeg(paste0(world, "_iso.jpg"), width=l, height=l) persp(1:(length(w[,1])), 1:(length(w[1,])), as.matrix(w), axes=F, - theta=110, phi=50, expand=0.4, col=cols, box=F, shade=0.3) + theta=110, phi=50, expand=0.4, col=cols, box=F, shade=0.5, border=NA) dev.off()