LoginSignup
25
24

More than 5 years have passed since last update.

プログラムでシダを描画する

Posted at

 概要と元ネタです。

プログラムでシダを描画する - 強火で進め

「プログラムでシダを描画する」をDartで描画する - Qiita

「プログラムでシダを描画する」をGoで描画する - Qiita

(ns fern
  (:require [incanter.core :refer [$=]])
  (:require [quil.core :refer :all]))

(def ^:dynamic *width* 500)
(def ^:dynamic *height* 500)

(defn W1x [x y]
  ($= 0.836 * x + 0.044 * y))

(defn W1y [x y]
  ($= -0.044 * x + 0.836 * y + 0.169))

(defn W2x [x y]
  ($= -0.141 * x + 0.302 * y))

(defn W2y [x y]
  ($= 0.302 * x + 0.141 * y + 0.127))

(defn W3x [x y]
  ($= 0.141 * x - 0.302 * y))

(defn W3y [x y]
  ($= 0.302 * x + 0.141 * y + 0.169))

(defn W4x [x y]
  0)

(defn W4y [x y]
  ($= 0.175337 * y))

(defn draw [n x y]
  (if (pos? n)
    (do
      (draw (dec n) (W1x x y) (W1y x y))
      (when (< (rand) 0.3) (draw (dec n) (W2x x y) (W2y x y)))
      (when (< (rand) 0.3) (draw (dec n) (W3x x y) (W3y x y)))
      (when (< (rand) 0.3) (draw (dec n) (W4x x y) (W4y x y))))
    (let [u ($= *width* - 10)
          v ($= *height* - 10)]
      (point ($= x * u + *width* * 0.5) ($= *height* - y * v)))))

(defn setup []
  (smooth)
  (stroke 32 128 32)
  (stroke-weight 1)
  (background 255)
  (draw 20 0 0))

(defsketch fern
  :title "fern"
  :setup setup
  :size [*width* *height*])

fern

楽しい! ✌(’ω’✌ )三✌(’ω’)✌三( ✌’ω’)✌

quil/quil - GitHub

Incanter

25
24
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
25
24