06-27-2023, 11:44 PM
SOLVED again , now saving the feature of drawing only foregorund colors of the image
please play the code and comments let understand where and why the issue arises
Short version for who has no time to read code and code comments:
Commands of DRAW draw from the starting point of the screen towards the direction selected of N times (if S4 each n = 1 pixel)
So if you type DRAW "s4c15 r1" it draws 5 pixels to right 1 of starting position + 4 of movement towards right edge of image/screen.
As you understand you are not able to draw a single pixel until you do not use M command that uses absolute/relative cohordinates and let move also 1 pixel towards the choosen direction.
please play the code and comments let understand where and why the issue arises
Code: (Select All)
Rem 27 06 2023 / 28 06 2023 SOLVED saving the feature of drawing only foreground of image
Rem but James D Jarvis wants to draw only foreground of image, NO background like for a vector image
'***************************************************************
'scanning a section of the screen converting and writing it with DRAW
'why doesn't it work?
'***************************************************************
Screen _NewImage(480, 400, 256)
$Console
_Console Off
Randomize Timer
Cls
_PrintMode _KeepBackground
_PrintString (0, 0), "AB"
'Line (1, 1)-(1, 14), 15
_Delay 0.5
msg$ = "<-- scanning this as a sample image"
_PrintString (40, 0), msg$
x = 0: y = 0
dd$ = ""
wid = 16
ht = 16
Draw "s4"
dd$ = Scan_draw$(x, y, ht, wid)
_Delay 1
Locate 4, 4
Line (40, 0)-(40 + Len(msg$) * 8, 15), 0, BF
msg$ = "ready (press any key)"
_PrintString (0, 100), msg$
Sleep
Line (0, 100)-(Len(msg$) * 8, 115), 0, BF
Locate 4, 4
Print "Draw Scanned image, Why isn't it drawing correctly?"
Print "Is the problem in the scanning routine or in how draw functions?"
Print "it is a problem arising from the translation of scanned data into Draw commands!"
putdraw 50, 0, dd$
putdraw 1, 20, dd$
drawto_console dd$
Input alldone$
End
'***************************************************************
' subroutines for making use of draw strings in 256 color mode.
' color 0 is treated as transpaernt
Sub putdraw (xx, yy, dd$)
Draw "bm" + Str$(xx) + "," + Str$(yy) + dd$
End Sub
Sub drawto_console (dd$)
'program must have console output activated earlier
'prints the string in a clean console window so it may be copied and pasted on any system with console support
sd& = _Dest
_Console On
_Dest _Console
Cls
Print dd$
Print
Print "Copy and Paste the above text for future use in DRAW commands"
_Dest sd&
End Sub
Function Scan_draw$ (sx, sy, ht, wid)
'scan a screen area starting at point sx,sy and saving it to the string DD$ for use in later draw commands
'simply scans each row and tracks color changes
For y = 0 To ht - 1
x = 0
Do
klr = Point(sx + x, sy + y) 'here cohordinates are relative to topleft starter point sx,sy
n = -1 ' why do you need to start from -1? So you are including also n = 0 that is the same point valutated here above
Do
n = n + 1
nklr = Point(x + n, y) 'here cohordinates are absolute starting from topleft starter point 0,0
Loop Until nklr <> klr Or x + n >= wid
'n, going out of loop, is bringing the value of the next color or got right edge
If klr = 0 Then
dd$ = dd$ + "br" + _Trim$(Str$(n)) ' it moves blind the graphic cursor towards the right edge with step of 2 pixels ata a time
Else
' R draws the starting point + the n pixels, so to solve we go back 1 pixel, then we draw n-1 pixels and then we go forwards 2 pixels
dd$ = dd$ + "bm-1,+0" + "C" + _Trim$(Str$(klr)) + " " + "R" + _Trim$(Str$(n - 1)) + "bm+2,+0" ' it draws a line to right from the starter point
End If
x = x + n
Loop Until x >= wid
dd$ = dd$ + "bd1bl" + Str$(wid) ' here it moves the graphic cursor to the first point of the next row
Next y
Scan_draw$ = dd$
End Function
Short version for who has no time to read code and code comments:
Commands of DRAW draw from the starting point of the screen towards the direction selected of N times (if S4 each n = 1 pixel)
So if you type DRAW "s4c15 r1" it draws 5 pixels to right 1 of starting position + 4 of movement towards right edge of image/screen.
As you understand you are not able to draw a single pixel until you do not use M command that uses absolute/relative cohordinates and let move also 1 pixel towards the choosen direction.