-1
我正在嘗試使用Quil編寫我的第一個簡單圖形應用程序。現在,我只是試圖繪製一個在屏幕上對角移動的點。Quil聲稱我的繪圖函數有0個參數
(ns quil-test.quil-first
(:require [quil.core :as q])
(:gen-class))
(defn setup-state []
(q/frame-rate 60)
{:x 0})
(defn update-state [s]
(assoc s :x (q/frame-count)))
(defn draw-state [state]
(let [x (:x state)]
(q/stroke-weight 100)
(q/point x x)))
(q/defsketch quil-first
:size [500 500]
:setup setup-state
:update update-state
:draw draw-state)
問題是,運行此不顯示一個點,下面的錯誤重複打印到控制檯:
Exception in :draw function: #error {
:cause Wrong number of args (0) passed to: quil-first/draw-state
:via
[{:type clojure.lang.ArityException
:message Wrong number of args (0) passed to: quil-first/draw-state
:at [clojure.lang.AFn throwArity AFn.java 429]}]
:trace
[[clojure.lang.AFn throwArity AFn.java 429]
[clojure.lang.AFn invoke AFn.java 28]
[clojure.lang.Var invoke Var.java 375]
[quil.middlewares.safe_fns$wrap_fn$fn__114 invoke safe_fns.clj 9]
[quil.middlewares.bind_output$bind_output$iter__148__152$fn__153$fn__164 invoke bind_output.clj 21]
[quil.applet$_draw invoke applet.clj 220]
[quil.Applet draw nil -1]
[processing.core.PApplet handleDraw PApplet.java 2402]
[quil.Applet handleDraw nil -1]
[processing.awt.PSurfaceAWT$12 callDraw PSurfaceAWT.java 1527]
[processing.core.PSurfaceNone$AnimationThread run PSurfaceNone.java 316]]}
stacktrace: clojure.lang.ArityException: Wrong number of args (0) passed to: quil-first/draw-state
at clojure.lang.AFn.throwArity (AFn.java:429)
clojure.lang.AFn.invoke (AFn.java:28)
clojure.lang.Var.invoke (Var.java:375)
quil.middlewares.safe_fns$wrap_fn$fn__114.invoke (safe_fns.clj:9)
quil.middlewares.bind_output$bind_output$iter__148__152$fn__153$fn__164.invoke (bind_output.clj:21)
quil.applet$_draw.invoke (applet.clj:220)
quil.Applet.draw (:-1)
processing.core.PApplet.handleDraw (PApplet.java:2402)
quil.Applet.handleDraw (:-1)
processing.awt.PSurfaceAWT$12.callDraw (PSurfaceAWT.java:1527)
processing.core.PSurfaceNone$AnimationThread.run (PSurfaceNone.java:316)
它說我draw-state
函數接受0參數,當它應該取1. draw-state
顯然需要1個參數。
我不明白爲什麼draw-state
以某種方式被「轉換」爲0值功能。
你向後解釋的錯誤信息;這意味着當它期待1個參數時,通過零參數。 –
雅。我的困惑源於這樣的事實:我所看到的例子有一個繪製函數,它帶有一個參數。我解決了它,所以我會發佈一個答案。 – Carcigenicate
Downvoter,請解釋。 – Carcigenicate