Search found 80 matches

by matt7
Mon May 10, 2021 11:46 am
Forum: Other topics
Topic: Selective area load of Images
Replies: 3
Views: 159

Re: Selective area load of Images

As a function that extracts an area of an image from x1,y1 to x2,y2 and puts it at destx,desty on the screen: img$ = "Examples/Graphics/images/firtree.png" GRAPHICS CROP_IMG(img$, 200,200, 230,230, 100,100) DEF CROP_IMG (name$, x1,y1, x2,y2, destx,desty) spr$ = UNIQUE_STR$() SPRITE spr$ BEGIN ABS(x2...
by matt7
Mon May 10, 2021 11:34 am
Forum: Other topics
Topic: Selective area load of Images
Replies: 3
Views: 159

Re: Selective area load of Images

What about starting a new sprite with the desired final size and then drawing the image to the sprite using negative coordinates to essentially crop the image. Then you can move the sprite where you want and show it or stamp it to the main graphics window. Here is how I can get a 30x30 portion put o...
by matt7
Sun Apr 11, 2021 6:05 pm
Forum: Other topics
Topic: Reading nth line in a file
Replies: 4
Views: 257

Re: Reading nth line in a file

You're welcome. However, after some testing I determined that using a bunch of READLINE calls is by far the fastest method. Here is my test file that times three different FILE_SETLINE functions: DEF FILE_SETLINE_RD (file$, line) FILE file$ SETPOS 0 IF line = 0 THEN RETURN FILE file$ READDIM bytes, ...
by matt7
Thu Apr 08, 2021 6:29 pm
Forum: Other topics
Topic: Reading nth line in a file
Replies: 4
Views: 257

Re: Reading nth line in a file

Follow-up thought: If memory is an issue or you just want a safer way to do this, modify the above function to use FILE N$ READDIM M, N, K in a loop, reading K bytes at a time. Then you can keep overwriting the bytes() variable as you count newline characters, keeping track of the total running file...
by matt7
Thu Apr 08, 2021 6:10 pm
Forum: Other topics
Topic: Reading nth line in a file
Replies: 4
Views: 257

Re: Reading nth line in a file

I recently tried to figure out how to do this but ended up settling for doing a bunch of READLINEs until I reached the line I wanted. However, your post got me thinking about the problem again and I realized that if you know the file size at the line you want, you can use FILE N$ SETPOS X. I briefly...
by matt7
Thu Mar 18, 2021 7:42 pm
Forum: Other topics
Topic: New to SB and File handling
Replies: 2
Views: 343

Re: New to SB and File handling

What is the expected range of values for your numeric variables? For example, if they are limited to the range 0-255 then FILE WRITE and FILE READ can be used, which write and read a single byte. But other numeric values will require some additional code to preserve precision. The below example uses...
by matt7
Wed Mar 03, 2021 3:57 pm
Forum: Libraries
Topic: Recursively Listing Files and Folders
Replies: 2
Views: 329

Re: Recursively Listing Files and Folders

Just updated the library code with some bug fixes.
by matt7
Sat Feb 27, 2021 6:05 am
Forum: Libraries
Topic: Recursively Listing Files and Folders
Replies: 2
Views: 329

Recursively Listing Files and Folders

Below is a standalone library for creating a list of either all files or all folders recursively from a starting directory. The two main functions are: DIRS_LIST_RECURSIVE(dir$) FILES_LIST_RECURSIVE(dir$) Here is a usage example: {{/lib/files/list_recursive}} ' whatever you name it and wherever you ...
by matt7
Sat Jan 16, 2021 3:29 pm
Forum: Other topics
Topic: Format string with PRINT command
Replies: 4
Views: 406

Re: Format string with PRINT command

Here's another option that builds the format string from right to left and then applies it.

Code: Select all

def fmt$(a)
f$="###"
m=1000
while abs(a)>=m
f$="###,"&f$
m*=1000
endwhile
return str$(a,f$)
enddef
Add a trim$() to the return line or whenever you call fmt$ to remove leading spaces.
by matt7
Thu Jan 07, 2021 9:46 pm
Forum: Other topics
Topic: New version has wrong number?
Replies: 7
Views: 948

Re: New version has wrong number?

Here is a thread discussing some different ways to achieve select-case functionality:
https://www.kibernetik.pro/forum/viewto ... =26&t=2387