From 2695554607bd99d90b16af6f6baede43a6c38dd5 Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Fri, 25 Jul 2014 09:58:54 +0100 Subject: [PATCH] New test build with gradients. --- project.clj | 2 +- resources/public/docs/mw-engine/uberdoc.html | 60 +++++++++++++++----- 2 files changed, 46 insertions(+), 16 deletions(-) diff --git a/project.clj b/project.clj index a588c51..609e3e1 100644 --- a/project.clj +++ b/project.clj @@ -1,6 +1,6 @@ (defproject mw-ui "0.1.2-SNAPSHOT" :description "Web-based user interface for MicroWorld" - :url "http://example.com/FIXME" + :url "http://www.journeyman.cc/microworld" :dependencies [[org.clojure/clojure "1.6.0"] [mw-engine "0.1.2-SNAPSHOT"] [mw-parser "0.1.2-SNAPSHOT"] diff --git a/resources/public/docs/mw-engine/uberdoc.html b/resources/public/docs/mw-engine/uberdoc.html index 7e96834..18e674e 100644 --- a/resources/public/docs/mw-engine/uberdoc.html +++ b/resources/public/docs/mw-engine/uberdoc.html @@ -3136,25 +3136,40 @@ ignored). Darker shades are higher.

(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.

(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))))) 

mw-engine.natural-rules

toc

A set of MicroWorld rules describing a simplified natural ecosystem.

+ (map-world + (map-world world transform-altitude (list heightmap)) + tag-gradient)))) 

mw-engine.natural-rules

toc

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.