Hello again all,
I have been working some more this weekend with creating gcode on the BASIC Engine. The program loads a .pcx image onto the screen and then, starting at the center of the image, it draws an Archimedes spiral to visit all (most) of the pixels in the image, testing each one to see if it's white. If it is, it makes the pixel red and drops the pen. If the next pixel is white too the pen stays down and tells the plotter to travel to the next point. It proceeds like this, lifting or lowering the pen if needed, and moving to the next point on the spiral. There are a few things I need to tweak still, sometimes the pen lifts in a seemingly solid area only to lower again, I'm sure the logic can be optimized further but it adds some interest to the final image as well. I am still learning - please feel free to comment or offer input.
Below is the code, the input image, and the plotted gcode created by the BASIC Engine. The gcode file produced by this program is slightly over 1 megabyte in size!
I figured out what was causing the 'extra' penup happening in solid areas. When the program tests a pixel it checks if it's white (255). If it is it makes it red (227) and continues on it's merry way. That's great but the issue is that on it's next coil around the spiral, there is a chance it could need to test the same pixel again. This happens because even though the coils have a radius 'one pixel' apart, a pixel is larger than 'one pixel wide' if you're measuring from corner to corner or any angle other than normal. I had to change the code to test for both the red and white pixel conditions. the last image attached below is a photo of the new output.
10 CLS 'SPIRALGCODE.BAS
12 OPEN "SPIRAL.GCODE" FOR OUTPUT AS #1
13 PRINT #1,"G21"
14 PRINT #1,"G90"
15 PRINT #1,"G54"
19 CALL PENUP
20 RADIUS=1'INITIAL RADIUS (DISTANCE TO CENTER)
30 DIV=1'DISTANCE BETWEEN POINTS ON SPIRAL
40 STARTX=INT(460/2)-0.5'CENTER SCREEN ON X
50 STARTY=INT(224/2)-0.5'AND ON Y
60 LOAD PCX "BE_LOGO.PCX" TO (STARTX-98),(STARTY-100) SIZE 200,200'SHIFTED ON SCREEN TO CENTER IMAGE ON SPIRAL
70 CIRCLE STARTX+2,STARTY,102,255,-1'DRAW A CIRCLE ON SCREEN AS A BORDER SHOWING OUR MAX EXTENTS
90 STARTX=STARTX+RADIUS'STARTING POINT
91 X1=STARTX:Y1=STARTY:CALL MOVE(X1,Y1)'MOVE TO START POINT OF SPIRAL
100 PIX=POINT(X1,Y1)'READ PIXEL COLOR INTO PIX VARIABLE
110 IF PIX=255 THEN PSET X1,Y1,227'IF PIXEL IS WHITE THEN TURN IT RED
120 IF PIX=255 THEN CALL PENDOWN'AND PUT THE PEN DOWN
130 CIRC=2*PI*RADIUS'GET THE CIRCUMFRENCE OF CURRENT RADIUS
140 DIST=CIRC/DIV'DIVIDE THE CIRCUMFRENCE BY AMOUNT OF DIVISIONS BETWEEN POINTS
150 DEG=360/DIST'CALCULATE DEGREES BETWEEN POINTS
160 A=A+DEG*0.01745'CONVERT DEGREES TO RADIANS
185 X1=STARTX+X:Y1=STARTY+Y'MOVE TO NEXT POINT OF SPIRAL
190 PIX=POINT(X1,Y1)'READ PIXEL COLOR INTO PIX VARIABLE
200 IF PIX=255 THEN PSET X1,Y1,227'IF PIXEL IS WHITE THEN TURN IT RED
210 IF PIX=255 AND PEN=0 THEN CALL PENDOWN
211 IF PIX<>255 AND PEN=1 THEN CALL PENUP
215 CALL MOVE(X1,Y1)
220 RADIUS=RADIUS+DEG/360'INCREMENT THE RADIUS FOR THE NEXT LOOP. THIS CONTROLS THE SPACING BETWEEN COILS OF SPIRAL
230 L=L+DIV'FOR A TOTAL LENGTH OF SPIRAL, PRINTED AT END OF PROGRAM
240 IF RADIUS<100 GOTO 130
250 LOCATE 0,1:PRINT "RADIUS=";RADIUS'1 PIXEL=1 MM. SCALE THIS BASED OF FILAL PLOT SIZE FOR AN ACCURATE CALCULATION. I.E. RADIUS/2
260 LOCATE 0,2:PRINT "LENGTH=";L'SAME AS ABOVE
265 IF PEN=1 THEN CALL PENUP
270 CLOSE #1
300 PROC MOVE(X1,Y1)
310 PRINT #1,"G1 X";(X1/2)-50;" Y-";Y1/2;" F";FEED 'SCALE DOWN GCODE OUTPUT TO FIT WITHIN PLOTTER LIMITS
400 PROC PENDOWN
410 PRINT #1,"G1 Z0 F";FEED
500 PROC PENUP
510 PRINT #1,"G1 Z2 F";FEED