Skip to content

Commit

Permalink
Added readme. Pushing to github.
Browse files Browse the repository at this point in the history
  • Loading branch information
maacl committed Aug 16, 2020
1 parent 545d038 commit 8b5f3cf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
25 changes: 11 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
# wfclj

A Clojure library designed to ... well, that part is up to you.
A Clojure implementation of the Wave Function Collapse algorithm invented by Maxim Gumin.

## Usage
https://github.com/mxgmn/WaveFunctionCollapse

FIXME
This implementation is inspired by the Python version referenced in this article: https://robertheaton.com/2018/12/17/wavefunction-collapse-algorithm/

## License
## Usage

Copyright © 2020 FIXME
(print-grid
(make-grid-and-run 20 20 input-matrix-1))

This will derive the weights and compatibilities from the tiles in input-matrix-1, construct a 20 x 20 grid based on these, and run the algorithm on it.

This program and the accompanying materials are made available under the
terms of the Eclipse Public License 2.0 which is available at
http://www.eclipse.org/legal/epl-2.0.
## License

This Source Code may also be made available under the following Secondary
Licenses when the conditions for such availability set forth in the Eclipse
Public License, v. 2.0 are satisfied: GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or (at your
option) any later version, with the GNU Classpath Exception which is available
at https://www.gnu.org/software/classpath/license.html.
Apache 2.0
Copyright © 2020 Martin Clausen
8 changes: 4 additions & 4 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
(defproject wfclj "0.1.0-SNAPSHOT"
:description "FIXME: write description"
(defproject wfclj "0.3.0"
:description "Toy implementation of the wave function collapse algorithm inspired by this python version: https://github.com/robert/wavefunction-collapse Authorative information regarding the algo is availale here: https://gridbugs.org/wave-function-collapse/#:~:text=Wave%20Function%20Collapse%20is%20a,frequently%20each%20tile%20should%20appear."
:url "http://example.com/FIXME"
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
:url "https://www.eclipse.org/legal/epl-2.0/"}
:license {:name "APACHE LICENSE, VERSION 2.0"
:url "https://www.apache.org/licenses/LICENSE-2.0"}
:dependencies [[org.clojure/clojure "1.10.1"]
[clojure-term-colors "0.1.0"]
[clansi "1.0.0"]]
Expand Down
25 changes: 19 additions & 6 deletions src/wfclj/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
(:require [clojure.inspector]
[clojure.set]
[clojure.pprint]
[clojure.term.colors :refer :all]
[clansi :refer :all]))

;;shared logic
Expand Down Expand Up @@ -50,17 +49,21 @@

(defn colorize [kw]
(get {:l (style "l" :bg-green)
:c (style "c" :bg-yellow)
:s (style "s" :bg-blue)}
:c (style "c" :bg-yellow)
:s (style "s" :bg-blue)
:A (style "A" :bg-green)
:B (style "B" :bg-black)
:C (style "C" :bg-yellow)}
kw))

(defn print-grid [grid]
(let [cols (:cols (meta grid))]
(clojure.pprint/pprint
(println
(clojure.string/join "\n"
(for [row (partition cols grid)]
(apply str
(map (fn [[_ [l _]]]
(colorize (first l))) row))))))
(colorize (first l))) row)))))))

(defn collapsed-val [loc grid]
(ffirst (get grid loc)))
Expand Down Expand Up @@ -171,6 +174,13 @@
(run
(vary-meta grid merge {:comps compatibillities :weights weights}))))

(defn make-grid-and-run [x-dim y-dim input-matrix]
(let [compatibillities (derive-compatibillities input-matrix)
weights (derive-weights input-matrix)
tiles (set (keys weights))]
(run
(vary-meta (make-grid x-dim y-dim tiles) merge {:comps compatibillities :weights weights}))))

(def input-matrix-1
[[:l :l :l :l]
[:l :l :l :l]
Expand All @@ -190,6 +200,9 @@
[:C :B :B :C]])

(print-grid
(derive-and-run (make-grid 20 20 #{:l :c :s}) input-matrix-1)
(make-grid-and-run 20 20 input-matrix-1))

(print-grid
(derive-and-run (make-grid 20 20 #{:l :c :s}) input-matrix-1)
;;(derive-and-run (make-grid 20 20 #{:A :B :C}) input-matrix-2)
)

0 comments on commit 8b5f3cf

Please sign in to comment.