all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Examples of use of svg.el?
@ 2022-04-01  7:05 Eduardo Ochs
  2022-04-01 11:11 ` Tomas Hlavaty
  2022-04-01 21:47 ` Michael Heerdegen
  0 siblings, 2 replies; 8+ messages in thread
From: Eduardo Ochs @ 2022-04-01  7:05 UTC (permalink / raw)
  To: help-gnu-emacs

Hi list,

I am trying to learn how to use svg.el, and I plan to use it mainly to
plot mathematical functions. Can you recommend me links to blog
posts/packages/demos/snippets/whatevers that show how to use svg.el?

My current notes are here:

  http://angg.twu.net/2022eev-svg.html

Thanks in advance! =)
  Eduardo Ochs
  http://angg.twu.net/#eev



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Examples of use of svg.el?
  2022-04-01  7:05 Examples of use of svg.el? Eduardo Ochs
@ 2022-04-01 11:11 ` Tomas Hlavaty
  2022-04-01 21:47 ` Michael Heerdegen
  1 sibling, 0 replies; 8+ messages in thread
From: Tomas Hlavaty @ 2022-04-01 11:11 UTC (permalink / raw)
  To: Eduardo Ochs; +Cc: help-gnu-emacs

On Fri 01 Apr 2022 at 04:05, Eduardo Ochs <eduardoochs@gmail.com> wrote:
> I am trying to learn how to use svg.el, and I plan to use it mainly to
> plot mathematical functions. Can you recommend me links to blog
> posts/packages/demos/snippets/whatevers that show how to use svg.el?
>
> My current notes are here:
>
>   http://angg.twu.net/2022eev-svg.html

There is svg.el but I do not like it because:
- it requires gui emacs
- it is not pure, it changes the cons-tree using side-effects

I prefer doing it using pure functions, something like described in
id:87ft7zs48u.fsf@logand.com

(require 'xml)
(with-temp-buffer
  (xml-print
   '((svg
      ((xmlns . "http://www.w3.org/2000/svg")
       (viewBox . "0 0 100 100"))
      (circle
       ((cx . "50") (cy . "50") (r . "20"))))))
  (write-file "/tmp/a.svg"))

which you can refactor anyway you like, e.g.

(defun svg (x y w h &rest body)
  `((svg
     ((xmlns . "http://www.w3.org/2000/svg")
      (viewBox . ,(format "%s %s %s %s" x y w h)))
     ,@body)))

(defun svg-circle (cx cy r)
  `(circle
    ((cx . ,(format "%s" cx)
     (cy . ,(format "%s" cy))
     (r . ,(format "%s" r))))))

(with-temp-buffer
  (xml-print
   (svg 0 0 100 100 (svg-circle 50 50 20)))
  (write-file "/tmp/a.svg"))



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Examples of use of svg.el?
  2022-04-01  7:05 Examples of use of svg.el? Eduardo Ochs
  2022-04-01 11:11 ` Tomas Hlavaty
@ 2022-04-01 21:47 ` Michael Heerdegen
  2022-04-02  0:12   ` Eduardo Ochs
  1 sibling, 1 reply; 8+ messages in thread
From: Michael Heerdegen @ 2022-04-01 21:47 UTC (permalink / raw)
  To: help-gnu-emacs

Eduardo Ochs <eduardoochs@gmail.com> writes:

> Hi list,
>
> I am trying to learn how to use svg.el, and I plan to use it mainly to
> plot mathematical functions.

Why don't you want to use Calc?

Michael.




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Examples of use of svg.el?
  2022-04-01 21:47 ` Michael Heerdegen
@ 2022-04-02  0:12   ` Eduardo Ochs
  2022-04-02  1:21     ` Michael Heerdegen
  0 siblings, 1 reply; 8+ messages in thread
From: Eduardo Ochs @ 2022-04-02  0:12 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: help-gnu-emacs

On Fri, 1 Apr 2022 at 18:47, Michael Heerdegen <michael_heerdegen@web.de> wrote:
>
> Eduardo Ochs <eduardoochs@gmail.com> writes:
>
> > Hi list,
> >
> > I am trying to learn how to use svg.el, and I plan to use it mainly to
> > plot mathematical functions.
>
> Why don't you want to use Calc?
>
> Michael.

Hi Michael,

I don't have a short answer for that, but I'll try to make my longish
answer short enough...

There are some programs that most people find very easy and a few
people find very hard. My favorite example of that is Org, see:

    http://angg.twu.net/2021-org-for-non-users.html

A quote:

  "At some point in 2021 I finally understood why I have always found
  Org Mode so hard to use. To make a long story short, I am a very bad
  _user_: when I try to use something and I can't make a clear mental
  model of what's going on my first reaction is to try to look at the
  data structures and at the source code - and the code that
  implements code blocks in Org is hard to understand."

I was never able to learn Calc properly, and I _guess_ that the main
reason for that is because I've never found a good way to record my
interactions with Calc and "play them back" later.

Take a look at the first three screenshots in:

  http://angg.twu.net/2022eev-svg.html

The third screenshot shows a quadratic function. I know how to make
Maxima draw something very similar to that; Maxima generates a script
for gnuplot, and asks gnuplot to render it. The script can be saved to
a file, and I learned a lot about gnuplot by examining these scripts.

I only learned that Calc can do graphics via gnuplot a few minutes
ago:

  (info "(calc)Graphics")

The quadratic function in my third screenshot is defined in this way:

  x0 = 3
  y0 = 2
  z = z(x,y) = (x-x0)^2 - (y-y0)^2 + 2

How would you make Calc plot it for x in [x0-1,x0+1] and y in
[y0-1,y0+1]? Also: how do we access the script that Calc sends to
gnuplot?

Btw, my way to script my interactions with Maxima is demo-ed here:

  http://angg.twu.net/eev-find-angg.html

The third thumbnail - the one that shows a 3D plot - points to this,

  http://www.youtube.com/watch?v=FoAzpGzFCSE&t=15m14s

that nowadays is one of my favorite short demos of eev in action - as
in: "hey, if you've never seen how to use eev to control REPLs then
follow this link and watch 30 seconds of the video... note that the
`&t=15m14s' make Youtube start playing it from 15:14".

I would _really_ love to make something similar for Calc. Any help
would be greatly appreciated!

  Cheers & thanks in advance,
  Eduardo Ochs
    http://angg.twu.net/#eev



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Examples of use of svg.el?
  2022-04-02  0:12   ` Eduardo Ochs
@ 2022-04-02  1:21     ` Michael Heerdegen
  2022-04-02  3:56       ` Michael Heerdegen
  2022-04-02 10:46       ` Eduardo Ochs
  0 siblings, 2 replies; 8+ messages in thread
From: Michael Heerdegen @ 2022-04-02  1:21 UTC (permalink / raw)
  To: help-gnu-emacs

Eduardo Ochs <eduardoochs@gmail.com> writes:

>   x0 = 3
>   y0 = 2
>   z = z(x,y) = (x-x0)^2 - (y-y0)^2 + 2
>
> How would you make Calc plot it for x in [x0-1,x0+1] and y in
> [y0-1,y0+1]? Also: how do we access the script that Calc sends to
> gnuplot?
> [...]
> I would _really_ love to make something similar for Calc. Any help
> would be greatly appreciated!

Calc is a cool interactive Calculator, but IMHO it's not so super useful
as programming language or for writing scripts, and it seems that's what
you want to do.

With my current Calc skills I would solve the above task like

' [x0-1 .. x0+1] RET      ; interval
' [y0-1 .. y0+1] RET      ; ditto
' (x-x0)^2 - (y-y0)^2 + 2 ; you could alternatively define a named function
3 s t x0                  ; set x0 to 3
2 s t y0                  ; ditto y0 to 2
M-3 =                     ; updates topmost 3 stack values with vars substituted
g F                       ; draw it

There are probably better ways to handle the constants x0 and y0.  You
can undo the variable substitution with `undo' (surprise!).

g v and g V show communication stuff with gnuplot.  g N to use more
interpolation points (the default is, dunno, 4 or so, you probably want
to change the default in your config: `calc-graph-default-resolution'
and `calc-graph-default-resolution-3d').

That's all I know.  If you are already happy with Maxima, Calc will
probably not be a complete substitute.

Michael.




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Examples of use of svg.el?
  2022-04-02  1:21     ` Michael Heerdegen
@ 2022-04-02  3:56       ` Michael Heerdegen
  2022-04-02 10:46       ` Eduardo Ochs
  1 sibling, 0 replies; 8+ messages in thread
From: Michael Heerdegen @ 2022-04-02  3:56 UTC (permalink / raw)
  To: help-gnu-emacs

Michael Heerdegen <michael_heerdegen@web.de> writes:

> Calc is a cool interactive Calculator, but IMHO it's not so super useful
> as programming language or for writing scripts, and it seems that's what
> you want to do.

However there is an embedded mode which allows to work with formulas in
separate buffers (files).

Michael.




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Examples of use of svg.el?
  2022-04-02  1:21     ` Michael Heerdegen
  2022-04-02  3:56       ` Michael Heerdegen
@ 2022-04-02 10:46       ` Eduardo Ochs
  2022-04-03  4:58         ` Michael Heerdegen
  1 sibling, 1 reply; 8+ messages in thread
From: Eduardo Ochs @ 2022-04-02 10:46 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: help-gnu-emacs

On Fri, 1 Apr 2022 at 22:21, Michael Heerdegen <michael_heerdegen@web.de> wrote:
>
> Calc is a cool interactive Calculator, but IMHO it's not so super useful
> as programming language or for writing scripts, and it seems that's what
> you want to do.
>
> With my current Calc skills I would solve the above task like
>
> ' [x0-1 .. x0+1] RET      ; interval
> ' [y0-1 .. y0+1] RET      ; ditto
> ' (x-x0)^2 - (y-y0)^2 + 2 ; you could alternatively define a named function
> 3 s t x0                  ; set x0 to 3
> 2 s t y0                  ; ditto y0 to 2
> M-3 =                     ; updates topmost 3 stack values with vars substituted
> g F                       ; draw it


Hi Michael,

thanks a lot!!! I found a way to record an interaction with Calc, but
the way to set up the windows is still very fragile. Here is a video,

  http://angg.twu.net/eev-videos/2022eev-calc-0.mp4

and here is the code:



(defun eek-at-window (window keyseq)
  (save-selected-window
    (select-window (get-buffer-window window))
    (eek keyseq)))

(defun eec (keyseq) (eek-at-window "*Calculator*" keyseq))

(defun ee-show-calc-windows ()
  (interactive)
  (find-wset "13o_3o_o"
    '(find-ebuffer "*Calculator*")
    '(find-ebuffer "*Calc Trail*")))

• (calc) (eek "C-x 3 M-1 M-j")
• (ee-show-calc-windows)
• (eec "' [x0-1 .. x0+1] RET             ;; interval")
• (eec "' [y0-1 .. y0+1] RET             ;; ditto")
• (eec "' (x-x0)^2 - (y-y0)^2 + 2 RET    ;; alt: define a named function")
• (eec "3 s t x0 RET                     ;; set x0 to 3")
• (eec "2 s t y0 RET                     ;; set y0 to 2")
• (eec "M-3 =          ;; updates topmost 3 stack values with vars substituted")
• (eec "g F            ;; draw it")



...it needs to be run from ~/TODO, and it is very fragile. The line

  (calc) (eek "C-x 3 M-1 M-j")

will start Calc, and Calc will (usually?) make the frame display the
"*Calculator*" window at the left and the "*Calc Trail*" window at the
right. Then in the `eek' sexp the `C-x 3' splits the "*Calculator*"
window into a left half and a right half, and the `M-1 M-j' makes the
left half visit the file "~/TODO". The

  (ee-show-calc-windows)

resizes the windows to make the "~/TODO" window take 50% of the width
of the frame and the window "*Calculator*" and "*Calc Trail*" take 25%
each.

  Cheers,
    Eduardo Ochs
    http://angg.twu.net/#eev



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Examples of use of svg.el?
  2022-04-02 10:46       ` Eduardo Ochs
@ 2022-04-03  4:58         ` Michael Heerdegen
  0 siblings, 0 replies; 8+ messages in thread
From: Michael Heerdegen @ 2022-04-03  4:58 UTC (permalink / raw)
  To: help-gnu-emacs

Eduardo Ochs <eduardoochs@gmail.com> writes:

> thanks a lot!!! I found a way to record an interaction with Calc, but
> the way to set up the windows is still very fragile. Here is a video,
>
>   http://angg.twu.net/eev-videos/2022eev-calc-0.mp4

Hey - cool.

I would (setq calc-display-trail nil) to get rid of the trail window,
at least for that purpose.  You can still get it back (actually, toggle
it displaying) with t d from the Calculator.

Michael.




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-04-03  4:58 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-01  7:05 Examples of use of svg.el? Eduardo Ochs
2022-04-01 11:11 ` Tomas Hlavaty
2022-04-01 21:47 ` Michael Heerdegen
2022-04-02  0:12   ` Eduardo Ochs
2022-04-02  1:21     ` Michael Heerdegen
2022-04-02  3:56       ` Michael Heerdegen
2022-04-02 10:46       ` Eduardo Ochs
2022-04-03  4:58         ` Michael Heerdegen

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.