Minor change to render-world towards allowing heightmaps to be selected.

This commit is contained in:
Simon Brooke 2014-07-17 09:52:58 +01:00
parent b666540ac9
commit dc4581924f
4 changed files with 35 additions and 21 deletions

View file

@ -3107,6 +3107,7 @@ ignored). Darker shades are higher.</p>
</td><td class="codes"><pre class="brush: clojure">(ns mw-engine.heightmap </td><td class="codes"><pre class="brush: clojure">(ns mw-engine.heightmap
(:import [java.awt.image BufferedImage]) (:import [java.awt.image BufferedImage])
(:use mw-engine.utils (:use mw-engine.utils
mw-engine.world
;; interestingly the imagez load-image is failing for me, while the ;; interestingly the imagez load-image is failing for me, while the
;; collage version is problem free. ;; collage version is problem free.
[mikera.image.core :only [filter-image get-pixels]] [mikera.image.core :only [filter-image get-pixels]]
@ -3156,14 +3157,24 @@ ignored). Darker shades are higher.</p>
the heightmap is at least as large in x and y dimensions as the world.</p> the heightmap is at least as large in x and y dimensions as the world.</p>
<ul> <ul>
<li><code>world</code> a world, as defined in <code>world.clj</code>, q.v.;</li> <li><code>world</code> a world, as defined in <code>world.clj</code>, q.v.; if world is not supplied,
a world the size of the heightmap will be created.</li>
<li><code>imagepath</code> a file path or URL which indicates an image file.</li> <li><code>imagepath</code> a file path or URL which indicates an image file.</li>
</ul> </ul>
</td><td class="codes"><pre class="brush: clojure">(defn apply-heightmap </td><td class="codes"><pre class="brush: clojure">(defn apply-heightmap
[world imagepath] ([world imagepath]
;; bizarrely, the collage load-util is working for me, but the imagez version isn't. ;; bizarrely, the collage load-util is working for me, but the imagez version isn't.
(let [heightmap (filter-image (grayscale)(load-image imagepath))] (let [heightmap (filter-image (grayscale)(load-image imagepath))]
(apply vector (map #(apply-heightmap-row % heightmap) world))))</pre></td></tr><tr><td class="spacer docs">&nbsp;</td><td class="codes" /></tr><tr><td class="docs"><div class="docs-header"><a class="anchor" href="#mw-engine.natural-rules" name="mw-engine.natural-rules"><h1 class="project-name">mw-engine.natural-rules</h1><a class="toc-link" href="#toc">toc</a></a></div></td><td class="codes" /></tr><tr><td class="docs"><p>A set of MicroWorld rules describing a simplified natural ecosystem.</p> (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)))))</pre></td></tr><tr><td class="spacer docs">&nbsp;</td><td class="codes" /></tr><tr><td class="docs"><div class="docs-header"><a class="anchor" href="#mw-engine.natural-rules" name="mw-engine.natural-rules"><h1 class="project-name">mw-engine.natural-rules</h1><a class="toc-link" href="#toc">toc</a></a></div></td><td class="codes" /></tr><tr><td class="docs"><p>A set of MicroWorld rules describing a simplified natural ecosystem.</p>
<p>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.</p>
</td><td class="codes"></td></tr><tr><td class="docs"> </td><td class="codes"></td></tr><tr><td class="docs">
</td><td class="codes"><pre class="brush: clojure">(ns mw-engine.natural-rules </td><td class="codes"><pre class="brush: clojure">(ns mw-engine.natural-rules
(:use mw-engine.utils (:use mw-engine.utils

View file

@ -3158,11 +3158,11 @@ front of the sequence of tokens it returns nil.</p>
(parse-simple-value tokens))) (parse-simple-value tokens)))
([tokens] ([tokens]
(parse-value tokens false)))</pre></td></tr><tr><td class="docs"><p>Parses a condition of the form '[property] in [value] or [value]...'</p> (parse-value tokens false)))</pre></td></tr><tr><td class="docs"><p>Parses a condition of the form '[property] in [value] or [value]...'</p>
</td><td class="codes"><pre class="brush: clojure">(defn- parse-member-condition </td><td class="codes"><pre class="brush: clojure">(defn parse-member-condition
[[property IS IN &amp; rest]] [[property IS IN &amp; rest]]
(if (and (member? IS '(&quot;is&quot; &quot;are&quot;)) (= IN &quot;in&quot;)) (if (and (member? IS '(&quot;is&quot; &quot;are&quot;)) (= IN &quot;in&quot;))
(let [[l remainder] (parse-disjunct-value (cons &quot;in&quot; rest) false)] (let [[l remainder] (parse-disjunct-value (cons &quot;in&quot; rest) false)]
[(list 'member? (keyword property) l) remainder])))</pre></td></tr><tr><td class="docs"><p>Parse '[property] less than [value]'.</p> [(list 'member? (list (keyword property) 'cell) (list 'quote l)) remainder])))</pre></td></tr><tr><td class="docs"><p>Parse '[property] less than [value]'.</p>
</td><td class="codes"><pre class="brush: clojure">(defn- parse-less-condition </td><td class="codes"><pre class="brush: clojure">(defn- parse-less-condition
[[property IS LESS THAN &amp; rest]] [[property IS LESS THAN &amp; rest]]
(cond (and (member? IS '(&quot;is&quot; &quot;are&quot;)) (member? LESS '(&quot;less&quot; &quot;fewer&quot;)) (= THAN &quot;than&quot;)) (cond (and (member? IS '(&quot;is&quot; &quot;are&quot;)) (member? LESS '(&quot;less&quot; &quot;fewer&quot;)) (= THAN &quot;than&quot;))
@ -3200,13 +3200,15 @@ front of the sequence of tokens it returns nil.</p>
(let [[condition remainder] partial] (let [[condition remainder] partial]
[(list 'not condition) remainder])))))</pre></td></tr><tr><td class="docs"> [(list 'not condition) remainder])))))</pre></td></tr><tr><td class="docs">
</td><td class="codes"><pre class="brush: clojure">(defn- gen-neighbours-condition </td><td class="codes"><pre class="brush: clojure">(defn- gen-neighbours-condition
[comparator quantity property value remainder comp2] ([comp1 quantity property value remainder comp2 distance]
[(list comparator [(list comp1
(list 'count (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)) (keyword property) (keyword-or-numeric value) comp2))
quantity) quantity)
remainder])</pre></td></tr><tr><td class="docs"><p>Parse conditions of the form '...more than 6 neighbours are [condition]'</p> remainder])
([comp1 quantity property value remainder comp2]
(gen-neighbours-condition comp1 quantity property value remainder comp2 1)))</pre></td></tr><tr><td class="docs"><p>Parse conditions of the form '...more than 6 neighbours are [condition]'</p>
</td><td class="codes"><pre class="brush: clojure">(defn parse-comparator-neighbours-condition </td><td class="codes"><pre class="brush: clojure">(defn parse-comparator-neighbours-condition
[[MORE THAN n NEIGHBOURS have-or-are &amp; rest]] [[MORE THAN n NEIGHBOURS have-or-are &amp; rest]]
(let [quantity (first (parse-numeric-value (list n))) (let [quantity (first (parse-numeric-value (list n)))
@ -3224,11 +3226,11 @@ front of the sequence of tokens it returns nil.</p>
(= have-or-are &quot;have&quot;) (= have-or-are &quot;have&quot;)
(let [[property comp1 comp2 value &amp; remainder] rest] (let [[property comp1 comp2 value &amp; remainder] rest]
(cond (and (= comp1 &quot;equal&quot;) (= comp2 &quot;to&quot;)) (cond (and (= comp1 &quot;equal&quot;) (= comp2 &quot;to&quot;))
(gen-neighbours-condition comparator quantity property value remainder '=) (gen-neighbours-condition comparator quantity property value remainder =)
(and (= comp1 &quot;more&quot;) (= comp2 &quot;than&quot;)) (and (= comp1 &quot;more&quot;) (= comp2 &quot;than&quot;))
(gen-neighbours-condition comparator quantity property value remainder '&gt;) (gen-neighbours-condition comparator quantity property value remainder &gt;)
(and (= comp1 &quot;less&quot;) (= comp2 &quot;than&quot;)) (and (= comp1 &quot;less&quot;) (= comp2 &quot;than&quot;))
(gen-neighbours-condition comparator quantity property value remainder '&lt;)))))))</pre></td></tr><tr><td class="docs"> (gen-neighbours-condition comparator quantity property value remainder &lt;)))))))</pre></td></tr><tr><td class="docs">
</td><td class="codes"><pre class="brush: clojure">(defn parse-some-neighbours-condition </td><td class="codes"><pre class="brush: clojure">(defn parse-some-neighbours-condition
[[SOME NEIGHBOURS &amp; rest]] [[SOME NEIGHBOURS &amp; rest]]
(cond (cond
@ -3242,15 +3244,15 @@ front of the sequence of tokens it returns nil.</p>
(cond (cond
(= have-or-are &quot;are&quot;) (= have-or-are &quot;are&quot;)
(let [[value &amp; remainder] rest] (let [[value &amp; remainder] rest]
(gen-neighbours-condition '= quantity :state value remainder)) (gen-neighbours-condition '= quantity :state value remainder =))
(= have-or-are &quot;have&quot;) (= have-or-are &quot;have&quot;)
(let [[property comp1 comp2 value &amp; remainder] rest] (let [[property comp1 comp2 value &amp; remainder] rest]
(cond (and (= comp1 &quot;equal&quot;) (= comp2 &quot;to&quot;)) (cond (and (= comp1 &quot;equal&quot;) (= comp2 &quot;to&quot;))
(gen-neighbours-condition '= quantity property value remainder) (gen-neighbours-condition '= quantity property value remainder =)
(and (= comp1 &quot;more&quot;) (= comp2 &quot;than&quot;)) (and (= comp1 &quot;more&quot;) (= comp2 &quot;than&quot;))
(gen-neighbours-condition '&gt; quantity property value remainder '&gt;) (gen-neighbours-condition '= quantity property value remainder &gt;)
(and (= comp1 &quot;less&quot;) (= comp2 &quot;than&quot;)) (and (= comp1 &quot;less&quot;) (= comp2 &quot;than&quot;))
(gen-neighbours-condition '&lt; quantity property value remainder '&lt;)))))))</pre></td></tr><tr><td class="docs"><p>Parse conditions referring to neighbours</p> (gen-neighbours-condition '= quantity property value remainder &lt;)))))))</pre></td></tr><tr><td class="docs"><p>Parse conditions referring to neighbours</p>
</td><td class="codes"><pre class="brush: clojure">(defn parse-neighbours-condition </td><td class="codes"><pre class="brush: clojure">(defn parse-neighbours-condition
[tokens] [tokens]
(or (or

View file

@ -3151,8 +3151,8 @@ net.brehaut.ClojureTools = (function (SH) {
(let [world (or (session/get :world) (let [world (or (session/get :world)
(engine/transform-world (engine/transform-world
(heightmap/apply-heightmap (heightmap/apply-heightmap
(world/make-world 20 20) ;;&quot;resources/public/img/20x20/hill.png&quot;
&quot;resources/public/img/20x20/hill.png&quot;) &quot;resources/public/img/heightmaps/great_britain_and_ireland_small.png&quot;)
rules/init-rules)) rules/init-rules))
rules (or (session/get :rules) rules (or (session/get :rules)
(do (session/put! :rules (compiler/compile-file &quot;resources/rulesets/basic.txt&quot;)) (do (session/put! :rules (compiler/compile-file &quot;resources/rulesets/basic.txt&quot;))

View file

@ -41,8 +41,9 @@
(let [world (or (session/get :world) (let [world (or (session/get :world)
(engine/transform-world (engine/transform-world
(heightmap/apply-heightmap (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/init-rules))
rules (or (session/get :rules) rules (or (session/get :rules)
(do (session/put! :rules (compiler/compile-file "resources/rulesets/basic.txt")) (do (session/put! :rules (compiler/compile-file "resources/rulesets/basic.txt"))