Minor change to render-world towards allowing heightmaps to be selected.
This commit is contained in:
parent
b666540ac9
commit
dc4581924f
|
@ -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"> </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"> </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
|
||||||
|
|
|
@ -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 & rest]]
|
[[property IS IN & rest]]
|
||||||
(if (and (member? IS '("is" "are")) (= IN "in"))
|
(if (and (member? IS '("is" "are")) (= IN "in"))
|
||||||
(let [[l remainder] (parse-disjunct-value (cons "in" rest) false)]
|
(let [[l remainder] (parse-disjunct-value (cons "in" 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 & rest]]
|
[[property IS LESS THAN & rest]]
|
||||||
(cond (and (member? IS '("is" "are")) (member? LESS '("less" "fewer")) (= THAN "than"))
|
(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.</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 & rest]]
|
[[MORE THAN n NEIGHBOURS have-or-are & 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 "have")
|
(= have-or-are "have")
|
||||||
(let [[property comp1 comp2 value & remainder] rest]
|
(let [[property comp1 comp2 value & remainder] rest]
|
||||||
(cond (and (= comp1 "equal") (= comp2 "to"))
|
(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"))
|
(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"))
|
(and (= comp1 "less") (= comp2 "than"))
|
||||||
(gen-neighbours-condition comparator quantity property value remainder '<)))))))</pre></td></tr><tr><td class="docs">
|
(gen-neighbours-condition comparator quantity property value remainder <)))))))</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 & rest]]
|
[[SOME NEIGHBOURS & rest]]
|
||||||
(cond
|
(cond
|
||||||
|
@ -3242,15 +3244,15 @@ front of the sequence of tokens it returns nil.</p>
|
||||||
(cond
|
(cond
|
||||||
(= have-or-are "are")
|
(= have-or-are "are")
|
||||||
(let [[value & remainder] rest]
|
(let [[value & remainder] rest]
|
||||||
(gen-neighbours-condition '= quantity :state value remainder))
|
(gen-neighbours-condition '= quantity :state value remainder =))
|
||||||
(= have-or-are "have")
|
(= have-or-are "have")
|
||||||
(let [[property comp1 comp2 value & remainder] rest]
|
(let [[property comp1 comp2 value & remainder] rest]
|
||||||
(cond (and (= comp1 "equal") (= comp2 "to"))
|
(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"))
|
(and (= comp1 "more") (= comp2 "than"))
|
||||||
(gen-neighbours-condition '> quantity property value remainder '>)
|
(gen-neighbours-condition '= quantity property value remainder >)
|
||||||
(and (= comp1 "less") (= comp2 "than"))
|
(and (= comp1 "less") (= comp2 "than"))
|
||||||
(gen-neighbours-condition '< quantity property value remainder '<)))))))</pre></td></tr><tr><td class="docs"><p>Parse conditions referring to neighbours</p>
|
(gen-neighbours-condition '= quantity property value remainder <)))))))</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
|
||||||
|
|
|
@ -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)
|
;;"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"))
|
||||||
|
|
|
@ -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"))
|
||||||
|
|
Loading…
Reference in a new issue