Mercurial > cortex
diff org/test-creature.org @ 99:b7a3ba5e879b
made BufferedImage visulation more general
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 14 Jan 2012 01:07:18 -0700 |
parents | 5b23961433e3 |
children | 940074adc1d5 |
line wrap: on
line diff
1.1 --- a/org/test-creature.org Wed Jan 11 21:30:26 2012 -0700 1.2 +++ b/org/test-creature.org Sat Jan 14 01:07:18 2012 -0700 1.3 @@ -6,6 +6,15 @@ 1.4 #+SETUPFILE: ../../aurellem/org/setup.org 1.5 #+INCLUDE: ../../aurellem/org/level-0.org 1.6 1.7 + 1.8 +* objectives 1.9 + - [ ] get an overall bitmap-like image for touch 1.10 + - [ ] write code to visuliaze this bitmap 1.11 + - [ ] directly change the UV-pixels to show touch sensor activation 1.12 + - [ ] write an explination for why b&w bitmaps for senses is appropiate 1.13 + - [ ] clean up touch code and write visulazation test 1.14 + - [ ] do the same for eyes 1.15 + 1.16 * Intro 1.17 So far, I've made the following senses -- 1.18 - Vision 1.19 @@ -49,8 +58,63 @@ 1.20 (use '(cortex world util body hearing touch vision)) 1.21 1.22 (rlm.rlm-commands/help) 1.23 +(import java.awt.image.BufferedImage) 1.24 +(import javax.swing.JPanel) 1.25 +(import javax.swing.SwingUtilities) 1.26 +(import java.awt.Dimension) 1.27 +(import javax.swing.JFrame) 1.28 +(import java.awt.Dimension) 1.29 +(declare joint-create) 1.30 1.31 -(declare joint-create) 1.32 +(defn view-image 1.33 + "Initailizes a JPanel on which you may draw a BufferedImage. 1.34 + Returns a function that accepts a BufferedImage and draws it to the 1.35 + JPanel." 1.36 + [] 1.37 + (let [image 1.38 + (atom 1.39 + (BufferedImage. 1 1 BufferedImage/TYPE_4BYTE_ABGR)) 1.40 + panel 1.41 + (proxy [JPanel] [] 1.42 + (paint 1.43 + [graphics] 1.44 + (proxy-super paintComponent graphics) 1.45 + (.drawImage graphics @image 0 0 nil))) 1.46 + frame (JFrame. "Display Image")] 1.47 + (SwingUtilities/invokeLater 1.48 + (fn [] 1.49 + (doto frame 1.50 + (-> (.getContentPane) (.add panel)) 1.51 + (.pack) 1.52 + (.setLocationRelativeTo nil) 1.53 + (.setResizable true) 1.54 + (.setVisible true)))) 1.55 + (fn [#^BufferedImage i] 1.56 + (reset! image i) 1.57 + (.setSize frame (+ 8 (.getWidth i)) (+ 28 (.getHeight i))) 1.58 + (.repaint panel 0 0 (.getWidth i) (.getHeight i))))) 1.59 + 1.60 + 1.61 +(defn visualize [points] 1.62 + 1.63 + 1.64 + 1.65 +(defn collapse 1.66 + "Take a set of pairs of integers and collapse them into a 1.67 + contigous bitmap." 1.68 + [points] 1.69 + (let [center [0 0]] 1.70 + 1.71 + ) 1.72 + 1.73 + 1.74 + 1.75 + 1.76 + 1.77 + 1.78 + 1.79 + 1.80 + 1.81 1.82 (defn load-bullet [] 1.83 (let [sim (world (Node.) {} no-op no-op)] 1.84 @@ -314,7 +378,6 @@ 1.85 ;; (println-repl (float (/ @timer 60)))))) 1.86 ))) 1.87 1.88 - 1.89 (defn colorful [] 1.90 (.getChild (worm-model) "worm-21")) 1.91 1.92 @@ -364,8 +427,6 @@ 1.93 (ImagePlus. 1.94 "UV-map" 1.95 (ImageToAwt/convert im false false 0)))))) 1.96 - 1.97 - 1.98 1.99 (import ij.process.ImageProcessor) 1.100 (import java.awt.image.BufferedImage) 1.101 @@ -602,7 +663,8 @@ 1.102 (set 1.103 (filter #(not (= geo %)) 1.104 (map #(.getGeometry %) results)))] 1.105 - (count touch-objects))))))))) 1.106 + (if (> (count touch-objects) 0) 1.107 + 1 0))))))))) 1.108 1.109 (defn touch [#^Node pieces] 1.110 (let [touch-components 1.111 @@ -612,11 +674,6 @@ 1.112 (fn [node] 1.113 (reduce into [] (map #(% node) touch-components))))) 1.114 1.115 - 1.116 - 1.117 - 1.118 - 1.119 - 1.120 (defn all-names [] 1.121 (concat 1.122 (re-split #"\n" (slurp (file-str 1.123 @@ -985,20 +1042,6 @@ 1.124 ) 1.125 )) 1.126 1.127 - 1.128 - 1.129 -#+end_src 1.130 - 1.131 - 1.132 -* COMMENT generate source 1.133 -#+begin_src clojure :tangle ../src/cortex/silly.clj 1.134 -<<body-1>> 1.135 -#+end_src 1.136 - 1.137 - 1.138 - 1.139 - 1.140 - 1.141 (defn transform-trianglesdsd 1.142 "Transform that converts each vertex in the first triangle 1.143 into the corresponding vertex in the second triangle." 1.144 @@ -1061,25 +1104,19 @@ 1.145 (dorun (map println in***)) 1.146 (println) 1.147 1.148 - ))) 1.149 - 1.150 - 1.151 - 1.152 - 1.153 - 1.154 - 1.155 - 1.156 - 1.157 - 1.158 + )))) 1.159 1.160 1.161 - 1.162 - 1.163 - 1.164 - 1.165 - 1.166 - 1.167 - 1.168 - ) 1.169 + 1.170 + 1.171 +#+end_src 1.172 + 1.173 + 1.174 +* COMMENT generate source 1.175 +#+begin_src clojure :tangle ../src/cortex/silly.clj 1.176 +<<body-1>> 1.177 +#+end_src 1.178 + 1.179 + 1.180 1.181