triangle-contains.scm 933 B

12345678910111213141516171819202122232425262728
  1. (add-to-load-path (dirname (dirname (current-filename))))
  2. (use-modules (basket)
  3. (srfi srfi-1))
  4. (define (random-triangle center radius)
  5. (map (lambda (x)
  6. (vec-add center
  7. (vec-rotate (make-vec radius 0)
  8. (+ (* x (/ tau 3))
  9. (* (random:uniform) (/ tau 3))))))
  10. (iota 3)))
  11. (define (draw-around center radius)
  12. (let ((triangle (random-triangle center radius))
  13. (rect (list (vec-sub center (make-vec radius radius))
  14. (vec-add center (make-vec radius radius)))))
  15. (list
  16. (poly->path triangle)
  17. (filter (curry triangle-contains triangle)
  18. (concatenate (rect->vecss rect 32))))))
  19. (define image
  20. `(stroke
  21. ,(map (lambda (v) (draw-around v 1/8))
  22. (concatenate (rect->vecss '((1/8 . 1/8) (7/8 . 7/8)) 4)))))
  23. (render-cairo-png image 1024 (cadr (program-arguments)))