(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`
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