This is a simple code that just color the window 4 times.
Maybe there is something obvious that I don't see.
My goal is to learn computer graphic from scratch and I want to draw pixel by pixel to have full control. I'm looking for a fast way to do it.
Here is the full code.
The relevant clojure part:
(defmacro for-loop [[sym init check change :as params] & steps]
`(loop [~sym ~init value# nil]
(if ~check
(let [new-value# (do ~@steps)]
(recur ~change new-value#))
value#)))
(time
(for-loop
[k 0 (< k 2) (inc k)]
(for-loop
[c 0 (< c 2) (inc c)]
(for-loop
[i 0 (< i width) (inc i)]
(for-loop
[j 0 (< j height) (inc j)]
(aset ^ints @pixels (+ i (* j width)) (get cs c))))
(.repaint canvas))))
The same code in java:
long t = System.currentTimeMillis();
for (int k = 0 ; k < 2; k++) {
for (int c = 0; c < 2; c++) {
for (int i = 0 ; i < width; i++) {
for (int j = 0; j < height; j++) {
pixels[i + j * width] = cs[c];
}
}
repaint();
}
}
System.out.println(System.currentTimeMillis() - t);