poly.scm 868 B

123456789101112131415161718192021222324252627
  1. (add-to-load-path (dirname (dirname (current-filename))))
  2. (use-modules (basket))
  3. (define (triangles x y z n)
  4. (if (= n 0)
  5. `((,x ,y ,z))
  6. ((lambda (ts)
  7. (append (triangles (caar ts) (cadar ts) (caddar ts) (1- n))
  8. (triangles (cadr ts) (caddr ts) (cadddr ts) (1- n))))
  9. (list-ref
  10. `(((,x ,y ,(vec-midpoint x z)) . (,y ,z ,(vec-midpoint x z)))
  11. ((,y ,z ,(vec-midpoint x y)) . (,x ,z ,(vec-midpoint x y)))
  12. ((,z ,x ,(vec-midpoint y z)) . (,x ,y ,(vec-midpoint y z))))
  13. (random 3)))))
  14. (define filled-triangles
  15. (append (triangles '(0 . 0) '(0 . 1) '(1 . 0) 8)
  16. (triangles '(1 . 1) '(0 . 1) '(1 . 0) 8)))
  17. (define image
  18. (map (lambda (x)
  19. `(set (color ,(hsv->rgb `(,(caar x) 1 1)))
  20. (fill ,x)))
  21. filled-triangles))
  22. (render-cairo-png image 1024 (cadr (program-arguments)))