@@ -20,6 +20,7 @@ You should have received a copy of the GNU General Public License
2020 * 2024-12-12 New routines to draw pixels dot by dot
2121 * 2024-12-18 Shape from script
2222 * 2025-04-08 add special function
23+ * 2025-06-07 fill specialCodexxx variables
2324*/
2425
2526using System ;
@@ -42,10 +43,10 @@ public partial class GCodeFromImage
4243 private static double pixelArtPenRadius = 0.2 ;
4344 private static bool pixelArtFill = false ;
4445
45- private static string specialCodeBefore = "" ;
46- private static string specialCodeValue1 = "" ;
47- private static string specialCodeValue2 = "" ;
48- private static string specialCodeAfter = "" ;
46+ private static string specialCodeBefore = "G90 G1 Z1 F1000 " ;
47+ private static string specialCodeValue1 = "G91 A " ;
48+ private static string specialCodeValue2 = "F10000 " ;
49+ private static string specialCodeAfter = "G90 G0 Z5 " ;
4950
5051
5152 private static StringBuilder pixelArtShapeScript = new StringBuilder ( ) ;
@@ -61,11 +62,13 @@ private void ConvertColorMapPixelArt()
6162 string pixelArtSource = "S" ;
6263 if ( RbStartGrayZ . Checked )
6364 pixelArtSource = "Z" ;
64- if ( RbStartGraySpecial . Checked )
65+ specialCodeValue1 = tBCodeValue1 . Text ;
66+ if ( RbStartGraySpecial . Checked && ( specialCodeValue1 . Length > 1 ) )
67+ {
6568 pixelArtSource = specialCodeValue1 . Substring ( specialCodeValue1 . Length - 1 ) ;
66-
69+ }
6770 Logger . Info ( "▼▼ ConvertColorMapPixelArt px-dist:{0} colorMapCount:{1}" , pixelArtDistance , colorMap . Count ) ;
68- Gcode . Comment ( finalString , string . Format ( "{0} Source=\" {1}\" />" , XmlMarker . PixelArt , pixelArtSource ) ) ;
71+ Gcode . Comment ( finalString , string . Format ( "{0} Source=\" {1}\" Dot-count= \" {2} \" />" , XmlMarker . PixelArt , pixelArtSource , ( resultImage . Width * resultImage . Height ) ) ) ;
6972 int toolNr , skipTooNr = 1 ;
7073 short key ;
7174 PointF tmpP ;
@@ -411,7 +414,7 @@ private long CreatePixelPatternHeight(int width, int height, bool useZnotS, bool
411414 drawType = 1 ;
412415
413416 int dotLineCount = 4 ;
414- if ( ! special )
417+ if ( ! special )
415418 {
416419 if ( useZnotS ) { dotLineCount = 3 ; }
417420 else { dotLineCount = 5 ; }
@@ -448,14 +451,14 @@ void ApplyPixelValueHeight(int xx, int yy)
448451 return ;
449452 }
450453 cncCoordLastZ = cncCoordZ = Gcode . GcodeZUp ;
451-
452- // move to xy position
454+
455+ // move to xy position
453456 if ( drawShape )
454457 finalString . AppendFormat ( "G{0} X{1} Y{2}\r \n " , Gcode . FrmtCode ( 0 ) , Gcode . FrmtNum ( pixelPosX - adaptRadius ) , Gcode . FrmtNum ( pixelPosY ) ) ;
455458 else
456459 finalString . AppendFormat ( "G{0} X{1} Y{2}\r \n " , Gcode . FrmtCode ( 0 ) , Gcode . FrmtNum ( pixelPosX ) , Gcode . FrmtNum ( pixelPosY ) ) ;
457460
458- // apply brightnes as Gcode value as Z, S or special
461+ // apply brightnes as Gcode value as Z, S or special
459462 SetPixelHeight ( brightnes , useZnotS , special , false ) ;
460463
461464 if ( ! special )
@@ -494,13 +497,13 @@ private void SetPixelHeight(int bright, bool useZnotS, bool special, bool relati
494497 { // apply code for down and up
495498 float sval = ( float ) nUDSpecialTop . Value - height * ( float ) ( nUDSpecialTop . Value - nUDSpecialBottom . Value ) / 255 ;
496499 if ( specialCodeBefore != "" )
497- {
498- finalString . AppendFormat ( "{0}\r \n " , specialCodeBefore ) ;
499- finalString . AppendFormat ( "{0}{1}{2} (PD DOT)\r \n " , specialCodeValue1 , Gcode . FrmtNum ( sval ) , specialCodeValue2 ) ;
500- }
501- else
502- finalString . AppendFormat ( "{0}{1}{2} (PD DOT)\r \n " , specialCodeValue1 , Gcode . FrmtNum ( sval ) , specialCodeValue2 ) ;
503-
500+ {
501+ finalString . AppendFormat ( "{0}\r \n " , specialCodeBefore ) ;
502+ finalString . AppendFormat ( "{0}{1}{2} (PD DOT)\r \n " , specialCodeValue1 , Gcode . FrmtNum ( sval ) , specialCodeValue2 ) ;
503+ }
504+ else
505+ finalString . AppendFormat ( "{0}{1}{2} (PD DOT)\r \n " , specialCodeValue1 , Gcode . FrmtNum ( sval ) , specialCodeValue2 ) ;
506+
504507 finalString . AppendFormat ( "{0} (PU)\r \n " , specialCodeAfter ) ;
505508 }
506509 else
@@ -536,7 +539,6 @@ private void UpdateSizeControls()
536539 LbLSizeXCode . Text = w . ToString ( ) ;
537540 LbLSizeYCode . Text = h . ToString ( ) ;
538541 }
539-
540542 }
541543
542544 class PixelBox : PictureBox
0 commit comments