Line Density Function

DRAFT art

Table of Contents

Continuing the Hatching Test experiment.

Lines

(defun line2 (from to)
  (add-shape (make-line from to)))

Function Plot

(with-scene
    (let ((step 0.1))
     (loop
       for x from 0 to (- (* 2 PI) step) by step
       do (line2 (vec2 x (cos x)) (vec2 (+ x step) (cos (+ x step))))))
  (plot-2d "images/line_density/sine.png" :format "30,10"))
sine.png

Integration

  1. Step along function in small increments, approximate integra
  2. Once limit is reached, draw a line

Line density is defined by a function line_density_function_da5d8714fa6a3a0f6769c17fc675ec3ee8803f80.svg .

(defun density (x) (/ (+ (cos x) 1) 2))

Approximation of line_density_function_9af8d58a8d217fb6c02e985071e4dbc46400828b.svg

(defun area (f a b)
  (/ (* (+ (funcall f a) (funcall f b)) (- b a)) 2))
(with-scene
    (let ((step 0.01) (limit 0.10))
     (loop
       for x from 0 to (- (* 2 PI) step) by step
       for area = 0.0 then (+ area (area #'density x (+ x step)))
       do (progn
        (line2 (vec2 x (- 1.0 (density x))) (vec2 (+ x step) (- 1.0 (density (+ x step)))))
        (when (> area limit)
          (line2 (vec2 (+ x step) (- 1.0 (density (+ x step)))) (vec2 (+ x step) 1.0))
          (setq area 0.0)))))
  (plot-2d "images/line_density/sine_density.png" :format "30,10"))
sine_density.png

Repetition

(with-scene
    (let ((step 0.002) (limit 0.15) (size 16))
     (loop for y from 0 below size do
      (let ((density (lambda (x) (/ (+ (cos (* 1 (norm (sub (vec2 x y) (vec2 0 0))))) 1) 2))))
     (loop
       for x from 0 to size by step
       for area = 0.0 then (+ area (area density x (+ x step)))
       do
        (when (> area limit)
          (line2 (vec2 (+ x step) y) (vec2 (+ x step) (1+ y)))
          (setq area 0.0)))))
  (line2 (vec2 0 0) (vec2 size 0))
  (line2 (vec2 size 0) (vec2 size size))
  (line2 (vec2 size size) (vec2 0 size))
  (line2 (vec2 0 size) (vec2 0 0))
  (plot-2d "images/line_density/line_density.png" :format "30,30" :palette "/home/leon/src/generative/bw.json")))
line_density.png

Both Directions

(with-scene
    (let ((step 0.002) (limit 0.15) (size 16))
      (loop for y from 0 below size do
        (let ((density (lambda (x) (/ (+ (cos (* 1 (norm (sub (vec2 x y) (vec2 0 0))))) 1) 2))))
          (loop
            for x from 0 to size by step
            for area = 0.0 then (+ area (area density x (+ x step)))
            do
               (when (> area limit)
                 (line2 (vec2 (+ x step) y) (vec2 (+ x step) (1+ y)))
                 (setq area 0.0)))))
      (loop for x from 0 below size do
        (let ((density (lambda (y) (/ (+ (cos (* 1 (norm (sub (vec2 x y) (vec2 0 0))))) 1) 2))))
          (loop
            for y from 0 to size by step
            for area = 0.0 then (+ area (area density y (+ y step)))
            do
               (when (> area limit)
                 (line2 (vec2 x (+ y step)) (vec2 (1+ x) (+ y step)))
                 (setq area 0.0)))))
      (line2 (vec2 0 0) (vec2 size 0))
      (line2 (vec2 size 0) (vec2 size size))
      (line2 (vec2 size size) (vec2 0 size))
      (line2 (vec2 0 size) (vec2 0 0))
      (plot-2d "images/line_density/line_density2.png" :format "30,30" :palette "/home/leon/src/generative/bw.json")))
line_density2.png

If you have an idea how this page could be improved or a comment send me a mail.