tobias...@t-online.de ha scritto:
   Dear Mailing-Liste,
   my name is Tobias and I have the following problem:
   The function y=f(x) shall be displayed with the values x_min <= x <= x_max
   in a drawing area (dwg.ClientW = const = 801, dwg.ClientH = const = 601)
   using the methods Draw.Scale and Draw.Translate.
   My questions:
   *What do these methods do?
   *How do I use them to fix my problem?
   Every tip to use these methods or a source to read is welcome - especially
   with examples.
The scale() function multiplies the X and Y coordinates for the values you specify, respectively in the first and second argument. So, if you issue a line(0,0,100,100), the normal result would be a diagonal line "\" starting in the upper-left corner of the drawing area, and going to the right and down. If a scale(2,2) is in effect, then the line will have the same appearance, but it will extend to (200;200) because every single coordinate is first multiplied by the scale() values. If these values are equal, then the aspect ratio is mantained; if these values are different an anamorphic transformation takes effect; you can use this to correct some monitor problem... Note that the computer graphic conventions say that the Y coordinate gets bigger going down to the screen, which is exactly the contrary in the normal world. So you can use draw.scale(..., -1) to flip the graphics in the correct way.

To fit your function in you drawing area, you should use ScaleX=801/(x_max-x_min), and OffsetX=-x_min:

   draw.begin(...)
   draw.scale(801/(x_max-x_min), ???)
   draw.translate(-x_min, 0?)
   blahblahblah (draw.point(), draw.line()...)
   draw.end()

Note that draw.translate() takes coordinates which then get scaled by scale(): this is why you can use "-x_min" in the draw.translate. If you invert the order of scale() and translate(), then the coordinates passed to translate() are no more "world" coordinates, but "device" coordinates.

Anyway, I attach a project: play with the controls to see their effect. Note that in the drawing routine the order is "scale, translate". Try to invert this order to see the effect.

Last thing to say: drawingareas can work in two modes - cached and not cached. In cached mode, you draw on them when you want, and they keep the data, much like normal paper (so you must erase them to change the contents). The mode I used is not cached, which is more correct in this case; when the graphic needs to be displayed, it "asks" your code to paint the area (using an event) - no image is kept in memory and, besides, it is possible to optimize a few things. To update the image, you refresh() the drawingarea, which in turn raises the event; this also happens when you cover the graphic with another window and later you unveil it.

Hope this introduction can help: ask for more if you are in need.

Regards,
Doriano


Attachment: draw-0.0.1.tar.gz
Description: application/gzip

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to