From: neil on
On Wed, 14 Jul 2010 15:39:25 +0100, Francis Glassborow wrote:

>> 2.once the user gives x,y coordinates the function will need to test to
>> see if the values are 'within range'. Valid values will depend on the
>> scale given. How can I test to know that for a given scale the x,y
>> coordinates are valid?
>
> Well if you know the origin and no the dimensions of playpen in raw
> pixels (512 by 512 if memory serves me correctly) Multiply each
> co-ordinate by the scale and you will have the offset from the origin in
> raw pixels. Now if you know where the origin is you should be able to
> compute whether the point is in the display window.
>

I think i see what you were explaining now.
From: Francis Glassborow on
neil wrote:

> The problem is with the function where(). The program works but if an out
> of range value id given for x,y - nothing will be out put. I would really
> like to identify out of range values like i have done in the previous two
> functions in here - although the replies have explained in a way how i
> might do this, i dont really understand and would ask that someone can
> please tell me how to check that the values x,y are in range - which
> depend upon the scale.
> thanks

OK, let me give it a shot.

Windows uses a plotting method that is not the same as the one we were
taught in school where plus is up or right and minus is down or left.
Playpen calls the windows type co-ordinates raw_pixels but the library
provides functions that do the translation from what we use in class to
the ones that the computer uses.

the origin() function reports where the origin is currently located on
the screen. and the second version origin(int, int) allows the
programmer to specify where he now wants the origin to be (and it can be
anywhere. The width and height of the Playpen window is fixed at 512 by
512 pixels (that is screen resolution pixels) and the plotting functions
always check that the raw pixels are only plotted if they lie within the
currently visible area. (Think of the display as a window onto a much
larger piece of graph paper.)

The first thing to do is to experiment with the origin command and the
plot command to make sure you understand how the origin gets moved
around. Here is a little program that will allow you to do that.

int main(){
int x;
int y;
Playpen paper;
cout << "Give the co-ordinates for the new origin: ";
cin >> x;
cin >> y;
paper.origin(x, y);
paper.plot(0, 0);
paper.display();
cin.get();
return 0;
}

Now as to scale(). This pair of functions works like the origin ones,
the first version tells you what the scale is and the second one allows
you to set the scale to a new value.

Now take the co-ordinates of a point you intend to plot. The scale tells
you what size square will be used to plot a point. With a scale of 1 you
will get a tiny, single pixel point on the screen, with a scale of 2 you
will get a 2 by 2 block of pixels, with a scale of 3 you will get a 3 by
3 block of pixels etc.

The point (0, 0) (i.e. the origin) will be displayed as an n by n block
of pixels with the bottom left vertex at the raw origin. Try
experimenting with the scale to see this in practice.


Finally take each co-ordinate of the point you want to display and
multiply it by the scale. Now add in the location of the origin (i.e.
the values you used to set the origin) If the result is less than 0 or
greater than 511 the point will not be fully displayed on the screen
(though some part of it might be if the point is just outside the screen.

I know this may seem complicated, so play with it. The whole purpose of
Playpen is to allow you to play :) and gain practical experience until
the underlying principles make sense.

Note that the Playpen functionality ensures that you will not bne able
to damage your hardware or crash the program by trying to plot points
outside the current display area, so play to your hearts content until
you have developed a mental model of what is happening.



From: neil on
On Thu, 15 Jul 2010 17:55:55 +0100, Francis Glassborow wrote:

> neil wrote:
>
>> The problem is with the function where(). The program works but if an
>> out of range value id given for x,y - nothing will be out put. I would
>> really like to identify out of range values like i have done in the
>> previous two functions in here - although the replies have explained in
>> a way how i might do this, i dont really understand and would ask that
>> someone can please tell me how to check that the values x,y are in
>> range - which depend upon the scale.
>> thanks
>
> OK, let me give it a shot.
>
> Windows uses a plotting method that is not the same as the one we were
> taught in school where plus is up or right and minus is down or left.
> Playpen calls the windows type co-ordinates raw_pixels but the library
> provides functions that do the translation from what we use in class to
> the ones that the computer uses.
>
> the origin() function reports where the origin is currently located on
> the screen. and the second version origin(int, int) allows the
> programmer to specify where he now wants the origin to be (and it can be
> anywhere. The width and height of the Playpen window is fixed at 512 by
> 512 pixels (that is screen resolution pixels) and the plotting functions
> always check that the raw pixels are only plotted if they lie within the
> currently visible area. (Think of the display as a window onto a much
> larger piece of graph paper.)
>
> The first thing to do is to experiment with the origin command and the
> plot command to make sure you understand how the origin gets moved
> around. Here is a little program that will allow you to do that.
>
> int main(){
> int x;
> int y;
> Playpen paper;
> cout << "Give the co-ordinates for the new origin: "; cin >> x;
> cin >> y;
> paper.origin(x, y);
> paper.plot(0, 0);
> paper.display();
> cin.get();
> return 0;
> }
>
> Now as to scale(). This pair of functions works like the origin ones,
> the first version tells you what the scale is and the second one allows
> you to set the scale to a new value.
>
> Now take the co-ordinates of a point you intend to plot. The scale tells
> you what size square will be used to plot a point. With a scale of 1 you
> will get a tiny, single pixel point on the screen, with a scale of 2 you
> will get a 2 by 2 block of pixels, with a scale of 3 you will get a 3 by
> 3 block of pixels etc.
>
> The point (0, 0) (i.e. the origin) will be displayed as an n by n block
> of pixels with the bottom left vertex at the raw origin. Try
> experimenting with the scale to see this in practice.
>
>
> Finally take each co-ordinate of the point you want to display and
> multiply it by the scale. Now add in the location of the origin (i.e.
> the values you used to set the origin) If the result is less than 0 or
> greater than 511 the point will not be fully displayed on the screen
> (though some part of it might be if the point is just outside the
> screen.
>
> I know this may seem complicated, so play with it. The whole purpose of
> Playpen is to allow you to play :) and gain practical experience until
> the underlying principles make sense.
>
> Note that the Playpen functionality ensures that you will not bne able
> to damage your hardware or crash the program by trying to plot points
> outside the current display area, so play to your hearts content until
> you have developed a mental model of what is happening.

Thank you for this - i think i need to experiment with the programs a
little more like you have suggested.