Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 06:24 27 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : CMM2 - et al - Can BOX w or h be -ve?

Author Message
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 847
Posted: 12:48am 15 Aug 2020
Copy link to clipboard 
Print this post

Morning all,
Is it me or can the w or h in a BOX command NOT be negative?
Mathematically it is possible but MMBasic does nothing (ie no box and no error).
Is it easy to fix or should I find a work around?
(I'm not sure if it is only CMM2's version of MMBasic)

Cheers,

Andrew
 
berighteous
Senior Member

Joined: 18/07/2020
Location: United States
Posts: 110
Posted: 01:23am 15 Aug 2020
Copy link to clipboard 
Print this post

The workaround is don't put negative numbers in w or h.  Why are you putting negative numbers in box?
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 847
Posted: 03:06am 15 Aug 2020
Copy link to clipboard 
Print this post

Thanks,
I'm not putting -ve numbers in a box - the equations are!
It might help you to know that LINE accepts -ve numbers - try:
LINE 400, 200, -200, 100

A -ve number merely instructs BASIC to go up or left, in this case, on a bar graph.

I'm porting a 2,500 line QB45 program to CMM2 and because QB45 accepts and correctly interprets, -ve numbers I've noticed that MMBasic appears not to. I then delved further.

Sure I can re-write the equations or test for -ve but I simply, and I think quite reasonably, inquired if it was intended.

Andrew
 
capsikin
Guru

Joined: 30/06/2020
Location: Australia
Posts: 341
Posted: 03:32am 15 Aug 2020
Copy link to clipboard 
Print this post

  Andrew_G said  (I'm not sure if it is only CMM2's version of MMBasic)


The old colour maximite 1 manual (Ver 4.5) doesn't have a box command, and the box version of the line command takes two opposite corners so it doesn't take a width and height.
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 847
Posted: 03:50am 15 Aug 2020
Copy link to clipboard 
Print this post

Hi Capsikin,

By this:
  Quote  (I'm not sure if it is only CMM2's version of MMBasic)


I was thinking more of whether the MM170, MM+ etc had the same "feature" (because I haven't tested it on them) rather than the CMM1. It is easy (but a little time consuming - and I am part way through) to fix my current program but I thought it worth asking if it was intended.

Cheers,

Andrew
 
mclout999
Guru

Joined: 05/07/2020
Location: United States
Posts: 469
Posted: 04:12am 15 Aug 2020
Copy link to clipboard 
Print this post

  capsikin said  
  Andrew_G said  (I'm not sure if it is only CMM2's version of MMBasic)


The old colour maximite 1 manual (Ver 4.5) doesn't have a box command, and the box version of the line command takes two opposite corners so it doesn't take a width and height.


I have not liked this form of the box and rbox command because it is atypical of traditional basics like GW and most of the others I have used. Are there other basics that used this form.  It forces more complex computations that the old x-y x-y format of the basics I am accustomed to.  If the old MMbasic had the traditionl form why was this new form chosen?  I mean by this is there a benefit of this form. I find it more cumbersome and am sure it will make conversion of old GW and old MMbasic programs more difficult or am I wrong?
 
capsikin
Guru

Joined: 30/06/2020
Location: Australia
Posts: 341
Posted: 04:44am 15 Aug 2020
Copy link to clipboard 
Print this post

  mclout999 said  
  capsikin said  
  Andrew_G said  (I'm not sure if it is only CMM2's version of MMBasic)


The old colour maximite 1 manual (Ver 4.5) doesn't have a box command, and the box version of the line command takes two opposite corners so it doesn't take a width and height.


I have not liked this form of the box and rbox command because it is atypical of traditional basics like GW and most of the others I have used. Are there other basics that used this form.  It forces more complex computations that the old x-y x-y format of the basics I am accustomed to.  If the old MMbasic had the traditionl form why was this new form chosen?  I mean by this is there a benefit of this form. I find it more cumbersome and am sure it will make conversion of old GW and old MMbasic programs more difficult or am I wrong?


For drawing a small fixed size box to erase a sprite or tile I find the new form easier. For drawing over most of the screen I think it would be harder. I haven't used rbox.

I like the name box better than line for drawing a rectangle.

I did find it made porting invaders more difficult, if I was starting again I'd write a box_corners sub that takes more of the old arguments.
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1109
Posted: 04:44am 15 Aug 2020
Copy link to clipboard 
Print this post

A variation that expects coordinates of two (opposite) corners:

boxy 200,200,50,-50,3,rgb(white),rgb(magenta)

' Subroutine to draw a box given coordinates of opposite corners
' Any number of coordinates can be negative
' Lineweight (lw), colour (c) and fill colour (cfill) must be given if other than 0
sub boxy(x1,y1,x2,y2,lw,c,cfill)
 local float xs,ys,w,h

 h = abs(x1 - x2)
 v = abs(y1 - y2)
 xs = min(x1,x2)
 ys = min(y1,y2)

 box xs,ys,h,v,lw,c,cfill
end sub


The only problem is default colours are not obeyed. If you skip a parameter, it will be filled in with the value 0.

A simple variation of this could be made to accept h and v with possible negative signs.
Visit Vegipete's *Mite Library for cool programs.
 
capsikin
Guru

Joined: 30/06/2020
Location: Australia
Posts: 341
Posted: 04:53am 15 Aug 2020
Copy link to clipboard 
Print this post

  Andrew_G said  Hi Capsikin,

By this:
  Quote  (I'm not sure if it is only CMM2's version of MMBasic)


I was thinking more of whether the MM170, MM+ etc had the same "feature" (because I haven't tested it on them) rather than the CMM1. It is easy (but a little time consuming - and I am part way through) to fix my current program but I thought it worth asking if it was intended.

Cheers,

Andrew


Ah okay. I would guess it is intended, because in the CMM2 manual it says for box "with the top left hand corner at 'x' and 'y'". Although for rbox it says "starting at 'x' and 'y'" instead. That's just my guess though.
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 847
Posted: 04:54am 15 Aug 2020
Copy link to clipboard 
Print this post

Thanks Pete,
That will work!
(But I'm still interested as to whether this is a "feature", "quirk" or "bug").

Cheers,

Andrew
 
capsikin
Guru

Joined: 30/06/2020
Location: Australia
Posts: 341
Posted: 04:57am 15 Aug 2020
Copy link to clipboard 
Print this post

  vegipete said  A variation that expects coordinates of two (opposite) corners:

boxy 200,200,50,-50,3,rgb(white),rgb(magenta)

' Subroutine to draw a box given coordinates of opposite corners
' Any number of coordinates can be negative
' Lineweight (lw), colour (c) and fill colour (cfill) must be given if other than 0
sub boxy(x1,y1,x2,y2,lw,c,cfill)
 local float xs,ys,w,h

 h = abs(x1 - x2)
 v = abs(y1 - y2)
 xs = min(x1,x2)
 ys = min(y1,y2)

 box xs,ys,h,v,lw,c,cfill
end sub


The only problem is default colours are not obeyed. If you skip a parameter, it will be filled in with the value 0.

A simple variation of this could be made to accept h and v with possible negative signs.


This draws a width and height zero box if x1=x2 and y1=y2, possibly it should be width and height 1. (hmm, I'm assuming x1 and x2 etc are pixel coordinates. I don't see it specified if the CMM1 box coordinates are for the corner pixels themselves, or the corner of the corner pixels, so I could be wrong.)

(edited to add: thanks, that will be helpful)
Edited 2020-08-15 18:21 by capsikin
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9122
Posted: 07:53am 15 Aug 2020
Copy link to clipboard 
Print this post

  Quote  Is it me or can the w or h in a BOX command NOT be negative?


The CMM2 works exactly like the Micromite (same code) and ignores the BOX and RBOX commands if w or h are negative or zero

HOWEVER, if you ask really nicely then I might just remove the restriction in the next beta  
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 847
Posted: 09:08am 15 Aug 2020
Copy link to clipboard 
Print this post

Hi Peter,
Your call (I've worked around my initial issue) but it did seem strange . . .
(How nice do I have to be? - but I DO have my limits).

Thanks for all your good work and cheers,

Andrew
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024