Hi again,
I made a mistake in my last post
The part that changes the position is:
;;adjust position
(setf (getf word :x) (+ x atract-x))
(setf (getf word :y) (+ y atract-y))
;;move display item
[do not works] ---> (set-coords *drawing-canvas-reference* (getf word :display-item) (list (getf word :x) (getf word :y)))
[works] ---> (itemmove *drawing-canvas-reference* (getf word :display-item) atract-x atract-y)
Thanks!
André
Hi,
I'm trying to create an animation with words based on the (ltktest) function in the library (rotate).
For that I'm storing the words in a plist. The code to maintain the words is:
(defvar *initial-word-energy* 100)
(defvar *words* '()) ; list of words in the form (:text :x :y :energy)
(defun make-word (text x y display-item)
(list :text text :x x :y y :display-item display-item :energy *initial-word-energy*))
(defun add-word (word) (push word *words*))
Then I created a button that will add words to the plist and to the canvas:
(enter-text-button (make-instance 'button
:master controls
:text "Enter text"
:command (lambda ()
;;store word in *words*
(let* ((text (text user-text-entry))
(x (random (read-from-string
(cget drawing-canvas-reference
:width))))
(y (random (read-from-string
(cget drawing-canvas-reference
:height))))
;;put text in canvas
(display-item (create-text drawing-canvas-reference
x
y
text))
(word (make-word
text
x
y
display-item)))
;;store new word
(add-word word)
;;clear entry widget
(setf (text user-text-entry) "")
(focus user-text-entry)
(finish-output)))))
The idea is that a word will store the position, the text, other things and the visual representation of the text.
In the animation part (same code as rotate in the library) I move the words, and here is the problem.
If I try the move changing the coordinates of the updated values of x and y of the word the text apearing in the canvas 'jumps' in the first move, afterward it move normally.
The other alternative is to use itemmove, which works. but I would like to just manipulate x and y of the word and transpose it to the created text item in the canvas.
;;move display item
[do not work] ---> (set-coords *drawing-canvas-reference* (getf word :display-item) (list (getf word :x) (getf word :y)))
[works] ----> (itemmove *drawing-canvas-reference* (getf word :display-item) atract-x atract-y)
So, I would like to understand better why there seems to be a difference in the values of x an y for the element stored and the element displayed, although they have been created with the same values.
If possible, I would like to know how can I query the created text element about it's x and y values.
Sorry for the long message.
Any help is appreciated.
Thanks,
André