Author Topic: Seeking best ellipse fill function. (For everyone's sake.)  (Read 42309 times)

0 Members and 1 Guest are viewing this topic.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Seeking best ellipse fill function. (For everyone's sake.)
« Reply #45 on: February 10, 2019, 06:55:35 pm »
So what Steve is saying is that...

R + R is faster than 2 * R
R * R is faster than R ^ 2

so for example in the original code...

xx = ry * ry * (1 - rx - rx) ' Original code

is faster than changing it to...

xx = ry * ry * (1 - 2 * rx)

I see you just changed it back to the original code, which should match the last one I posted, where I changed it back as well. So we should now have the fastest way to move through the equations, plus my fix the periodic fill problem. All good to go?

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Seeking best ellipse fill function. (For everyone's sake.)
« Reply #46 on: February 10, 2019, 07:37:19 pm »
I just ran the timed test in a 32 bit version of QB64 and saved almost 3 sec on both CircleFill and EllipseFill.

Ha! go figure.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Seeking best ellipse fill function. (For everyone's sake.)
« Reply #47 on: February 10, 2019, 07:46:51 pm »
And I just save hundreds by switching my car insurance to GEICO.

So 64-bit has too much memory allocated for more digits than needed, maybe, or just a fluke?

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Seeking best ellipse fill function. (For everyone's sake.)
« Reply #48 on: February 10, 2019, 07:55:05 pm »
I just ran the timed test in a 32 bit version of QB64 and saved almost 3 sec on both CircleFill and EllipseFill.

Ha! go figure.

And have fun playing with some of the math optimization flags.  They can drastically change your test times.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Seeking best ellipse fill function. (For everyone's sake.)
« Reply #49 on: February 10, 2019, 11:10:43 pm »
Aaaalrighty, didn't expect to be gone all day, so I'm trying to play catchup here. First thing I notice is Steve's function doesn't draw ellipses for large eccentricity (small b). There are boobs on each end - just a recent artifact or was that there all along?

100% regardless of this issue or any others, I think the situation demands a pencil-to-paper derivation of how that function works. I'll reinvent it all if I have to, but surely it's among Steve's notes somewhere?

fdsfadfdfd.png
* fdsfadfdfd.png (Filesize: 11.58 KB, Dimensions: 1037x430, Views: 268)
You're not done when it works, you're done when it's right.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Seeking best ellipse fill function. (For everyone's sake.)
« Reply #50 on: February 10, 2019, 11:21:53 pm »
Aaaalrighty, didn't expect to be gone all day, so I'm trying to play catchup here. First thing I notice is Steve's function doesn't draw ellipses for large eccentricity (small b). There are boobs on each end - just a recent artifact or was that there all along?

100% regardless of this issue or any others, I think the situation demands a pencil-to-paper derivation of how that function works. I'll reinvent it all if I have to, but surely it's among Steve's notes somewhere?

Afraid not.  I found it in an old QB45 program that was on an old drive of mine from ages ago.  I have no idea where the heck I originally acquired/derived it, and I didn’t take any notes as I tweaked it to remove duplicate lines in the past. (And it seems I still missed a few, but I think Pete’s fix corrects those.)

I’ll see if I can pull the original back up later (I have to reinstall the old 40GB drive and an IDE card/cable to use it), and see if the “boob effect” is there from the original, or introduced via alterations.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Seeking best ellipse fill function. (For everyone's sake.)
« Reply #51 on: February 10, 2019, 11:35:52 pm »
I noticed we had an ellipse with tits, too... with some sizes... but seriously guys, you wanna change that??!

Pete :D
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Seeking best ellipse fill function. (For everyone's sake.)
« Reply #52 on: February 10, 2019, 11:47:31 pm »
Although I'm from Massachusetts, I take a page out of the Texas playbook when it comes to certain anatomical preferences. I wish the tit effect would show up for BIG ellipses, not puny little pointy ones.

XD

I should modify my Tilted ellipse to include a Titted ellipse version as well...
« Last Edit: February 10, 2019, 11:48:50 pm by STxAxTIC »
You're not done when it works, you're done when it's right.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Seeking best ellipse fill function. (For everyone's sake.)
« Reply #53 on: February 11, 2019, 12:42:11 am »
We can still make a fortune selling this to dress designers, who outfit super-models...  So, there's a bright side!

Pete :D
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Seeking best ellipse fill function. (For everyone's sake.)
« Reply #54 on: February 11, 2019, 01:06:58 am »
Alright, so this function is optimized for clarity instead of speed, but has a lovely out-of-the-box feature of running about as fast as the one Steve brought in. Surely more speed can be injected into this thing, too.

Code: QB64: [Select]
  1. SUB FlatEllipseFill (ox AS INTEGER, oy AS INTEGER, a AS INTEGER, b AS INTEGER, col AS _UNSIGNED LONG)
  2.     DIM h2 AS LONG
  3.     DIM w2 AS LONG
  4.     DIM h2w2 AS LONG
  5.     DIM xi AS INTEGER
  6.     DIM dx AS INTEGER
  7.     DIM x AS INTEGER
  8.     DIM y AS INTEGER
  9.     w2 = a * a
  10.     h2 = b * b
  11.     h2w2 = h2 * w2
  12.     xi = a
  13.     dx = 0
  14.     LINE (ox - a, oy)-(ox + a, oy), col, BF
  15.     FOR y = 1 TO b
  16.         FOR x = xi - dx + 1 TO 0 STEP -1
  17.             IF x * x * h2 + y * y * w2 <= h2w2 THEN EXIT FOR
  18.         NEXT
  19.         dx = xi - x
  20.         xi = x
  21.         LINE (ox - xi, oy + y)-(ox + xi, oy + y), col, BF
  22.         LINE (ox - xi, oy - y)-(ox + xi, oy - y), col, BF
  23.     NEXT

... just have to check it for bugs, boobs, or other artifacts.
« Last Edit: February 11, 2019, 01:16:44 am by STxAxTIC »
You're not done when it works, you're done when it's right.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Seeking best ellipse fill function. (For everyone's sake.)
« Reply #55 on: February 11, 2019, 01:52:43 am »
This one fails at various levels, too. Here is one, for example...

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(1000, 700, 32)
  2. _SCREENMOVE 180, 20
  3.  
  4. FlatEllipseFill 500, 350, 400, 200, _RGBA(255, 255, 255, 40)
  5.  
  6. SUB FlatEllipseFill (ox AS INTEGER, oy AS INTEGER, a AS INTEGER, b AS INTEGER, col AS _UNSIGNED LONG)
  7. DIM h2w2 AS LONG
  8. w2 = a * a
  9. h2 = b * b
  10. h2w2 = h2 * w2
  11. xi = a
  12. dx = 0
  13. LINE (ox - a, oy)-(ox + a, oy), col, BF
  14. FOR y = 1 TO b
  15.     FOR x = xi - dx + 1 TO 0 STEP -1
  16.         IF x * x * h2 + y * y * w2 <= h2w2 THEN EXIT FOR
  17.     NEXT
  18.     dx = xi - x
  19.     xi = x
  20.     LINE (ox - xi, oy + y)-(ox + xi, oy + y), col, BF
  21.     LINE (ox - xi, oy - y)-(ox + xi, oy - y), col, BF
  22.  

201 fails, too, but plug in 203 and it's fine.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Seeking best ellipse fill function. (For everyone's sake.)
« Reply #56 on: February 11, 2019, 02:27:07 am »
So what Steve is saying is that...
...
R * R is faster than R ^ 2
...
Pete

and _SHL\_SHR are even faster if dealing with powers of 2
so _SHL(R,1) should be faster than R^2 and R*R
only draw back is it has to be power of 2.

I like 2s, 2 eyes, 2 ears, 2 hands, 2 balls.., 2 teats.... life is full of 2s unless your a cow then its 4 teats(hey power of 2!) or pigs then its 8 teats (hey another power of 2!) not versed enough in animal biology does any animal have 16 teats?
Granted after becoming radioactive I only have a half-life!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Seeking best ellipse fill function. (For everyone's sake.)
« Reply #57 on: February 11, 2019, 02:40:21 am »
Siamese pigs.
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Seeking best ellipse fill function. (For everyone's sake.)
« Reply #58 on: February 11, 2019, 02:45:10 am »
Bill, simple variable designation problem. LONG doesn't cut it, so....

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(1000, 700, 32)
  2. _SCREENMOVE 180, 20
  3.  
  4. FlatEllipseFill 500, 350, 400, 200, _RGBA(255, 255, 255, 40)
  5.  
  6. SUB FlatEllipseFill (ox AS INTEGER, oy AS INTEGER, a AS INTEGER, b AS INTEGER, col AS _UNSIGNED LONG)
  7. w2 = a * a
  8. h2 = b * b
  9. h2w2 = h2 * w2
  10. xi = a
  11. dx = 0
  12. LINE (ox - a, oy)-(ox + a, oy), col, BF
  13. FOR y = 1 TO b
  14.     FOR x = xi - dx + 1 TO 0 STEP -1
  15.         IF x * x * h2 + y * y * w2 <= h2w2 THEN EXIT FOR
  16.     NEXT
  17.     dx = xi - x
  18.     xi = x
  19.     LINE (ox - xi, oy + y)-(ox + xi, oy + y), col, BF
  20.     LINE (ox - xi, oy - y)-(ox + xi, oy - y), col, BF
  21.  

So I tested it with this, and no glitches. It will make a circle at 300 and then start on a vertical ellipse. It's also a fun effect if you omit the CLS and sleep. Stop it at 300 and you get a full moon effect.

Anyway, maybe something less than DOUBLE can be used but that for/next loop spits out some very large figures.

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(1000, 700, 32)
  2. _SCREENMOVE 180, 20
  3.  
  4. FOR i = 1 TO 350
  5.     CLS
  6.     PRINT "300 x"; i
  7.     FlatEllipseFill 500, 350, 300, i, _RGBA(255, 255, 255, 40)
  8.     SLEEP
  9.  
  10. SUB FlatEllipseFill (ox AS INTEGER, oy AS INTEGER, a AS INTEGER, b AS INTEGER, col AS _UNSIGNED LONG)
  11. w2 = a * a
  12. h2 = b * b
  13. h2w2 = h2 * w2
  14. xi = a
  15. dx = 0
  16. LINE (ox - a, oy)-(ox + a, oy), col, BF
  17. FOR y = 1 TO b
  18.     FOR x = xi - dx + 1 TO 0 STEP -1
  19.         IF x * x * h2 + y * y * w2 <= h2w2 THEN EXIT FOR
  20.     NEXT
  21.     dx = xi - x
  22.     xi = x
  23.     LINE (ox - xi, oy + y)-(ox + xi, oy + y), col, BF
  24.     LINE (ox - xi, oy - y)-(ox + xi, oy - y), col, BF
  25.  

I was about half way through making one like this, after getting the formulas together to calculate the parts of an ellipse. Oh well, spoiler. Nice find, Bill...

Pete
« Last Edit: February 11, 2019, 03:00:16 am by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Seeking best ellipse fill function. (For everyone's sake.)
« Reply #59 on: February 11, 2019, 06:48:30 am »
Ah, there are the finishing touches. I figured I was being lazy with respect to variable types but it was also pretty late. I blame Loki. So now I suppose we just wait for bplus to get hold of this...
You're not done when it works, you're done when it's right.