[racket] plot pixel position

From: Neil Toronto (neil.toronto at gmail.com)
Date: Tue Apr 1 17:41:52 EDT 2014

On 04/01/2014 02:17 PM, David Vanderson wrote:
> Plot is fantastic - thanks so much!
>
> Is there a way to hook into the interactive features of plot so, for
> instance, the user could click to add data or drag data points around?
>
> I'm using plot/dc to draw onto a canvas, and I'd be more than happy just
> to be able to ask a plot to translate a pixel position to the
> corresponding axes' positions.  I know that plot does this for the
> zooming feature, but is there a way for external code to do it?

There's not an easy way right now.

If you don't mind copying code, you can take some from `plot/dc' here:

     pkgs/plot-pkgs/plot-lib/plot/private/no-gui/plot2d.rkt

The main thing you need is access to the `area' object, which has a 
public `dc->plot' method that translates device context coordinates into 
plot coordinates. I'm sorry it's not easier. :/

It will be someday, I promise! I've lately decided that "2D and 3D games 
that use Plot to render scenes" will be two of my main test cases. Games 
are the most interactive uses I can think of, and they need to be fast, 
so that should cover pretty much everyone's interactivity needs.

Neil ⊥


Posted on the users mailing list.