New test build with gradients.
This commit is contained in:
parent
b995425bf1
commit
2695554607
|
@ -1,6 +1,6 @@
|
||||||
(defproject mw-ui "0.1.2-SNAPSHOT"
|
(defproject mw-ui "0.1.2-SNAPSHOT"
|
||||||
:description "Web-based user interface for MicroWorld"
|
: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"]
|
:dependencies [[org.clojure/clojure "1.6.0"]
|
||||||
[mw-engine "0.1.2-SNAPSHOT"]
|
[mw-engine "0.1.2-SNAPSHOT"]
|
||||||
[mw-parser "0.1.2-SNAPSHOT"]
|
[mw-parser "0.1.2-SNAPSHOT"]
|
||||||
|
|
|
@ -3136,25 +3136,40 @@ ignored). Darker shades are higher.</p>
|
||||||
</ul>
|
</ul>
|
||||||
</td><td class="codes"><pre class="brush: clojure">(defn- abs
|
</td><td class="codes"><pre class="brush: clojure">(defn- abs
|
||||||
[n]
|
[n]
|
||||||
(cond (< n 0) (- 0 n) true n))</pre></td></tr><tr><td class="docs"><p>Set the altitude of this cell from the corresponding pixel of this heightmap.
|
(cond (< n 0) (- 0 n) true n))</pre></td></tr><tr><td class="docs"><p>Set the <code>gradient</code> property of this <code>cell</code> of this <code>world</code> to the difference in
|
||||||
|
altitude between its highest and lowest neghbours.</p>
|
||||||
|
</td><td class="codes"><pre class="brush: clojure">(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)})))</pre></td></tr><tr><td class="docs"><p>Set the <code>gradient</code> property of each cell in this <code>world</code> to the difference in
|
||||||
|
altitude between its highest and lowest neghbours.</p>
|
||||||
|
</td><td class="codes"><pre class="brush: clojure">(defn tag-gradients
|
||||||
|
[world]
|
||||||
|
(map-world world tag-gradient))</pre></td></tr><tr><td class="docs"><p>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.</p>
|
If the heightmap you supply is smaller than the world, this will break.</p>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
|
<li><code>world</code> not actually used, but present to enable this function to be
|
||||||
|
passed as an argument to <code>mw-engine.utils/map-world</code>, q.v.</li>
|
||||||
<li><code>cell</code> a cell, as discussed in world.clj, q.v. Alternatively, a map;</li>
|
<li><code>cell</code> a cell, as discussed in world.clj, q.v. Alternatively, a map;</li>
|
||||||
<li><code>heightmap</code> an (ideally) greyscale image, whose x and y dimensions should
|
<li><code>heightmap</code> an (ideally) greyscale image, whose x and y dimensions should
|
||||||
exceed those of the world of which the <code>cell</code> forms part.</li>
|
exceed those of the world of which the <code>cell</code> forms part.</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td><td class="codes"><pre class="brush: clojure">(defn transform-altitude
|
</td><td class="codes"><pre class="brush: clojure">(defn transform-altitude
|
||||||
[cell heightmap]
|
([world cell heightmap]
|
||||||
(merge cell
|
(transform-altitude cell heightmap))
|
||||||
{:altitude
|
([cell heightmap]
|
||||||
(+ (get-int cell :altitude)
|
(merge cell
|
||||||
(- 256
|
{:altitude
|
||||||
(abs
|
(+ (get-int cell :altitude)
|
||||||
(mod
|
(- 256
|
||||||
(.getRGB heightmap
|
(abs
|
||||||
(get-int cell :x)
|
(mod
|
||||||
(get-int cell :y)) 256))))}))</pre></td></tr><tr><td class="docs"><p>Set the altitude of each cell in this sequence from the corresponding pixel
|
(.getRGB heightmap
|
||||||
|
(get-int cell :x)
|
||||||
|
(get-int cell :y)) 256))))})))</pre></td></tr><tr><td class="docs"><p>Set the altitude of each cell in this sequence from the corresponding pixel
|
||||||
of this heightmap.
|
of this heightmap.
|
||||||
If the heightmap you supply is smaller than the world, this will break.</p>
|
If the heightmap you supply is smaller than the world, this will break.</p>
|
||||||
|
|
||||||
|
@ -3179,11 +3194,15 @@ a world the size of the heightmap will be created.</li>
|
||||||
([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))))
|
(map-world
|
||||||
([imagepath]
|
(map-world world transform-altitude (list heightmap))
|
||||||
|
tag-gradient)))
|
||||||
|
([imagepath]
|
||||||
(let [heightmap (filter-image (grayscale)(load-image imagepath))
|
(let [heightmap (filter-image (grayscale)(load-image imagepath))
|
||||||
world (make-world (.getWidth heightmap) (.getHeight heightmap))]
|
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>
|
(map-world
|
||||||
|
(map-world world transform-altitude (list heightmap))
|
||||||
|
tag-gradient))))</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 -
|
<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
|
there are still a few things that you can do with rules written in Clojure
|
||||||
|
@ -3339,7 +3358,18 @@ important.</p>
|
||||||
</ul>
|
</ul>
|
||||||
</td><td class="codes"><pre class="brush: clojure">(defn in-bounds
|
</td><td class="codes"><pre class="brush: clojure">(defn in-bounds
|
||||||
[world x y]
|
[world x y]
|
||||||
(and (>= x 0)(>= y 0)(< y (count world))(< x (count (first world)))))</pre></td></tr><tr><td class="docs"><p>Return the cell a x, y in this world, if any.</p>
|
(and (>= x 0)(>= y 0)(< y (count world))(< x (count (first world)))))</pre></td></tr><tr><td class="docs"><p>Apply this <code>function</code> to each cell in this <code>world</code> to produce a new world.
|
||||||
|
the arguments to the function will be the cell, the world, and any
|
||||||
|
<code>additional-args</code> supplied</p>
|
||||||
|
</td><td class="codes"><pre class="brush: clojure">(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))))))</pre></td></tr><tr><td class="docs"><p>Return the cell a x, y in this world, if any.</p>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
<li><code>world</code> a world as defined above;</li>
|
<li><code>world</code> a world as defined above;</li>
|
||||||
|
|
Loading…
Reference in a new issue