0

I made a program for drawing graphs function but I don't know how to replace the image when drawing again

(defun eilmc-infix-plot () "" (interactive) (switch-to-buffer "*Function Plotter*") (kill-all-local-variables) (make-local-variable 'expr-widget) (make-local-variable 'error-widget) (let ((inhibit-read-only t)) (erase-buffer)) (remove-overlays) (setq expr-widget (widget-create 'editable-field :format "Function (infix notation):\n%v" "x^2")) (widget-insert "\n") (widget-insert "Error: ") (setq error-widget (widget-create 'item :value "")) (widget-insert "\n") (widget-create 'push-button :notify (lambda (&rest ignore) (condition-case err (let* ((expr (widget-value expr-widget)) (tokens (elimc-tokenize-math-expression expr)) (rpn (elimc-shunting-yard tokens)) (image (elimc-fill-image (elimc-create-image 400 400) 0))) ;; grid (dotimes (x 400) (dotimes (y 400) (when (or (= (mod x 50) 0) (= (mod y 50) 0)) (elimc-setpixel image x y 1)))) ;; plot (dotimes (x 400) (let* ((x-val (- (/ (* x 8.0) 400) 4)) ;; X (y-val (elimc-rpn-calc rpn x-val)) (y (round (- 200 (* 50 y-val))))) ;; Y (when (and (>= y 0) (< y 400)) (elimc-setpixel image x y 1)))) ;; display img (let ((pbm (elimc-image-to-pbm image))) (with-current-buffer "*Function Plotter*" (let ((inhibit-read-only t)) (goto-char (point-max)) (widget-image-insert result-widget "The console does not support images" (create-image pbm 'pbm "")))))) (error (widget-value-set error-widget (error-message-string err))))) "Plot") (widget-insert "\n") (setq result-widget (widget-create 'item :value "")) (use-local-map widget-keymap) (widget-setup)) 
5
  • The question is incomplete without the implementation of the elimc-* functions that you use or an indication where the library can be found. Please provide that information. Commented Feb 16 at 19:44
  • this is a personal code, it is not needed, from the name of the function you can understand that it simply creates a string with image data, and then becomes an image. Here the question is how can I replace images Commented Feb 17 at 13:01
  • In that case, change the code that you submitted so that it does not use it. But provide something that we can use to reproduce your problem. Do not expect us to spend our time to write a test program for your problem. Commented Feb 17 at 17:51
  • In fact, it's probably better to submit a much simplified version of your function that dispenses with everything that is not essential to reproduce your problem. Commented Feb 17 at 21:17
  • (following on NickD) also called a MWE (minimal working example) Commented Feb 20 at 7:49

1 Answer 1

0

Your use of widget-image-insert is odd. Usually, that call should be inside a :value-create function.

Try something like:

  • Define a custom :value-create function for your result-widget.
  • Store the image that you want to insert in some variable, or even as a property of the result-widget.
  • Inside your :value-create function, call widget-image-insert, passing that variable/property value.
  • In your :notify function, update that variable/property and call widget-value-set for the result-widget.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.