From dc4581924fc99a08df85102943a3ce306d769fa4 Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Thu, 17 Jul 2014 09:52:58 +0100 Subject: [PATCH] Minor change to render-world towards allowing heightmaps to be selected. --- resources/public/docs/mw-engine/uberdoc.html | 19 ++++++++++--- resources/public/docs/mw-parser/uberdoc.html | 28 +++++++++++--------- resources/public/docs/mw-ui/uberdoc.html | 4 +-- src/mw_ui/render_world.clj | 5 ++-- 4 files changed, 35 insertions(+), 21 deletions(-) diff --git a/resources/public/docs/mw-engine/uberdoc.html b/resources/public/docs/mw-engine/uberdoc.html index 81e3588..8a15e4b 100644 --- a/resources/public/docs/mw-engine/uberdoc.html +++ b/resources/public/docs/mw-engine/uberdoc.html @@ -3107,6 +3107,7 @@ ignored). Darker shades are higher.

(ns mw-engine.heightmap
   (:import [java.awt.image BufferedImage])
   (:use mw-engine.utils
+        mw-engine.world
         ;; interestingly the imagez load-image is failing for me, while the
         ;; collage version is problem free.
         [mikera.image.core :only [filter-image get-pixels]]
@@ -3156,14 +3157,24 @@ ignored). Darker shades are higher.

the heightmap is at least as large in x and y dimensions as the world.

(defn apply-heightmap
-  [world imagepath]
+  ([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))))
 

A set of MicroWorld rules describing a simplified natural ecosystem.

+ (let [heightmap (filter-image (grayscale)(load-image imagepath))] + (apply vector (map #(apply-heightmap-row % heightmap) world)))) + ([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.

+ +

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 +that you can't do in the rule language, but not many and I doubt they're +important.

(ns mw-engine.natural-rules
   (:use mw-engine.utils
diff --git a/resources/public/docs/mw-parser/uberdoc.html b/resources/public/docs/mw-parser/uberdoc.html
index 7032d5b..d40132a 100644
--- a/resources/public/docs/mw-parser/uberdoc.html
+++ b/resources/public/docs/mw-parser/uberdoc.html
@@ -3158,11 +3158,11 @@ front of the sequence of tokens it returns nil.

(parse-simple-value tokens))) ([tokens] (parse-value tokens false)))

Parses a condition of the form '[property] in [value] or [value]...'

-
(defn- parse-member-condition
+
(defn parse-member-condition
   [[property IS IN & rest]]
   (if (and (member? IS '("is" "are")) (= IN "in"))
     (let [[l remainder] (parse-disjunct-value (cons "in" rest) false)]
-      [(list 'member? (keyword property) l) remainder])))

Parse '[property] less than [value]'.

+ [(list 'member? (list (keyword property) 'cell) (list 'quote l)) remainder])))

Parse '[property] less than [value]'.

(defn- parse-less-condition
   [[property IS LESS THAN & rest]]
   (cond (and (member? IS '("is" "are")) (member? LESS '("less" "fewer")) (= THAN "than"))
@@ -3200,13 +3200,15 @@ front of the sequence of tokens it returns nil.

(let [[condition remainder] partial] [(list 'not condition) remainder])))))
(defn- gen-neighbours-condition
-  [comparator quantity property value remainder comp2] 
-  [(list comparator  
+  ([comp1 quantity property value remainder comp2 distance] 
+    [(list comp1  
          (list 'count
-               (list 'get-neighbours-with-property-value 'world '(cell :x) '(cell :y) 
+               (list 'get-neighbours-with-property-value 'world '(cell :x) '(cell :y) 1
                      (keyword property) (keyword-or-numeric value) comp2))
          quantity)
-           remainder])

Parse conditions of the form '...more than 6 neighbours are [condition]'

+ remainder]) + ([comp1 quantity property value remainder comp2] + (gen-neighbours-condition comp1 quantity property value remainder comp2 1)))

Parse conditions of the form '...more than 6 neighbours are [condition]'

(defn parse-comparator-neighbours-condition
   [[MORE THAN n NEIGHBOURS have-or-are & rest]]
   (let [quantity (first (parse-numeric-value (list n)))
@@ -3224,11 +3226,11 @@ front of the sequence of tokens it returns nil.

(= have-or-are "have") (let [[property comp1 comp2 value & remainder] rest] (cond (and (= comp1 "equal") (= comp2 "to")) - (gen-neighbours-condition comparator quantity property value remainder '=) + (gen-neighbours-condition comparator quantity property value remainder =) (and (= comp1 "more") (= comp2 "than")) - (gen-neighbours-condition comparator quantity property value remainder '>) + (gen-neighbours-condition comparator quantity property value remainder >) (and (= comp1 "less") (= comp2 "than")) - (gen-neighbours-condition comparator quantity property value remainder '<)))))))
+ (gen-neighbours-condition comparator quantity property value remainder <)))))))
(defn parse-some-neighbours-condition
   [[SOME NEIGHBOURS & rest]]
   (cond
@@ -3242,15 +3244,15 @@ front of the sequence of tokens it returns nil.

(cond (= have-or-are "are") (let [[value & remainder] rest] - (gen-neighbours-condition '= quantity :state value remainder)) + (gen-neighbours-condition '= quantity :state value remainder =)) (= have-or-are "have") (let [[property comp1 comp2 value & remainder] rest] (cond (and (= comp1 "equal") (= comp2 "to")) - (gen-neighbours-condition '= quantity property value remainder) + (gen-neighbours-condition '= quantity property value remainder =) (and (= comp1 "more") (= comp2 "than")) - (gen-neighbours-condition '> quantity property value remainder '>) + (gen-neighbours-condition '= quantity property value remainder >) (and (= comp1 "less") (= comp2 "than")) - (gen-neighbours-condition '< quantity property value remainder '<)))))))

Parse conditions referring to neighbours

+ (gen-neighbours-condition '= quantity property value remainder <)))))))

Parse conditions referring to neighbours

(defn parse-neighbours-condition
   [tokens]
   (or
diff --git a/resources/public/docs/mw-ui/uberdoc.html b/resources/public/docs/mw-ui/uberdoc.html
index c2cde8a..7953467 100644
--- a/resources/public/docs/mw-ui/uberdoc.html
+++ b/resources/public/docs/mw-ui/uberdoc.html
@@ -3151,8 +3151,8 @@ net.brehaut.ClojureTools = (function (SH) {
   (let [world (or (session/get :world)
                   (engine/transform-world
                    (heightmap/apply-heightmap
-                    (world/make-world 20 20)
-                    "resources/public/img/20x20/hill.png")
+                     ;;"resources/public/img/20x20/hill.png"
+                     "resources/public/img/heightmaps/great_britain_and_ireland_small.png")
                    rules/init-rules))
         rules (or (session/get :rules) 
                   (do (session/put! :rules (compiler/compile-file "resources/rulesets/basic.txt"))
diff --git a/src/mw_ui/render_world.clj b/src/mw_ui/render_world.clj
index 473eb79..896b1d1 100644
--- a/src/mw_ui/render_world.clj
+++ b/src/mw_ui/render_world.clj
@@ -41,8 +41,9 @@
   (let [world (or (session/get :world)
                   (engine/transform-world
                    (heightmap/apply-heightmap
-                    (world/make-world 20 20)
-                    "resources/public/img/20x20/hill.png")
+                     ;;"resources/public/img/20x20/hill.png"
+                     "resources/public/img/heightmaps/great_britain_and_ireland_small.png"
+                     )
                    rules/init-rules))
         rules (or (session/get :rules) 
                   (do (session/put! :rules (compiler/compile-file "resources/rulesets/basic.txt"))