我正在尝试构建此自行车站地图动画的制图 quil 可视化衍生物。我正在尝试在 quil 中使用新的默认功能模式,因为它看起来处理了大量处理鼠标事件和更新显示的工作。但是,我遇到了一个问题,即绘图的一部分(背景图)需要很长时间才能完全渲染,即使帧速率非常低。
按照这个可视化的建议,我正在通过下载它来安装 UnfoldingMaps 依赖项,并将其安装到 leiningen localrepo 中,如下所示:
$ lein localrepo install /path/to/library/Unfolding.jar unfolding 0.9.6
$ lein localrepo install /path/to/library/json4processing.jar json4proc 0.9.6
我的 project.clj 文件如下所示:
(defproject transit-map "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:plugins [[lein-localrepo "0.5.3"]]
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.6.0"]
[org.clojure/data.json "0.2.5"]
[quil "2.2.5"]
[unfolding "0.9.6"] ; Installed in local repo
[json4proc "0.9.6"] ; Ditto; shipped with unfolding
[log4j "1.2.15"]])
而且,我的简单 core.clj 看起来像这样:
(ns transit-map.core
(:import (de.fhpotsdam.unfolding UnfoldingMap)
(de.fhpotsdam.unfolding.geo Location)
(de.fhpotsdam.unfolding.providers StamenMapProvider)
(de.fhpotsdam.unfolding.marker SimplePointMarker))
(:require [quil.core :as q]
[quil.middleware :as m]))
(defn setup []
;; Only has close to enough time to plot if the framerate is very
;; low, and even then doesn't quite get the job done.
(q/frame-rate 1)
;; setup function returns initial state.
;; State is one big happy hashmap
{:bg-map (doto (UnfoldingMap.
(quil.applet/current-applet)
(de.fhpotsdam.unfolding.providers.StamenMapProvider$TonerBackground.))
(.setZoomRange 10 12)
(.zoomToLevel 11)
(.panTo (Location. 47.625 -122.332071))
(.draw))})
(defn update-state [state])
(defn draw-state [state]
(.draw (state :bg-map)))
(q/defsketch transit-map
:title "Transit map"
:size [250 500]
;; setup function called only once, during sketch initialization.
:setup setup
;; update-state is called on each iteration before draw-state.
:update update-state
:draw draw-state
;; This sketch uses functional-mode middleware.
:middleware [m/fun-mode])
值得注意的是,只需很少的努力,这就能奏效……有点。即使将帧速率调回 1fps,背景图像也无法完全渲染:
关于如何为这个特定元素提供完全渲染所需的时间有什么建议吗?最终,我希望在此之上以超过 1fps 的速度制作一些动画。我开始怀疑我最好的选择是抓取静态图像并将其扔到背景中。但是,这里还有什么可以推荐的吗?