Post Reply 
A simple graphics rectangle? My coordinates are wrong
06-01-2016, 11:16 PM
Post: #1
A simple graphics rectangle? My coordinates are wrong
This should be a simple rectangle inside a rectangle - but I am not seeing the border I expect.
It seems almost like the inner x,y coordinates are being seen as lengths rather than absolute coordinates.
Where am I going wrong?
(Android version)
Code:


 LOCAL BWIDTH:=8; //FRAME OR BORDER
 LOCAL YLEN:=192; //OR 175 MAIN AREA
 //INNER RECT IS 255*YLEN

 DRAW_IT()
 BEGIN
  LOCAL COLY:=#0F0F0FFFh;
  //WHERE IS 255,YLEN;
  RECT_P(255,YLEN,255,YLEN,#04040404h);
  WAIT;
  TEXTOUT_P("*",255,YLEN);
  WAIT;
  //DRAW FRAME
  //RECT_P(0,0,255+2*BWIDTH,YLEN+2*BWIDTH,#0F0F0FFFh,#7F7F7FFFh);
  ///THE OUTER X IS 255+2B
  ///THE OUTER Y IS YLEN+2B
  RECT_P(0,0,255+2*BWIDTH,BWIDTH,COLY);
  WAIT;
  RECT_P(0,BWIDTH,BWIDTH,YLEN+BWIDTH,COLY);
  WAIT;
  RECT_P(255+BWIDTH,BWIDTH,255+2*BWIDTH,YLEN+BWIDTH,COLY);
  WAIT;
  RECT_P(0,YLEN+BWIDTH,255+2*BWIDTH,YLEN+2*BWIDTH,COLY);
  TEXTOUT_P("255+2B=",255+2*BWIDTH,20);
  TEXTOUT_P(255+2*BWIDTH,255+2*BWIDTH,40);
  WAIT;
  //DRAW MAIN-THIS LOOKS RIGHT
  //A FRAME ALL AROUND
  //WHY IS TEXT TO LEFT OF EDGE? BOTH 255
  //THE RECT AND TEXTOUT COORDINATES ARE NOT ALIGNED?
  RECT_P(BWIDTH,BWIDTH,255,YLEN,#FF0101FFh,#07FF07FFh);
  TEXTOUT_P("255",255,80);
  WAIT;
  //BUT SHOULD IT NOT BE
  RECT_P(BWIDTH,BWIDTH,255+BWIDTH,YLEN+BWIDTH,#FF0101FFh,#07FF07FFh);
  TEXTOUT_P("255+",255+BWIDTH,YLEN+BWIDTH);
  //BECAUSE OF THE TOP/LEFT FRAME
  //BUT THAT LOOKS WRONG
  WAIT;
 END;
 
 EXPORT TRYFRAMEONE()
 BEGIN
  //DIMGROB_P(G0,320,240);
  RECT_P();
  DRAW_IT();
  FREEZE; 
 END;

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
06-02-2016, 05:28 AM
Post: #2
RE: A simple graphics rectangle? My coordinates are wrong
Hello,

RECT_P uses the top left and bottom right (included) coordinates.

Text writing is always strange because characters do not always start on the provided starting point. They are very often shifted by a number of pixels.

Why are you using so many alpha channel values? are you truly trying to have semi transparent colors in your test program?

Cyrille

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
Find all posts by this user
Quote this message in a reply
06-02-2016, 06:42 AM (This post was last modified: 06-02-2016 06:55 AM by StephenG1CMZ.)
Post: #3
RE: A simple graphics rectangle? My coordinates are wrong
(06-02-2016 05:28 AM)cyrille de brébisson Wrote:  Hello,

RECT_P uses the top left and bottom right (included) coordinates.

Text writing is always strange because characters do not always start on the provided starting point. They are very often shifted by a number of pixels.

Why are you using so many alpha channel values? are you truly trying to have semi transparent colors in your test program?

Cyrille

No, all I wanted was two different colours - I will add in a list of more sensible values for the user to choose later. But first, I want to understand why the final inner rectangle obscures the border - not because of transparency, but the x and y coordinates are not producing what I expected.

If I understand it, the coordinate (255+border,YLEN+border) should not overlap the outer border at (255+2border,YLEN+2border) and overwrite the final border. I think I need to find a bug in my code or understanding.

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
06-03-2016, 05:46 PM
Post: #4
RE: A simple graphics rectangle? My coordinates are wrong
(06-02-2016 05:28 AM)cyrille de brébisson Wrote:  RECT_P uses the top left and bottom right (included) coordinates.

(06-02-2016 06:42 AM)StephenG1CMZ Wrote:  If I understand it, the coordinate (255+border,YLEN+border) should not overlap the outer border at (255+2border,YLEN+2border) and overwrite the final border. I think I need to find a bug in my code or understanding.

I think your problem is in the definition above. It draws up to and including those coordinates.
So you go (0,0) to (255+2*BWIDTH,BWIDTH), then (0,BWIDTH) to (BWIDTH,YLEN+BWIDTH) for example.
The segment exactly at (0,BWIDTH) to (BWIDTH,BWIDTH) is included in both rectangles, therefore it's overlapping.
If you want your width to be 255 pixels and have BWIDTH border each side, you'll go:
from 0 to BWIDTH-1, then your main area goes from BWIDTH to 255+BWIDTH-1, and the final border from 255+BWIDTH to 255+2*BWIDTH-1.
Find all posts by this user
Quote this message in a reply
06-05-2016, 08:35 AM (This post was last modified: 06-05-2016 08:37 AM by StephenG1CMZ.)
Post: #5
RE: A simple graphics rectangle? My coordinates are wrong
Thanks for your insights guys...
This version seems much clearer.
One known bug for me to look into in this code if it becomes necessary:
If border width is changed to 0 a border still appears.

Code:


 LOCAL Y0:=0;
 LOCAL BWIDTH:=8; //FRAME OR BORDER
 //KNOWN BUG:A WIDTH OF 0 STILL GIVES A BORDER
 
 LOCAL XLEN:=255; //255;
 LOCAL YLEN:=192; //192; //OR 175 MAIN AREA
 //INNER RECT IS XLEN*YLEN
 LOCAL BORDERU,BORDERD,BORDERL,BORDERR,SCRN;
 LOCAL COLRB:=RGB(0,0,#CDh);
 LOCAL COLRS:=RGB(0,#CDh,0);

 INITS()
 BEGIN
  BORDERU:={0,Y0,             XLEN+2*BWIDTH-1,Y0+BWIDTH-1};
  BORDERD:={0,Y0+BWIDTH+YLEN, XLEN+2*BWIDTH-1,Y0+YLEN+2*BWIDTH-1};
  BORDERL:={0,Y0+BWIDTH,      BWIDTH-1,Y0+YLEN+BWIDTH-1};
  BORDERR:={XLEN+BWIDTH,Y0,   XLEN+2*BWIDTH-1,Y0+YLEN+2*BWIDTH-1};
  SCRN:=   {BWIDTH,Y0+BWIDTH, XLEN+BWIDTH-1,Y0+YLEN+BWIDTH-1,COLRS};
 END;

 DRAW_BORDER()
 BEGIN
  RECT_P(BORDERU(1),BORDERU(2),BORDERU(3),BORDERU(4),COLRB);
  RECT_P(BORDERR(1),BORDERR(2),BORDERR(3),BORDERR(4),COLRB);
  RECT_P(BORDERD(1),BORDERD(2),BORDERD(3),BORDERD(4),COLRB);
  RECT_P(BORDERL(1),BORDERL(2),BORDERL(3),BORDERL(4),COLRB);
  WAIT;
 END;

 DRAW_SCREEN()
 BEGIN
  RECT_P(SCRN(1),SCRN(2),SCRN(3),SCRN(4),COLRS);
 END;

 
 EXPORT BORDER()
 BEGIN
  RECT_P();
  INITS();
  DRAW_BORDER();
  DRAW_SCREEN();
  FREEZE; 
 END;

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
06-05-2016, 12:15 PM
Post: #6
RE: A simple graphics rectangle? My coordinates are wrong
Hello Stephen,
the problem must be computation of data in BORDERU, if BWIDTH is 0 then BORDERU(4) is -1, I don't know why this works at all.
But after I tried without these -1 parts the Programm still draws a line. So the conclusion is that rect_p cannot draw rectangles of size 0.
Arno
Find all posts by this user
Quote this message in a reply
06-05-2016, 08:46 PM
Post: #7
RE: A simple graphics rectangle? My coordinates are wrong
Well,
concerning my last answer I now wrote 2 simple lines of code
Code:
RECT_P();
RECT_P(11,10,11,100,RGB(0,0,#CDh));
which draws a blue line even if one might expect that a rectangle of width 0 is not drawn at all. So if you need the possibility to have no border you must include it in some if then statements.
Arno
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)