summary history branches tags files
commit:e30495d33f4cf2c97485a07b2ddc8b8b6b3c823a
author:Trevor Bentley
committer:Trevor Bentley
date:Thu Mar 15 22:59:28 2012 -0400
parents:fc3251a486737824358ec387354d520cbb439b88
Generate level 'segments' from the list of lines, instead of explicit data structures.
diff --git a/resources/public/tempest.js b/resources/public/tempest.js
line changes: +19/-14
index 0c4e5bb..2097293
--- a/resources/public/tempest.js
+++ b/resources/public/tempest.js
@@ -9612,26 +9612,31 @@ cljs.core.prefers = function(a) {
 };
 var tempest = {levels:{}};
 tempest.levels._STAR_default_line_length_STAR_ = 80;
+tempest.levels._STAR_default_length_fn_STAR_ = function(a) {
+  return 4 * a
+};
+tempest.levels.build_unlinked_segment_list = function(a) {
+  return cljs.core.vec.call(null, function(a, c) {
+    for(;;) {
+      if(cljs.core.truth_(cljs.core._EQ_.call(null, a, 0))) {
+        return c
+      }
+      var d = a - 1, e = cljs.core.cons.call(null, cljs.core.Vector.fromArray([a - 1, a]), c), a = d, c = e
+    }
+  }.call(null, a, cljs.core.Vector.fromArray([])))
+};
+tempest.levels.build_segment_list = function(a, b) {
+  var c = tempest.levels.build_unlinked_segment_list.call(null, a);
+  return cljs.core.truth_(!0 === b) ? cljs.core.conj.call(null, c, cljs.core.Vector.fromArray([cljs.core.last.call(null, cljs.core.last.call(null, c)), cljs.core.first.call(null, cljs.core.first.call(null, c))])) : c
+};
 tempest.levels._STAR_level1_lines_STAR_ = cljs.core.Vector.fromArray([cljs.core.Vector.fromArray([113, 225]), cljs.core.Vector.fromArray([99, 234]), cljs.core.Vector.fromArray([90, 243]), cljs.core.Vector.fromArray([84, 252]), cljs.core.Vector.fromArray([81, 261]), cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_, 270]), cljs.core.Vector.fromArray([81, 279]), cljs.core.Vector.fromArray([84, 288]), cljs.core.Vector.fromArray([90, 297]), cljs.core.Vector.fromArray([99, 306]), 
 cljs.core.Vector.fromArray([113, 315])]);
-tempest.levels._STAR_level1_segments_STAR_ = cljs.core.Vector.fromArray([cljs.core.Vector.fromArray([0, 1]), cljs.core.Vector.fromArray([1, 2]), cljs.core.Vector.fromArray([2, 3]), cljs.core.Vector.fromArray([3, 4]), cljs.core.Vector.fromArray([4, 5]), cljs.core.Vector.fromArray([5, 6]), cljs.core.Vector.fromArray([6, 7]), cljs.core.Vector.fromArray([7, 8]), cljs.core.Vector.fromArray([8, 9]), cljs.core.Vector.fromArray([9, 10])]);
-tempest.levels._STAR_level1_STAR_ = cljs.core.ObjMap.fromObject(["\ufdd0'lines", "\ufdd0'segments", "\ufdd0'length-fn"], {"\ufdd0'lines":tempest.levels._STAR_level1_lines_STAR_, "\ufdd0'segments":tempest.levels._STAR_level1_segments_STAR_, "\ufdd0'length-fn":function(a) {
-  return 4 * a
-}});
 tempest.levels._STAR_level2_lines_STAR_ = cljs.core.Vector.fromArray([cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_, 0]), cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_, 18]), cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_, 36]), cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_, 54]), cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_, 72]), cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_, 
 90]), cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_, 108]), cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_, 126]), cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_, 144]), cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_, 162]), cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_, 180]), cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_, 198]), 
 cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_, 216]), cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_, 234]), cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_, 252]), cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_, 270]), cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_, 288]), cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_, 306]), cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_, 
 324]), cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_, 342])]);
-tempest.levels._STAR_level2_segments_STAR_ = cljs.core.Vector.fromArray([cljs.core.Vector.fromArray([0, 1]), cljs.core.Vector.fromArray([1, 2]), cljs.core.Vector.fromArray([2, 3]), cljs.core.Vector.fromArray([3, 4]), cljs.core.Vector.fromArray([4, 5]), cljs.core.Vector.fromArray([5, 6]), cljs.core.Vector.fromArray([6, 7]), cljs.core.Vector.fromArray([7, 8]), cljs.core.Vector.fromArray([8, 9]), cljs.core.Vector.fromArray([9, 10]), cljs.core.Vector.fromArray([10, 11]), cljs.core.Vector.fromArray([11, 
-12]), cljs.core.Vector.fromArray([12, 13]), cljs.core.Vector.fromArray([13, 14]), cljs.core.Vector.fromArray([14, 15]), cljs.core.Vector.fromArray([15, 16]), cljs.core.Vector.fromArray([16, 17]), cljs.core.Vector.fromArray([17, 18]), cljs.core.Vector.fromArray([18, 19]), cljs.core.Vector.fromArray([19, 0])]);
-tempest.levels._STAR_level2_STAR_ = cljs.core.ObjMap.fromObject(["\ufdd0'lines", "\ufdd0'segments", "\ufdd0'length-fn"], {"\ufdd0'lines":tempest.levels._STAR_level2_lines_STAR_, "\ufdd0'segments":tempest.levels._STAR_level2_segments_STAR_, "\ufdd0'length-fn":function(a) {
-  return 4 * a
-}});
-tempest.levels._STAR_levels_STAR_ = cljs.core.Vector.fromArray([cljs.core.ObjMap.fromObject(["\ufdd0'lines", "\ufdd0'segments", "\ufdd0'length-fn"], {"\ufdd0'lines":tempest.levels._STAR_level1_lines_STAR_, "\ufdd0'segments":tempest.levels._STAR_level1_segments_STAR_, "\ufdd0'length-fn":function(a) {
-  return 4 * a
-}}), cljs.core.ObjMap.fromObject(["\ufdd0'lines", "\ufdd0'segments", "\ufdd0'length-fn"], {"\ufdd0'lines":tempest.levels._STAR_level2_lines_STAR_, "\ufdd0'segments":tempest.levels._STAR_level2_segments_STAR_, "\ufdd0'length-fn":function(a) {
-  return 4 * a
-}})]);
+tempest.levels._STAR_levels_STAR_ = cljs.core.Vector.fromArray([cljs.core.ObjMap.fromObject(["\ufdd0'lines", "\ufdd0'segments", "\ufdd0'length-fn"], {"\ufdd0'lines":tempest.levels._STAR_level1_lines_STAR_, "\ufdd0'segments":tempest.levels.build_segment_list.call(null, cljs.core.count.call(null, tempest.levels._STAR_level1_lines_STAR_) - 1, !1), "\ufdd0'length-fn":tempest.levels._STAR_default_length_fn_STAR_}), cljs.core.ObjMap.fromObject(["\ufdd0'lines", "\ufdd0'segments", "\ufdd0'length-fn"], {"\ufdd0'lines":tempest.levels._STAR_level2_lines_STAR_, 
+"\ufdd0'segments":tempest.levels.build_segment_list.call(null, cljs.core.count.call(null, tempest.levels._STAR_level2_lines_STAR_) - 1, !0), "\ufdd0'length-fn":tempest.levels._STAR_default_length_fn_STAR_})]);
 tempest.polar_to_cartesian_coords = function() {
   return function(a, b) {
     switch(arguments.length) {

diff --git a/src/tempest_cljs/views/welcome.clj b/src/tempest_cljs/views/welcome.clj
line changes: +1/-0
index 9f40542..9b921d3
--- a/src/tempest_cljs/views/welcome.clj
+++ b/src/tempest_cljs/views/welcome.clj
@@ -15,3 +15,4 @@
    [:canvas#canv1 {:width "900" :height "900"}]
    (javascript-tag (str "tempest.canvasDraw(" (pr-str level) ");"))
    ))
+

diff --git a/tempest/levels.cljs b/tempest/levels.cljs
line changes: +24/-43
index a5330e5..37634bd
--- a/tempest/levels.cljs
+++ b/tempest/levels.cljs
@@ -6,6 +6,22 @@
             [goog.math :as math]))
 
 (def *default-line-length* 80)
+(def *default-length-fn* #(* 4 %))
+
+(defn build-unlinked-segment-list [max-x]
+  (vec ((fn [x segments]
+    (if (= x 0)
+      segments
+      (recur (dec x) (cons [(dec x) x] segments)))
+    ) max-x [])))
+
+(defn build-segment-list [max-x linked?]
+  (let [segments (build-unlinked-segment-list max-x)]
+    (if (true? linked?)
+      (conj segments [(last (last segments)) (first (first segments))])
+      segments)
+    )
+  )
 
 ;; short radius, angle in degrees
 ;; straight lines: r = *default-line-length*/abs(cos(270-angle))
@@ -21,23 +37,7 @@
    [90 297]
    [99 306]
    [113 315]])
-(def *level1_segments*
-  [[0 1]
-   [1 2]
-   [2 3]
-   [3 4]
-   [4 5]
-   [5 6]
-   [6 7]
-   [7 8]
-   [8 9]
-   [9 10]
-   ])
-(def *level1* {:lines *level1_lines*
-   :segments *level1_segments*
-   :length-fn #(* % 4)})
 
-;; short radius, angle in degrees
 (def *level2_lines*
   [[*default-line-length* 0]
    [*default-line-length* 18]
@@ -60,34 +60,15 @@
    [*default-line-length* 324]
    [*default-line-length* 342]
    ])
-(def *level2_segments*
-  [[0 1]
-   [1 2]
-   [2 3]
-   [3 4]
-   [4 5]
-   [5 6]
-   [6 7]
-   [7 8]
-   [8 9]
-   [9 10]
-   [10 11]
-   [11 12]
-   [12 13]
-   [13 14]
-   [14 15]
-   [15 16]
-   [16 17]
-   [17 18]
-   [18 19]
-   [19 0]
-   ])
-(def *level2* {:lines *level2_lines*
-   :segments *level2_segments*
-   :length-fn #(* % 4)})
+
 
 (def *levels*
   [
-   {:lines *level1_lines* :segments *level1_segments* :length-fn #(* % 4)}
-   {:lines *level2_lines* :segments *level2_segments* :length-fn #(* % 4)}
+   {:lines *level1_lines*
+    :segments (build-segment-list (- (count *level1_lines*) 1) false)
+    :length-fn *default-length-fn*}
+   
+   {:lines *level2_lines*
+    :segments (build-segment-list (- (count *level2_lines*) 1) true)
+    :length-fn *default-length-fn*}
    ])

diff --git a/tempest/out/levels.js b/tempest/out/levels.js
line changes: +31/-13
index b314789..16ba756
--- a/tempest/out/levels.js
+++ b/tempest/out/levels.js
@@ -6,18 +6,36 @@ goog.require('goog.events');
 goog.require('goog.events.EventType');
 goog.require('goog.math');
 tempest.levels._STAR_default_line_length_STAR_ = 80;
+tempest.levels._STAR_default_length_fn_STAR_ = (function _STAR_default_length_fn_STAR_(p1__2735_SHARP_){
+return (4 * p1__2735_SHARP_);
+});
+tempest.levels.build_unlinked_segment_list = (function build_unlinked_segment_list(max_x){
+return cljs.core.vec.call(null,(function (x,segments){
+while(true){
+if(cljs.core.truth_(cljs.core._EQ_.call(null,x,0)))
+{return segments;
+} else
+{{
+var G__2736 = (x - 1);
+var G__2737 = cljs.core.cons.call(null,cljs.core.Vector.fromArray([(x - 1),x]),segments);
+x = G__2736;
+segments = G__2737;
+continue;
+}
+}
+break;
+}
+}).call(null,max_x,cljs.core.Vector.fromArray([])));
+});
+tempest.levels.build_segment_list = (function build_segment_list(max_x,linked_QMARK_){
+var segments__2738 = tempest.levels.build_unlinked_segment_list.call(null,max_x);
+
+if(cljs.core.truth_(linked_QMARK_ === true))
+{return cljs.core.conj.call(null,segments__2738,cljs.core.Vector.fromArray([cljs.core.last.call(null,cljs.core.last.call(null,segments__2738)),cljs.core.first.call(null,cljs.core.first.call(null,segments__2738))]));
+} else
+{return segments__2738;
+}
+});
 tempest.levels._STAR_level1_lines_STAR_ = cljs.core.Vector.fromArray([cljs.core.Vector.fromArray([113,225]),cljs.core.Vector.fromArray([99,234]),cljs.core.Vector.fromArray([90,243]),cljs.core.Vector.fromArray([84,252]),cljs.core.Vector.fromArray([81,261]),cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_,270]),cljs.core.Vector.fromArray([81,279]),cljs.core.Vector.fromArray([84,288]),cljs.core.Vector.fromArray([90,297]),cljs.core.Vector.fromArray([99,306]),cljs.core.Vector.fromArray([113,315])]);
-tempest.levels._STAR_level1_segments_STAR_ = cljs.core.Vector.fromArray([cljs.core.Vector.fromArray([0,1]),cljs.core.Vector.fromArray([1,2]),cljs.core.Vector.fromArray([2,3]),cljs.core.Vector.fromArray([3,4]),cljs.core.Vector.fromArray([4,5]),cljs.core.Vector.fromArray([5,6]),cljs.core.Vector.fromArray([6,7]),cljs.core.Vector.fromArray([7,8]),cljs.core.Vector.fromArray([8,9]),cljs.core.Vector.fromArray([9,10])]);
-tempest.levels._STAR_level1_STAR_ = cljs.core.ObjMap.fromObject(["\uFDD0'lines","\uFDD0'segments","\uFDD0'length-fn"],{"\uFDD0'lines":tempest.levels._STAR_level1_lines_STAR_,"\uFDD0'segments":tempest.levels._STAR_level1_segments_STAR_,"\uFDD0'length-fn":(function _STAR_level1_STAR_(p1__2735_SHARP_){
-return (p1__2735_SHARP_ * 4);
-})});
 tempest.levels._STAR_level2_lines_STAR_ = cljs.core.Vector.fromArray([cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_,0]),cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_,18]),cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_,36]),cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_,54]),cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_,72]),cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_,90]),cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_,108]),cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_,126]),cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_,144]),cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_,162]),cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_,180]),cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_,198]),cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_,216]),cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_,234]),cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_,252]),cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_,270]),cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_,288]),cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_,306]),cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_,324]),cljs.core.Vector.fromArray([tempest.levels._STAR_default_line_length_STAR_,342])]);
-tempest.levels._STAR_level2_segments_STAR_ = cljs.core.Vector.fromArray([cljs.core.Vector.fromArray([0,1]),cljs.core.Vector.fromArray([1,2]),cljs.core.Vector.fromArray([2,3]),cljs.core.Vector.fromArray([3,4]),cljs.core.Vector.fromArray([4,5]),cljs.core.Vector.fromArray([5,6]),cljs.core.Vector.fromArray([6,7]),cljs.core.Vector.fromArray([7,8]),cljs.core.Vector.fromArray([8,9]),cljs.core.Vector.fromArray([9,10]),cljs.core.Vector.fromArray([10,11]),cljs.core.Vector.fromArray([11,12]),cljs.core.Vector.fromArray([12,13]),cljs.core.Vector.fromArray([13,14]),cljs.core.Vector.fromArray([14,15]),cljs.core.Vector.fromArray([15,16]),cljs.core.Vector.fromArray([16,17]),cljs.core.Vector.fromArray([17,18]),cljs.core.Vector.fromArray([18,19]),cljs.core.Vector.fromArray([19,0])]);
-tempest.levels._STAR_level2_STAR_ = cljs.core.ObjMap.fromObject(["\uFDD0'lines","\uFDD0'segments","\uFDD0'length-fn"],{"\uFDD0'lines":tempest.levels._STAR_level2_lines_STAR_,"\uFDD0'segments":tempest.levels._STAR_level2_segments_STAR_,"\uFDD0'length-fn":(function _STAR_level2_STAR_(p1__2736_SHARP_){
-return (p1__2736_SHARP_ * 4);
-})});
-tempest.levels._STAR_levels_STAR_ = cljs.core.Vector.fromArray([cljs.core.ObjMap.fromObject(["\uFDD0'lines","\uFDD0'segments","\uFDD0'length-fn"],{"\uFDD0'lines":tempest.levels._STAR_level1_lines_STAR_,"\uFDD0'segments":tempest.levels._STAR_level1_segments_STAR_,"\uFDD0'length-fn":(function _STAR_levels_STAR_(p1__2737_SHARP_){
-return (p1__2737_SHARP_ * 4);
-})}),cljs.core.ObjMap.fromObject(["\uFDD0'lines","\uFDD0'segments","\uFDD0'length-fn"],{"\uFDD0'lines":tempest.levels._STAR_level2_lines_STAR_,"\uFDD0'segments":tempest.levels._STAR_level2_segments_STAR_,"\uFDD0'length-fn":(function _STAR_levels_STAR_(p1__2738_SHARP_){
-return (p1__2738_SHARP_ * 4);
-})})]);
+tempest.levels._STAR_levels_STAR_ = cljs.core.Vector.fromArray([cljs.core.ObjMap.fromObject(["\uFDD0'lines","\uFDD0'segments","\uFDD0'length-fn"],{"\uFDD0'lines":tempest.levels._STAR_level1_lines_STAR_,"\uFDD0'segments":tempest.levels.build_segment_list.call(null,(cljs.core.count.call(null,tempest.levels._STAR_level1_lines_STAR_) - 1),false),"\uFDD0'length-fn":tempest.levels._STAR_default_length_fn_STAR_}),cljs.core.ObjMap.fromObject(["\uFDD0'lines","\uFDD0'segments","\uFDD0'length-fn"],{"\uFDD0'lines":tempest.levels._STAR_level2_lines_STAR_,"\uFDD0'segments":tempest.levels.build_segment_list.call(null,(cljs.core.count.call(null,tempest.levels._STAR_level2_lines_STAR_) - 1),true),"\uFDD0'length-fn":tempest.levels._STAR_default_length_fn_STAR_})]);