DAY 009:_PutImage
#40
(08-27-2023, 11:16 PM)bplus Wrote:
Quote:Could you possibly show me an example where we are using the absolute position value for the 2nd (x, y) and then how step would fix it?

From our very recent code rewrite for FONT.print
Code: (Select All)
Sub F0NT.print (s$, f() As F0NT, x%, y%, scale%, spacing%)
  Dim As Integer i, l, dx1, dy1, dx2, dy2, orig_x
  Dim c As String
  Dim g As Long
  l% = Len(s$)
  ' PSet (x%, y%)
  For i% = 1 To l%
    c$ = Mid$(s$, i%, 1)
    'g& =
    '_Source g&
    dx1% = x% + (i% - 1) * (COLS + spacing%) * scale%
    dy1% = y%
    'dx2% = (COLS * scale%) + dx1%  ' << STEP allows us to leave off the dx1% from which we STEP
    'dy2% = (ROWS * scale%) + dy1%  ' << STEP allows us to leave off the dx2% from which we STEP
    '_PutImage (dx1%, dy1%)-(dx2%, dy2%), F0NT.get_glyph(c$, f())
    _PutImage (dx1%, dy1%)-Step(COLS * scale% - 1, ROWS * scale% - 1), F0NT.get_glyph(c$, f())
  Next i%
End Sub
AHA! Perfect example. Let me try to explain what I understand in my own words to make sure I grok this.
  • L13 - We don't need to calc
    dx2%
    because with STEP that becomes relative and auto-mathic to be: x:
    dx1% + COLS * scale% - 1)
    ?
  • L14 - We don't need to calc
    dy2%
    because with STEP that becomes relative and auto-mathic to be: y:
    dy1% + ROWS * scale% - 1)
    ?
  • So! STEP uses the previous x and y in the first pair of
    (x,y)
    in
    _PUTIMAGE
    and we can simply provide width and height if we
    STEP(w,h)
    ?
  • L16 - The reason we use
    -1
    in
    COLS * scale% -1
    and
    ROWS * scale% - 1
    is because in the first iteration of the loop with
    i%
    being 1, if we did not subtract one, it would offset them, and so the passed in desired positions would be actually offset for the first character.
  • L16 - Why are we doing a
    i% - 1
    in the
    dx1%
    on line
    11
    ? Same reason, to prevent the offset? Since that would evaluate to
    x% + (1-1)
    OR
    x% + 0 * (COLS + spacing%) * scale%
    which means in the first pass through the loop the
    x
    position is also not offset in
    dx1%
    either, so!
    STEP(-1)
    thing is to make it consistent for the width and height -- but
    y
    is
    -1
    in
    STEP(-1)
    for height, but
    dy1%
    has no offset - why?

Thanks!

I think I understand
STEP
. It makes the second set of parenthesis args relative to the first set of parenthesis arg. So first set of parens =
(dx1, dy1)
. Second set is implicit dx1+ and dy1+. Right?

Can you confirm if I have the right of it for -1 for x and y on both lines 11 and 16? but curious why line 12 has no
-1
there. Ah! because in the loop we aren't offsetting
y
for each pass! the characters are adjacent on the
x
and SAME on the
y
.

NOW I get it.

ALSO something happened when I had to type this out. I realized a thing, might be obvious to others but wasn't to me.

Simplify the math and vars to understand WTF is happening.

If the code has:
dx1% = x% + (i% - 1) * (COLS + spacing%) * scale%

simplify pass 1:
dx1% = x% + (1 - 1) * (COLS + spacing%) * scale%

simplify pass 2:
dx1% = x% + (0) * (COLS + spacing%) * scale%

simplify pass 3:
dx1% = x% + 0 * (COLS + spacing%) * scale%

simplify pass 4:
If:
x% = 0 : COLS = 9 : spacing% = 2 : scale% = 3
dx1% = 0 + 0 * (9 + 2) * 3

simplify pass 5:
If:
x% = 0 : COLS = 9 : spacing% = 2 : scale% = 3
dx1% = 0 + 0 * (11) * 3

simplify pass 6:
If:
x% = 0 : COLS = 9 : spacing% = 2 : scale% = 3
dx1% = 0 + 0 * 11 * 3

simplify pass 7:
If:
x% = 0 : COLS = 9 : spacing% = 2 : scale% = 3
dx1% = 0 + 0 * 11 * 3
in loop iteration 1
dx1% = 0

simplify simulate
i% + 1
to assert .. so pass 8:
If:
x% = 0 : COLS = 9 : spacing% = 2 : scale% = 3
dx1% = 0 + (1 * 11) * 3

simplify simulate
i% + 1
to assert .. so pass 9:
If:
x% = 0 : COLS = 9 : spacing% = 2 : scale% = 3
dx1% = 0 + (11) * 3

simplify simulate
i% + 1
to assert .. so pass 10:
If:
x% = 0 : COLS = 9 : spacing% = 2 : scale% = 3
dx1% = 0 + 11 * 3

simplify simulate
i% + 1
to assert .. so pass 11:
If:
x% = 0 : COLS = 9 : spacing% = 2 : scale% = 3
dx1% = 0 + (11 * 3)

simplify simulate
i% + 1
to assert .. so pass 12:
If:
x% = 0 : COLS = 9 : spacing% = 2 : scale% = 3
dx1% = 0 + (33)

simplify simulate
i% + 1
to assert .. so pass 13:
If:
x% = 0 : COLS = 9 : spacing% = 2 : scale% = 3
dx1% = 0 + 33
in loop iteration 2
dx1% = 33

Idea 

I know, we can just watch those variables and debug and step through.. For some reason this didn't occur to me either.

Thanks @bplus Heart
grymmjack (gj!)
GitHubYouTube | Soundcloud | 16colo.rs
Reply


Messages In This Thread
DAY 009:_PutImage - by bplus - 11-15-2022, 12:00 AM
RE: DAY 009:_PutImage - by bplus - 11-15-2022, 12:23 AM
RE: DAY 009:_PutImage - by bplus - 11-15-2022, 12:32 AM
RE: DAY 009:_PutImage - by PhilOfPerth - 11-15-2022, 01:25 AM
RE: DAY 009:_PutImage - by mnrvovrfc - 11-15-2022, 12:38 AM
RE: DAY 009:_PutImage - by james2464 - 11-15-2022, 01:09 AM
RE: DAY 009:_PutImage - by bplus - 11-15-2022, 01:22 AM
RE: DAY 009:_PutImage - by bplus - 11-15-2022, 01:49 AM
RE: DAY 009:_PutImage - by PhilOfPerth - 11-15-2022, 01:58 AM
RE: DAY 009:_PutImage - by bplus - 11-15-2022, 02:19 AM
RE: DAY 009:_PutImage - by SMcNeill - 11-15-2022, 02:33 AM
RE: DAY 009:_PutImage - by bplus - 11-15-2022, 03:18 AM
RE: DAY 009:_PutImage - by Pete - 11-15-2022, 03:25 AM
RE: DAY 009:_PutImage - by grymmjack - 08-27-2023, 10:32 PM
RE: DAY 009:_PutImage - by james2464 - 11-15-2022, 04:20 AM
RE: DAY 009:_PutImage - by SMcNeill - 11-15-2022, 11:23 AM
RE: DAY 009:_PutImage - by james2464 - 11-15-2022, 04:32 PM
RE: DAY 009:_PutImage - by madscijr - 11-15-2022, 03:54 PM
RE: DAY 009:_PutImage - by SMcNeill - 11-15-2022, 04:37 PM
RE: DAY 009:_PutImage - by james2464 - 11-15-2022, 04:43 PM
RE: DAY 009:_PutImage - by Pete - 11-15-2022, 04:43 PM
RE: DAY 009:_PutImage - by bplus - 11-15-2022, 04:52 PM
RE: DAY 009:_PutImage - by grymmjack - 09-02-2023, 02:57 PM
RE: DAY 009:_PutImage - by james2464 - 11-15-2022, 07:19 PM
RE: DAY 009:_PutImage - by SMcNeill - 11-15-2022, 07:33 PM
RE: DAY 009:_PutImage - by james2464 - 11-15-2022, 08:20 PM
RE: DAY 009:_PutImage - by james2464 - 11-15-2022, 08:49 PM
RE: DAY 009:_PutImage - by bplus - 11-15-2022, 11:22 PM
RE: DAY 009:_PutImage - by SMcNeill - 11-15-2022, 11:46 PM
RE: DAY 009:_PutImage - by james2464 - 11-16-2022, 12:10 AM
RE: DAY 009:_PutImage - by SMcNeill - 11-16-2022, 01:00 AM
RE: DAY 009:_PutImage - by james2464 - 11-16-2022, 01:27 AM
RE: DAY 009:_PutImage - by james2464 - 11-16-2022, 03:48 AM
RE: DAY 009:_PutImage - by SMcNeill - 11-16-2022, 03:55 AM
RE: DAY 009:_PutImage - by james2464 - 11-16-2022, 04:01 AM
RE: DAY 009:_PutImage - by grymmjack - 09-02-2023, 02:45 PM
RE: DAY 009:_PutImage - by grymmjack - 09-02-2023, 02:54 PM
RE: DAY 009:_PutImage - by bplus - 11-16-2022, 05:21 AM
RE: DAY 009:_PutImage - by SMcNeill - 11-16-2022, 04:07 AM
RE: DAY 009:_PutImage - by james2464 - 11-16-2022, 04:38 AM
RE: DAY 009:_PutImage - by grymmjack - 08-27-2023, 09:58 PM
RE: DAY 009:_PutImage - by bplus - 08-27-2023, 11:16 PM
RE: DAY 009:_PutImage - by grymmjack - 08-27-2023, 11:51 PM
RE: DAY 009:_PutImage - by grymmjack - 08-28-2023, 12:14 AM
RE: DAY 009:_PutImage - by a740g - 08-28-2023, 07:49 AM
RE: DAY 009:_PutImage - by grymmjack - 08-28-2023, 11:32 AM
RE: DAY 009:_PutImage - by grymmjack - 08-28-2023, 11:51 AM
RE: DAY 009:_PutImage - by bplus - 08-28-2023, 01:33 AM
RE: DAY 009:_PutImage - by bplus - 08-29-2023, 03:21 PM
RE: DAY 009:_PutImage - by grymmjack - 08-29-2023, 10:41 PM
RE: DAY 009:_PutImage - by grymmjack - 09-02-2023, 01:58 PM
RE: DAY 009:_PutImage - by grymmjack - 09-02-2023, 02:36 PM
RE: DAY 009:_PutImage - by grymmjack - 09-02-2023, 02:41 PM
RE: DAY 009:_PutImage - by grymmjack - 09-02-2023, 02:42 PM
RE: DAY 009:_PutImage - by grymmjack - 09-02-2023, 02:45 PM



Users browsing this thread: 28 Guest(s)