]> code.delx.au - gnu-emacs-elpa/blob - packages/xpm/flower.el
Merge commit '0cda39255827f283e7578cd469ae42daad9556a2' from js2-mode
[gnu-emacs-elpa] / packages / xpm / flower.el
1 ;;; flower.el --- can `xpm-raster' DTRT? -*- lexical-binding: t -*-
2
3 ;; Copyright (C) 2014 Free Software Foundation, Inc.
4
5 ;; Author: Thien-Thi Nguyen <ttn@gnu.org>
6 ;; Maintainer: Thien-Thi Nguyen <ttn@gnu.org>
7
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
12
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
17
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
20
21 ;;; Commentary:
22
23 ;; This file helps visualize `xpm-raster' failure modes. Maybe one
24 ;; day it will be rendered useless by improvements to `xpm-raster'.
25 ;;
26 ;; NB: There is no `provide' form.
27 ;; NB: Loading munges the global keymap -- YHBW!
28
29 ;;; Code:
30
31 (require 'xpm)
32 (require 'xpm-m2z)
33 (require 'cl-lib)
34
35 (defun flower (&optional again)
36 "Stress `xpm-raster' in various ways."
37 (interactive "P")
38 (let ((buf (get-buffer "flower")))
39 (when buf (kill-buffer buf)))
40 (switch-to-buffer
41 (xpm-generate-buffer "flower" 99 99 2
42 '((" " . "green")
43 (".." . "yellow")
44 ("OO" . "red")
45 ("--" . "black"))))
46 (setq truncate-lines t)
47 (let* ((τ (* 4 2 (atan 1)))
48 (half (/ 99 2.0))
49 (mag-fns (vector (lambda (θ) (ignore θ) 1)
50 (lambda (θ) (sin θ))
51 (lambda (θ) (cos θ))
52 (lambda (θ) (sin (* 0.5 τ θ)))
53 (lambda (θ) (cos (* 0.5 τ θ)))
54 (lambda (θ) (sin (* 0.25 τ θ)))
55 (lambda (θ) (cos (* 0.25 τ θ)))
56 (lambda (θ) (sin (* τ θ)))
57 (lambda (θ) (cos (* τ θ)))))
58 (n-mag-fns (length mag-fns)))
59 (cl-flet
60 ((random-mag-fn () (aref mag-fns (random n-mag-fns)))
61 (form (fn &rest args) (apply fn half half (random 42) args)))
62 (let* ((x-mag-fn (random-mag-fn))
63 (y-mag-fn (random-mag-fn))
64 (form (if again
65 (get 'flower 'form)
66 (delete-dups
67 (if (zerop (random 5))
68 (let ((one (form 'xpm-m2z-circle))
69 (two (form 'xpm-m2z-ellipse (random 42))))
70 (append one two))
71 (cl-loop
72 for θ below τ by 0.003
73 collect
74 (cl-flet
75 ((at (f mfn)
76 (truncate (+ half (* 42 (funcall mfn θ)
77 (funcall f θ))))))
78 (cons (at 'cos x-mag-fn)
79 (at 'sin y-mag-fn)))))))))
80 (put 'flower 'form form)
81 (xpm-raster form "OO" ".."))))
82 (image-mode)
83 ;; strangely, image-mode screws up the markers, so we need to do
84 ;; this again if we want to do subsequent xpm-* access:
85 ;;+ (xpm-grok t)
86 t)
87
88 ;;;---------------------------------------------------------------------------
89 ;;; load-time actions
90
91 (global-set-key [f9] 'flower)
92 (global-set-key
93 [(meta f9)]
94 (lambda () (interactive)
95 (message "xpm-raster-inhibit-continuity-optimization now %s"
96 (setq xpm-raster-inhibit-continuity-optimization
97 (not xpm-raster-inhibit-continuity-optimization)))))
98
99 ;;; flower.el ends here