• A drawing program on the REPL with GUI feedback

    From Laroux@21:1/5 to All on Wed Jul 17 01:36:01 2024
    I'm designing a drawing program whose functionality will be fully
    programmable on the REPL. There will be a canvas display. You can do
    something like:

    (draw (color (line '(0 0) '(10 10)) 1))

    And a straight line from pixel coordinates 0, 0 to 10, 10 in color index 1
    will be drawn. This is relatively easy. The line function returns a list
    of coordinates. The color function associates a color index to each
    coordinate, and the draw function colors each coordinate with the given
    color (assuming a color palette previously defined).

    But, when drawing it is most often the case that the end user wishes to
    use the mouse to point at areas of the canvas upon which to draw. I would
    like the functions to be completely ignorant of whether the values were
    typed in directly at the REPL as my example above, or obtained from the
    user via the mouse.

    Even the color index could instead be a request for the user to select a
    color from the color palette.

    For example:

    (draw (color (line '(ask) '(ask)) 1))

    This would then prompt (both at the REPL and on the canvas) for the user
    to enter the starting and ending coordinates for the line. The user could
    just type the values into the prompt at the REPL, or move the mouse onto
    the canvas click once, move and click a second time.

    The GUI part, and acquisition of the mouse coordinates is not where I'm
    stuck. I'm sure I could use something like SDL or Mcclim for this task.

    But, what I am unsure about is how to make a generalized function which
    can read a series of values from the user, and then pass them as
    parameters to the given functions.

    Let's just take the line function, for example. I guess it needs to be a
    macro, so that it does not evaluate its terms. Okay, so macro "line" will
    need to eventually call real function "line" which does the job of
    calculating the pixel coordinates from the beginning to the end.

    What I would like is for some ability to inspect the real function called
    line to determine what parameters it requests. Then compare that with the parameters passed into the macro.

    In this case we can say "Ah, function line takes one or more coordinates.
    If just one coordinate, it returns that one. If two, then a list of
    coordinates between them. If three then a line from coordinate one to two,
    and then from two to three, etc." Further, we passed in two "ask"
    requests, so that would fill in exactly two coordinates for the line
    function. Let's request them from the user.

    Here are some other examples:

    (line 'ask)
    This should keep asking for coordinates until some other user input (maybe
    the escape key) indicates the end of the list.

    (line '(0 ask) '(10 ask))
    This will ask for the y value of the coordinate for both the beginning and
    the end

    (line '(ask start-coord) '((+ 10 (car start-coord)) (+ 10 (cadr start-
    coord)))
    This will ask for the starting coordinate, and assign it to the variable "start-coord." The ending coordinate will be ten pixels right and ten
    pixels down (using screen coordinates) from the starting coordinate.

    I may have the syntax incorrect. Maybe I need to always have "ask" in parenthesis, as like a function.

    But, the main part I wish to figure out is how to take an arbitrary set of parameters that would normally be passed into a function, compare that to
    the function's signature, and then request the user to "fill in the
    blanks."

    I think part of the solution includes having the function (I mean "line"
    in this instance) declare the type of its values. I think also there is a
    way to include documentation of each input parameter. That documentation
    could be used as the prompt at the REPL.

    Thanks for any ideas you may have.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Madhu@21:1/5 to All on Wed Jul 17 10:03:41 2024
    * Laroux <v77761$1fmm0$[email protected]> :
    Wrote on Wed, 17 Jul 2024 01:36:01 -0000 (UTC):

    Even the color index could instead be a request for the user to select a color from the color palette.

    For example:

    (draw (color (line '(ask) '(ask)) 1))

    This would then prompt (both at the REPL and on the canvas) for the user
    to enter the starting and ending coordinates for the line. The user could just type the values into the prompt at the REPL, or move the mouse onto
    the canvas click once, move and click a second time.

    The GUI part, and acquisition of the mouse coordinates is not where I'm stuck. I'm sure I could use something like SDL or Mcclim for this task.
    But, what I am unsure about is how to make a generalized function which
    can read a series of values from the user, and then pass them as
    parameters to the given functions.


    as user Interaction is intimately tied to the platform and GUI and
    threading model of the GUI, you are constrained by what you have chosen
    and your implementation of abstractions over it automatically become
    wedded to it, to what your framework provides.

    Generalized prompting is provided through mechanisms like Emacs
    INTERACTIVE clim Presentation Types, these are from the 1980s and I am
    not dont remember newer techniques but these work in their contexts and
    are forever being reimplemented in other contexts (platform gui etc) and
    after your initial stab at identifying the problems, you perhaps could
    study how these are addressed by INTERACTIVE and PRESENTATION-TYPES, so
    you can use those principles in your solution

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Madhu on Wed Jul 17 06:20:53 2024
    On Wed, 17 Jul 2024 10:03:41 +0530, Madhu wrote:

    Generalized prompting is provided through mechanisms like Emacs
    INTERACTIVE clim Presentation Types, these are from the 1980s and I am
    not dont remember newer techniques ...

    Another one that comes to mind is the system of declarative “properties”
    in the Blender 3D app. These are attached to “operators”, which define the actions that users can perform, and are used to automatically construct a
    GUI for those operators. This mechanism also extends to user-written
    addons in Python.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)