From 2695554607bd99d90b16af6f6baede43a6c38dd5 Mon Sep 17 00:00:00 2001
From: Simon Brooke
(defn- abs [n] - (cond (< n 0) (- 0 n) true n))
Set the altitude of this cell from the corresponding pixel of this heightmap. + (cond (< n 0) (- 0 n) true n))
Set the gradient
property of this cell
of this world
to the difference in
+ altitude between its highest and lowest neghbours.
(defn tag-gradient + [cell world] + (let [heights (map '(:altitude %) (get-neighbours world cell)) + highest (apply max heights) + lowest (apply min heights)] + #(merge cell {:gradient (- highest lowest)})))
Set the gradient
property of each cell in this world
to the difference in
+ altitude between its highest and lowest neghbours.
(defn tag-gradients + [world] + (map-world world tag-gradient))
Set the altitude of this cell from the corresponding pixel of this heightmap. If the heightmap you supply is smaller than the world, this will break.
world
not actually used, but present to enable this function to be
+ passed as an argument to mw-engine.utils/map-world
, q.v.cell
a cell, as discussed in world.clj, q.v. Alternatively, a map;heightmap
an (ideally) greyscale image, whose x and y dimensions should
exceed those of the world of which the cell
forms part.(defn transform-altitude - [cell heightmap] - (merge cell - {:altitude - (+ (get-int cell :altitude) - (- 256 - (abs - (mod - (.getRGB heightmap - (get-int cell :x) - (get-int cell :y)) 256))))}))
Set the altitude of each cell in this sequence from the corresponding pixel + ([world cell heightmap] + (transform-altitude cell heightmap)) + ([cell heightmap] + (merge cell + {:altitude + (+ (get-int cell :altitude) + (- 256 + (abs + (mod + (.getRGB heightmap + (get-int cell :x) + (get-int cell :y)) 256))))})))
Set the altitude of each cell in this sequence from the corresponding pixel of this heightmap. If the heightmap you supply is smaller than the world, this will break.
@@ -3179,11 +3194,15 @@ a world the size of the heightmap will be created. ([world imagepath] ;; bizarrely, the collage load-util is working for me, but the imagez version isn't. (let [heightmap (filter-image (grayscale)(load-image imagepath))] - (apply vector (map #(apply-heightmap-row % heightmap) world)))) - ([imagepath] + (map-world + (map-world world transform-altitude (list heightmap)) + tag-gradient))) + ([imagepath] (let [heightmap (filter-image (grayscale)(load-image imagepath)) world (make-world (.getWidth heightmap) (.getHeight heightmap))] - (apply vector (map #(apply-heightmap-row % heightmap) world)))))A set of MicroWorld rules describing a simplified natural ecosystem.
+ (map-world + (map-world world transform-altitude (list heightmap)) + tag-gradient))))A set of MicroWorld rules describing a simplified natural ecosystem.
Since the completion of the rule language this is more or less obsolete - there are still a few things that you can do with rules written in Clojure @@ -3339,7 +3358,18 @@ important.
(defn in-bounds [world x y] - (and (>= x 0)(>= y 0)(< y (count world))(< x (count (first world)))))
Return the cell a x, y in this world, if any.
+ (and (>= x 0)(>= y 0)(< y (count world))(< x (count (first world)))))Apply this function
to each cell in this world
to produce a new world.
+ the arguments to the function will be the cell, the world, and any
+ additional-args
supplied
(defn map-world + ([world function] + (map-world world function nil)) + ([world function additional-args] + (apply vector ;; vectors are more efficient for scanning, which we do a lot. + (for [row world] + (apply vector + (map #(apply function (cons world (cons % additional-args))) + row))))))
Return the cell a x, y in this world, if any.
world
a world as defined above;