12-16-2022, 05:49 PM
(12-16-2022, 04:44 PM)mnrvovrfc Wrote: That's in the spirit of the holiday season!
I was going to change it so it drew a candy cane of text and changed from white to red and green.
I was going to propose "POINT()" but that's unreliable. This program should be studied carefully by beginners before they have anything to do with the "_MEM" functions.
Here's the main thing people need to learn to do with _MEM:
Code: (Select All)
For y = y1 * _Width * 4 To y2 * _Width * 4 Step _Width
For x = x1 * 4 To x2 * 4 Step 4
Take the math OUT of the processing loop!! Most of the time, you see people with something such as:
FOR y = y1 TO y2
FOR x = x1 TO x2
IF _MEMGET(m, m.offset + y * 4 * _WIDTH + x * 4, _UNSIGNED LONG) = OldColor THEN _MEMPUT m, m.offst + 4 * _WIDTH + x * 4, NewColor
...
And that's a LOT of math to process inside that loop, which ends up making the mem routines get to the point where they're barely better than POINT and PSET with a plain x/y value.
If you notice, my whole math formula is a simple: o = m.OFFSET + y + x
That's a LOT less calculations than my previous example up there -- and it's going to be done over and over and over inside that loop!