Author Topic: and another one for your toolbox...  (Read 21262 times)

0 Members and 1 Guest are viewing this topic.

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
Re: and another one for your toolbox...
« Reply #75 on: March 04, 2020, 07:44:27 pm »
Rotozoom is definitely one for the toolbox, it's worked flawlessly in everything I've used it in.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
Re: and another one for your toolbox...
« Reply #76 on: March 04, 2020, 07:55:25 pm »
Thanks for your input Moses - *this* is why code needs to cook out in Programs for a while before being ordained.
You're not done when it works, you're done when it's right.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: and another one for your toolbox...
« Reply #77 on: March 04, 2020, 09:32:53 pm »
Yes to cooking! But I know OldMoses is referring to RotoZoom2. 3 has a slight change using the Rotation Units of Radians instead of Degrees.

I just cooked up a little show in the demo to show RotoZoom3 in action loop, see Best Answer. I also wanted to show how _WIDTH(imageHandle&) and _HEIGHT(imageHandle&) can be used with the x and y Scale parameters.
« Last Edit: March 04, 2020, 09:36:20 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: and another one for your toolbox...
« Reply #78 on: March 07, 2020, 10:58:18 pm »
OK I posted RotoZoom3.

Funny story, I was looking all through samples for it after STxAxTIC assimilated the Toolbox into the Child-boards of Samples. Where is it? Oh, you haven't posted it yet, you ninny!

So I guess it's time to post it.
https://www.qb64.org/forum/index.php?topic=2313.msg115354#msg115354
« Last Edit: September 12, 2020, 01:33:12 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: and another one for your toolbox...
« Reply #79 on: April 09, 2020, 02:49:35 pm »
Thanks to Petr who helped Craz1000 and probably Steve who set Petr up with MEM stuff?

This looks useful and in my opinion didn't need fixing, you just have to keep track of all the new images you are making with _COPYIMAGE. Maybe I am missing something?

Anyway the latest addition to my Toolbox, swapColor Function with demo:
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32) ' b+ tested 2020-04-09
  2. t& = _LOADIMAGE("Templar thru 3d.png")
  3.  
  4. _PUTIMAGE , t& 'check our current image , OK
  5. _TITLE "SwapColor test"
  6. sColor~& = POINT(400, 300)
  7. g = 10
  8.     PRINT "Press any to swap color..."
  9.     SLEEP
  10.     newT& = swapColor&(t&, sColor~&, _RGB32(0, g, 0))
  11.     CLS
  12.     _PUTIMAGE , newT&
  13.     _FREEIMAGE newT&
  14.     g = g + 10
  15.     IF g > 255 THEN g = 10
  16.  
  17. ' create new Image Handle for an image copy with a color changed from original image, returns new Handle&
  18. 'https://www.qb64.org/forum/index.php?topic=2451.0
  19. ' from Petr to Craz1000
  20. FUNCTION swapColor& (oldHandle&, oldcolor~&, newcolor~&)
  21.     DIM m AS _MEM, c AS _UNSIGNED LONG
  22.     swapColor& = _COPYIMAGE(oldHandle&, 32)
  23.     m = _MEMIMAGE(swapColor)
  24.     DO UNTIL a& = m.SIZE - 4
  25.         a& = a& + 4
  26.         c~& = _MEMGET(m, m.OFFSET + a&, _UNSIGNED LONG)
  27.         IF c~& = oldcolor~& THEN _MEMPUT m, m.OFFSET + a&, newcolor~&
  28.     LOOP
  29.     _MEMFREE m
  30.  
  31.  

Image for demo:
* swapColor.zip (Filesize: 32.55 KB, Downloads: 243)
« Last Edit: September 12, 2020, 01:30:56 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: and another one for your toolbox...
« Reply #80 on: June 08, 2020, 12:11:45 am »
« Last Edit: September 12, 2020, 01:30:18 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: and another one for your toolbox...
« Reply #81 on: August 18, 2020, 03:47:07 pm »
« Last Edit: September 12, 2020, 01:29:35 pm by bplus »

Marked as best answer by bplus on September 03, 2020, 03:52:10 pm

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: and another one for your toolbox...
« Reply #82 on: September 03, 2020, 07:51:55 pm »
GetLists for Files and Directory's something Steve has worked up and we've debugged, still may have more to go? Works for Windows and Linux (Linux recently confirmed finally).

Code: QB64: [Select]
  1. ' 2019-08-22 orig post at https://www.qb64.org/forum/index.php?topic=1646.msg108682#msg108682
  2.  
  3. ' direntry.h needs to be in QB64 folder
  4.     FUNCTION load_dir& (s AS STRING)
  5.     FUNCTION has_next_entry& ()
  6.     SUB close_dir ()
  7.     SUB get_next_entry (s AS STRING, flags AS LONG, file_size AS LONG)
  8. REDIM SHARED DIRs(0) AS STRING, FILs(0) AS STRING
  9.  
  10. GetLists ".", DIRs(), FILs()
  11. FOR i = LBOUND(fils) TO UBOUND(fils)
  12.     PRINT i, FILs(i)
  13.     IF i MOD 20 = 19 THEN PRINT "Press any to cont..": SLEEP
  14. PRINT "Press any to cont.. next Folder up": SLEEP
  15. CHDIR ".."
  16. GetLists ".", DIRs(), FILs()
  17. FOR i = LBOUND(fils) TO UBOUND(fils)
  18.     PRINT i, FILs(i)
  19.     IF i MOD 20 = 19 THEN PRINT "Press any to cont..": SLEEP
  20.  
  21.  
  22. SUB GetLists (SearchDirectory AS STRING, DirList() AS STRING, FileList() AS STRING)
  23.  
  24.     CONST IS_DIR = 1
  25.     CONST IS_FILE = 2
  26.     DIM flags AS LONG, file_size AS LONG, DirCount AS INTEGER, FileCount AS INTEGER, length AS LONG
  27.     DIM nam$
  28.     REDIM _PRESERVE DirList(100), FileList(100)
  29.     DirCount = 0: FileCount = 0
  30.  
  31.     IF load_dir(SearchDirectory + CHR$(0)) THEN
  32.         DO
  33.             length = has_next_entry
  34.             IF length > -1 THEN
  35.                 nam$ = SPACE$(length)
  36.                 get_next_entry nam$, flags, file_size
  37.                 IF (flags AND IS_DIR) THEN
  38.                     DirCount = DirCount + 1
  39.                     IF DirCount > UBOUND(DirList) THEN REDIM _PRESERVE DirList(UBOUND(DirList) + 100)
  40.                     DirList(DirCount) = nam$
  41.                 ELSEIF (flags AND IS_FILE) THEN
  42.                     FileCount = FileCount + 1
  43.                     IF FileCount > UBOUND(filelist) THEN REDIM _PRESERVE FileList(UBOUND(filelist) + 100)
  44.                     FileList(FileCount) = nam$
  45.                 END IF
  46.             END IF
  47.         LOOP UNTIL length = -1
  48.         'close_dir 'move to after end if  might correct the multi calls problem
  49.     ELSE
  50.     END IF
  51.     close_dir 'this  might correct the multi calls problem
  52.  
  53.     REDIM _PRESERVE DirList(DirCount)
  54.     REDIM _PRESERVE FileList(FileCount)
  55.  
  56.  
  57.  
* direntry.h (Filesize: 1.21 KB, Downloads: 191)
« Last Edit: January 23, 2021, 03:44:35 pm by bplus »

Offline FilipeEstima

  • Newbie
  • Posts: 63
Re: and another one for your toolbox...
« Reply #83 on: September 11, 2020, 12:36:16 am »
Very interesting, I never knew this _PRESERVE was available. If I only knew it before... Every time I need to DIM an array that may have a different number of files, I have to SHELL _HIDE a DIR command, read the output file and count the number of lines, for only then make a DIM. With REDIM _PRESERVE it's so much more practical.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: and another one for your toolbox...
« Reply #84 on: September 11, 2020, 12:42:29 am »
Very interesting, I never knew this _PRESERVE was available. If I only knew it before... Every time I need to DIM an array that may have a different number of files, I have to SHELL _HIDE a DIR command, read the output file and count the number of lines, for only then make a DIM. With REDIM _PRESERVE it's so much more practical.

yes, _PRESERVE is nice option but remember to start the array with REDIM not DIM or use DYNAMIC keyword somewhere in beginning which I don't do. STATIC is default.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: and another one for your toolbox...
« Reply #85 on: September 12, 2020, 12:47:39 pm »
Ordered Listings of Combinations and Permutations

You may not need it today or tomorrow but someday you might wish you had a listing of combinations you can make with n things:
https://www.qb64.org/forum/index.php?topic=2999.msg122579#msg122579

It is easy to code any word into a letter and then decode letter back as an element of  combination.

In the same vein, here is a copy of way to get listings of permutations:
https://www.qb64.org/forum/index.php?topic=2961.msg122575#msg122575

Thanks to Danilin for getting me to share these goodies with you. :)
« Last Edit: September 12, 2020, 01:22:08 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: and another one for your toolbox...
« Reply #86 on: September 12, 2020, 12:52:48 pm »
Thanks to Steve McNeil for this gem!

Exponential Notation Remover

I don't know how many hours wasted dealing with exponential notation popping up and ruining my display of numbers:
https://www.qb64.org/forum/index.php?topic=2985.msg122404#msg122404

The final return format I settled on is here N2S$ but you might like Steve's in reply above (just don't use his "fix" there because he had it right from the start):
https://www.qb64.org/forum/index.php?topic=2985.msg122585#msg122585

Another lesson from there: be careful which Type variable you use for exponents! you might get unexpected results using default SINGLE type.
« Last Edit: September 12, 2020, 01:22:26 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: and another one for your toolbox...
« Reply #87 on: September 12, 2020, 01:01:53 pm »
In response to CoderVSB12 nascent conception of New Game, I spontaneously came up with this:

Turning a Loaded Image Into a Sprite When _CLEARCOLOR Is Not Enough
by removing dark background; can be done just as easy with light background.

https://www.qb64.org/forum/index.php?topic=3007.msg122645#msg122645

and better 3D effect with same image:
https://www.qb64.org/forum/index.php?topic=3009.msg122648#msg122648


Removing light background for dark object in foreground, this case a shark fin:
https://www.qb64.org/forum/index.php?topic=3307.msg125977#msg125977
« Last Edit: December 03, 2020, 10:18:16 am by bplus »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • Steve’s QB64 Archive Forum
Re: and another one for your toolbox...
« Reply #88 on: December 03, 2020, 10:07:40 am »
A little function which probably doesn't need a whole topic, but which might be useful for someone's tool box -- GetKeyName:

Code: QB64: [Select]
  1.     k = _KEYHIT
  2.     IF k > 0 THEN PRINT GetKeyName(k)
  3.     _LIMIT 30
  4.  
  5. FUNCTION GetKeyName$ (code)
  6.     SELECT CASE code
  7.         CASE 8: GetKeyName$ = "BACK SPACE"
  8.         CASE 9: GetKeyName$ = "TAB"
  9.         CASE 13: GetKeyName$ = "ENTER"
  10.         CASE 27: GetKeyName$ = "ESC"
  11.         CASE 32: GetKeyName$ = "SPACE"
  12.         CASE 33 TO 255: GetKeyName$ = CHR$(code)
  13.         CASE 15104: GetKeyName$ = "F1"
  14.         CASE 15360: GetKeyName$ = "F2"
  15.         CASE 15616: GetKeyName$ = "F3"
  16.         CASE 15872: GetKeyName$ = "F4"
  17.         CASE 16128: GetKeyName$ = "F5"
  18.         CASE 16384: GetKeyName$ = "F6"
  19.         CASE 16640: GetKeyName$ = "F7"
  20.         CASE 16896: GetKeyName$ = "F8"
  21.         CASE 17152: GetKeyName$ = "F9"
  22.         CASE 17408: GetKeyName$ = "F10"
  23.         CASE 34048: GetKeyName$ = "F11"
  24.         CASE 34304: GetKeyName$ = "F12"
  25.         CASE 18432: GetKeyName$ = "UP ARROW"
  26.         CASE 19200: GetKeyName$ = "LEFT ARROW"
  27.         CASE 19712: GetKeyName$ = "RIGHT ARROW"
  28.         CASE 20480: GetKeyName$ = "DOWN ARROW"
  29.  
  30.         CASE 18176: GetKeyName$ = "HOME"
  31.         CASE 18688: GetKeyName$ = "PG UP"
  32.         CASE 20224: GetKeyName$ = "END"
  33.         CASE 20736: GetKeyName$ = "PG DOWN"
  34.         CASE 20992: GetKeyName$ = "INS"
  35.         CASE 21248: GetKeyName$ = "DEL"
  36.  
  37.         CASE 100019: GetKeyName$ = "PAUSE"
  38.         CASE 100300: GetKeyName$ = "NUM LOCK"
  39.         CASE 100301: GetKeyName$ = "CAPS LOCK"
  40.         CASE 100302: GetKeyName$ = "SCROLL LOCK"
  41.         CASE 100303: GetKeyName$ = "R SHIFT"
  42.         CASE 100304: GetKeyName$ = "L SHIFT"
  43.         CASE 100305: GetKeyName$ = "R CTRL"
  44.         CASE 100306: GetKeyName$ = "L CTRL"
  45.         CASE 100307: GetKeyName$ = "R ALT"
  46.         CASE 100308: GetKeyName$ = "L ALT"
  47.         CASE 100309: GetKeyName$ = "L APPLE"
  48.         CASE 100310: GetKeyName$ = "R APPLE"
  49.         CASE 100311: GetKeyName$ = "R WIN"
  50.         CASE 100312: GetKeyName$ = "L WIN"
  51.         CASE 100316: GetKeyName$ = "SYSTEM"
  52.         CASE 100319: GetKeyName$ = "MENU"
  53.     END SELECT
  54.  

Send it a code, get a name of what key it represents.  Good for formatting and display purposes, if you ever need to allow the user to choose their own keys for whatever reason. 

For example: 

Press <ANY KEY> to Jump:

(user presses a key)

Jump key is now: 100319

Now that doesn't make any dang sense to an user!  But, with the above, you get, instead:

Press <ANY KEY> to Jump:

(user presses a key)

Jump key is now: MENU


Oooooohhhhh!  The MENU keys makes my little dude jump now!  YAAAYYY!  That makes sense!  :D
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: and another one for your toolbox...
« Reply #89 on: December 03, 2020, 10:19:39 am »
@SMcNeill

What is the Menu or Jump Key?

Is it MS Windows Logo pictured key?

Update: Nope, it's not the airplane either dang it! Lost my Internet connection :P Ha! There are keys I never mess with on my keyboard ;-))
« Last Edit: December 03, 2020, 10:25:13 am by bplus »