08-27-2023, 11:51 PM
(This post was last modified: 08-28-2023, 12:08 AM by grymmjack.
Edit Reason: Fixed and over-analyzed some more. lol
)
(08-27-2023, 11:16 PM)bplus Wrote:AHA! Perfect example. Let me try to explain what I understand in my own words to make sure I grok this.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
- 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 weSTEP(w,h)
?
- L16 - The reason we use
-1
inCOLS * scale% -1
andROWS * scale% - 1
is because in the first iteration of the loop withi%
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 thedx1%
on line11
? Same reason, to prevent the offset? Since that would evaluate tox% + (1-1)
ORx% + 0 * (COLS + spacing%) * scale%
which means in the first pass through the loop thex
position is also not offset indx1%
either, so!STEP(-1)
thing is to make it consistent for the width and height -- buty
is-1
inSTEP(-1)
for height, butdy1%
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
-1there. Ah! because in the loop we aren't offsetting
yfor each pass! the characters are adjacent on the
xand 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 * 3in loop iteration 1
dx1% = 0
simplify simulate
i% + 1to assert .. so pass 8:
If:
x% = 0 : COLS = 9 : spacing% = 2 : scale% = 3
dx1% = 0 + (1 * 11) * 3
simplify simulate
i% + 1to assert .. so pass 9:
If:
x% = 0 : COLS = 9 : spacing% = 2 : scale% = 3
dx1% = 0 + (11) * 3
simplify simulate
i% + 1to assert .. so pass 10:
If:
x% = 0 : COLS = 9 : spacing% = 2 : scale% = 3
dx1% = 0 + 11 * 3
simplify simulate
i% + 1to assert .. so pass 11:
If:
x% = 0 : COLS = 9 : spacing% = 2 : scale% = 3
dx1% = 0 + (11 * 3)
simplify simulate
i% + 1to assert .. so pass 12:
If:
x% = 0 : COLS = 9 : spacing% = 2 : scale% = 3
dx1% = 0 + (33)
simplify simulate
i% + 1to assert .. so pass 13:
If:
x% = 0 : COLS = 9 : spacing% = 2 : scale% = 3
dx1% = 0 + 33in loop iteration 2
dx1% = 33
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