2013-02-17 23:52:07 +01:00
|
|
|
/**
|
2015-04-26 13:13:35 +02:00
|
|
|
Polargraph controller
|
|
|
|
Copyright Sandy Noble 2015.
|
|
|
|
|
|
|
|
This file is part of Polargraph Controller.
|
|
|
|
|
|
|
|
Polargraph Controller is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Polargraph Controller is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Polargraph Controller. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
Requires the excellent ControlP5 GUI library available from http://www.sojamo.de/libraries/controlP5/.
|
|
|
|
Requires the excellent Geomerative library available from http://www.ricardmarxer.com/geomerative/.
|
|
|
|
|
|
|
|
This is an application for controlling a polargraph machine, communicating using ASCII command language over a serial link.
|
|
|
|
|
|
|
|
sandy.noble@gmail.com
|
|
|
|
http://www.polargraph.co.uk/
|
|
|
|
https://github.com/euphy/polargraphcontroller
|
|
|
|
*/
|
2013-02-17 23:52:07 +01:00
|
|
|
static final String CMD_CHANGELENGTH = "C01,";
|
|
|
|
static final String CMD_CHANGEPENWIDTH = "C02,";
|
|
|
|
static final String CMD_CHANGEMOTORSPEED = "C03,";
|
|
|
|
static final String CMD_CHANGEMOTORACCEL = "C04,";
|
|
|
|
static final String CMD_DRAWPIXEL = "C05,";
|
|
|
|
static final String CMD_DRAWSCRIBBLEPIXEL = "C06,";
|
|
|
|
static final String CMD_DRAWRECT = "C07,";
|
|
|
|
static final String CMD_CHANGEDRAWINGDIRECTION = "C08,";
|
|
|
|
static final String CMD_SETPOSITION = "C09,";
|
|
|
|
static final String CMD_TESTPATTERN = "C10,";
|
|
|
|
static final String CMD_TESTPENWIDTHSQUARE = "C11,";
|
|
|
|
static final String CMD_TESTPENWIDTHSCRIBBLE = "C12,";
|
|
|
|
static final String CMD_PENDOWN = "C13,";
|
|
|
|
static final String CMD_PENUP = "C14,";
|
|
|
|
static final String CMD_DRAWSAWPIXEL = "C15,";
|
|
|
|
static final String CMD_DRAWROUNDPIXEL = "C16,";
|
|
|
|
static final String CMD_CHANGELENGTHDIRECT = "C17,";
|
|
|
|
static final String CMD_TXIMAGEBLOCK = "C18,";
|
|
|
|
static final String CMD_STARTROVE = "C19,";
|
|
|
|
static final String CMD_STOPROVE = "C20,";
|
|
|
|
static final String CMD_SET_ROVE_AREA = "C21,";
|
|
|
|
static final String CMD_LOADMAGEFILE = "C23,";
|
|
|
|
static final String CMD_CHANGEMACHINESIZE = "C24,";
|
|
|
|
static final String CMD_CHANGEMACHINENAME = "C25,";
|
|
|
|
static final String CMD_REQUESTMACHINESIZE = "C26,";
|
|
|
|
static final String CMD_RESETMACHINE = "C27,";
|
|
|
|
static final String CMD_DRAWDIRECTIONTEST = "C28,";
|
|
|
|
static final String CMD_CHANGEMACHINEMMPERREV = "C29,";
|
|
|
|
static final String CMD_CHANGEMACHINESTEPSPERREV = "C30,";
|
|
|
|
static final String CMD_SETMOTORSPEED = "C31,";
|
|
|
|
static final String CMD_SETMOTORACCEL = "C32,";
|
|
|
|
static final String CMD_MACHINE_MODE_STORE_COMMANDS = "C33,";
|
|
|
|
static final String CMD_MACHINE_MODE_EXEC_FROM_STORE = "C34,";
|
|
|
|
static final String CMD_MACHINE_MODE_LIVE = "C35,";
|
|
|
|
static final String CMD_RANDOM_DRAW = "C36,";
|
|
|
|
static final String CMD_SETMACHINESTEPMULTIPLIER = "C37,";
|
|
|
|
static final String CMD_START_TEXT = "C38,";
|
|
|
|
static final String CMD_DRAW_SPRITE = "C39,";
|
|
|
|
static final String CMD_CHANGELENGTH_RELATIVE = "C40,";
|
|
|
|
static final String CMD_SWIRLING = "C41,";
|
|
|
|
static final String CMD_DRAW_RANDOM_SPRITE = "C42,";
|
|
|
|
static final String CMD_DRAW_NORWEGIAN = "C43,";
|
|
|
|
static final String CMD_DRAW_NORWEGIAN_OUTLINE = "C44,";
|
2013-03-22 23:35:52 +01:00
|
|
|
static final String CMD_SETPENLIFTRANGE = "C45,";
|
2013-04-28 11:47:01 +02:00
|
|
|
static final String CMD_SELECT_ROVE_SOURCE_IMAGE = "C46";
|
|
|
|
static final String CMD_RENDER_ROVE = "C47";
|
2013-02-17 23:52:07 +01:00
|
|
|
|
2015-03-18 18:33:13 +01:00
|
|
|
static final String CMD_ACTIVATE_MACHINE_BUTTON = "C49";
|
|
|
|
static final String CMD_DEACTIVATE_MACHINE_BUTTON = "C50";
|
|
|
|
|
2013-04-20 01:41:27 +02:00
|
|
|
static final int PATH_SORT_NONE = 0;
|
|
|
|
static final int PATH_SORT_MOST_POINTS_FIRST = 1;
|
|
|
|
static final int PATH_SORT_GREATEST_AREA_FIRST = 2;
|
|
|
|
static final int PATH_SORT_CENTRE_FIRST = 3;
|
|
|
|
|
2013-04-04 01:30:34 +02:00
|
|
|
private PVector mouseVector = new PVector(0, 0);
|
2013-02-17 23:52:07 +01:00
|
|
|
|
|
|
|
Comparator xAscending = new Comparator()
|
|
|
|
{
|
|
|
|
public int compare(Object p1, Object p2)
|
|
|
|
{
|
|
|
|
PVector a = (PVector) p1;
|
|
|
|
PVector b = (PVector) p2;
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-02-17 23:52:07 +01:00
|
|
|
int xValue = new Float(a.x).compareTo(b.x);
|
|
|
|
return xValue;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Comparator yAscending = new Comparator()
|
|
|
|
{
|
|
|
|
public int compare(Object p1, Object p2)
|
|
|
|
{
|
|
|
|
PVector a = (PVector) p1;
|
|
|
|
PVector b = (PVector) p2;
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-02-17 23:52:07 +01:00
|
|
|
int yValue = new Float(a.y).compareTo(b.y);
|
|
|
|
return yValue;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void sendResetMachine()
|
|
|
|
{
|
|
|
|
String command = CMD_RESETMACHINE + "END";
|
|
|
|
addToCommandQueue(command);
|
|
|
|
}
|
|
|
|
void sendRequestMachineSize()
|
|
|
|
{
|
|
|
|
String command = CMD_REQUESTMACHINESIZE + "END";
|
|
|
|
addToCommandQueue(command);
|
|
|
|
}
|
|
|
|
void sendMachineSpec()
|
|
|
|
{
|
|
|
|
// ask for input to get the new machine size
|
2017-06-25 22:50:44 +02:00
|
|
|
String command = CMD_CHANGEMACHINESIZE+getDisplayMachine().inMM(getDisplayMachine().getWidth())+","+getDisplayMachine().inMM(getDisplayMachine().getHeight())+",END";
|
2013-02-17 23:52:07 +01:00
|
|
|
addToCommandQueue(command);
|
|
|
|
command = CMD_CHANGEMACHINEMMPERREV+int(getDisplayMachine().getMMPerRev())+",END";
|
|
|
|
addToCommandQueue(command);
|
|
|
|
command = CMD_CHANGEMACHINESTEPSPERREV+int(getDisplayMachine().getStepsPerRev())+",END";
|
|
|
|
addToCommandQueue(command);
|
|
|
|
command = CMD_SETMACHINESTEPMULTIPLIER+machineStepMultiplier+",END";
|
|
|
|
addToCommandQueue(command);
|
2013-04-17 00:14:46 +02:00
|
|
|
command = CMD_SETPENLIFTRANGE+penLiftDownPosition+","+penLiftUpPosition+",1,END";
|
2013-03-24 01:13:00 +01:00
|
|
|
addToCommandQueue(command);
|
2013-04-17 00:14:46 +02:00
|
|
|
|
|
|
|
// speeds
|
|
|
|
NumberFormat nf = NumberFormat.getNumberInstance(Locale.UK);
|
|
|
|
DecimalFormat df = (DecimalFormat)nf;
|
|
|
|
df.applyPattern("###.##");
|
|
|
|
addToCommandQueue(CMD_SETMOTORSPEED+df.format(currentMachineMaxSpeed)+",1,END");
|
|
|
|
addToCommandQueue(CMD_SETMOTORACCEL+df.format(currentMachineAccel)+",1,END");
|
2013-02-17 23:52:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public PVector getMouseVector()
|
|
|
|
{
|
|
|
|
if (mouseVector == null)
|
|
|
|
{
|
2013-04-04 01:30:34 +02:00
|
|
|
mouseVector = new PVector(0, 0);
|
2013-02-17 23:52:07 +01:00
|
|
|
}
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-02-17 23:52:07 +01:00
|
|
|
mouseVector.x = mouseX;
|
|
|
|
mouseVector.y = mouseY;
|
|
|
|
return mouseVector;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Uses the mouse position unless one is specified
|
|
|
|
void sendMoveToPosition(boolean direct)
|
|
|
|
{
|
|
|
|
sendMoveToPosition(direct, getMouseVector());
|
|
|
|
}
|
|
|
|
|
|
|
|
void sendMoveToPosition(boolean direct, PVector position)
|
|
|
|
{
|
|
|
|
String command = null;
|
|
|
|
PVector p = getDisplayMachine().scaleToDisplayMachine(position);
|
|
|
|
p = getDisplayMachine().inSteps(p);
|
|
|
|
p = getDisplayMachine().asNativeCoords(p);
|
|
|
|
sendMoveToNativePosition(direct, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sendMoveToNativePosition(boolean direct, PVector p)
|
|
|
|
{
|
|
|
|
String command = null;
|
|
|
|
if (direct)
|
|
|
|
command = CMD_CHANGELENGTHDIRECT+int(p.x+0.5)+","+int(p.y+0.5)+","+getMaxSegmentLength()+",END";
|
|
|
|
else
|
|
|
|
command = CMD_CHANGELENGTH+(int)p.x+","+(int)p.y+",END";
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-02-17 23:52:07 +01:00
|
|
|
addToCommandQueue(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int getMaxSegmentLength()
|
|
|
|
{
|
|
|
|
return this.maxSegmentLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sendTestPattern()
|
|
|
|
{
|
|
|
|
String command = CMD_DRAWDIRECTIONTEST+int(gridSize)+",6,END";
|
|
|
|
addToCommandQueue(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sendTestPenWidth()
|
|
|
|
{
|
|
|
|
NumberFormat nf = NumberFormat.getNumberInstance(Locale.UK);
|
|
|
|
DecimalFormat df = (DecimalFormat)nf;
|
|
|
|
df.applyPattern("##0.##");
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
sb.append(testPenWidthCommand)
|
|
|
|
.append(int(gridSize))
|
2016-01-17 23:37:24 +01:00
|
|
|
.append(",")
|
|
|
|
.append(df.format(testPenWidthStartSize))
|
|
|
|
.append(",")
|
|
|
|
.append(df.format(testPenWidthEndSize))
|
|
|
|
.append(",")
|
|
|
|
.append(df.format(testPenWidthIncrementSize))
|
|
|
|
.append(",END");
|
2013-02-17 23:52:07 +01:00
|
|
|
addToCommandQueue(sb.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
void sendSetPosition()
|
|
|
|
{
|
|
|
|
PVector p = getDisplayMachine().scaleToDisplayMachine(getMouseVector());
|
|
|
|
p = getDisplayMachine().convertToNative(p);
|
|
|
|
p = getDisplayMachine().inSteps(p);
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-02-17 23:52:07 +01:00
|
|
|
String command = CMD_SETPOSITION+int(p.x+0.5)+","+int(p.y+0.5)+",END";
|
|
|
|
addToCommandQueue(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sendStartTextAtPoint()
|
|
|
|
{
|
|
|
|
PVector p = getDisplayMachine().scaleToDisplayMachine(getMouseVector());
|
|
|
|
p = getDisplayMachine().convertToNative(p);
|
|
|
|
p = getDisplayMachine().inSteps(p);
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-02-17 23:52:07 +01:00
|
|
|
String command = CMD_START_TEXT+(int)p.x+","+(int)p.y+","+gridSize+",2,END";
|
|
|
|
addToCommandQueue(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sendSetHomePosition()
|
|
|
|
{
|
|
|
|
PVector pgCoords = getDisplayMachine().asNativeCoords(getHomePoint());
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-02-17 23:52:07 +01:00
|
|
|
String command = CMD_SETPOSITION+int(pgCoords.x+0.5)+","+int(pgCoords.y+0.5)+",END";
|
|
|
|
addToCommandQueue(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
int scaleDensity(int inDens, int inMax, int outMax)
|
|
|
|
{
|
|
|
|
float reducedDens = (float(inDens) / float(inMax)) * float(outMax);
|
|
|
|
reducedDens = outMax-reducedDens;
|
2013-04-04 01:30:34 +02:00
|
|
|
// println("inDens:"+inDens+", inMax:"+inMax+", outMax:"+outMax+", reduced:"+reducedDens);
|
|
|
|
|
2013-02-17 23:52:07 +01:00
|
|
|
// round up if bigger than .5
|
|
|
|
int result = int(reducedDens);
|
|
|
|
if (reducedDens - (result) > 0.5)
|
|
|
|
result ++;
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-02-17 23:52:07 +01:00
|
|
|
//result = outMax - result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
SortedMap<Float, List<PVector>> divideIntoRows(Set<PVector> pixels, int direction)
|
|
|
|
{
|
|
|
|
SortedMap<Float, List<PVector>> inRows = new TreeMap<Float, List<PVector>>();
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-02-17 23:52:07 +01:00
|
|
|
for (PVector p : pixels)
|
|
|
|
{
|
|
|
|
Float row = p.x;
|
|
|
|
if (direction == DRAW_DIR_SE || direction == DRAW_DIR_NW)
|
|
|
|
row = p.y;
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-02-17 23:52:07 +01:00
|
|
|
if (!inRows.containsKey(row))
|
|
|
|
{
|
|
|
|
inRows.put(row, new ArrayList<PVector>());
|
|
|
|
}
|
|
|
|
inRows.get(row).add(p);
|
|
|
|
}
|
|
|
|
return inRows;
|
|
|
|
}
|
|
|
|
|
|
|
|
PVector sortPixelsInRowsAlternating(SortedMap<Float, List<PVector>> inRows, int initialDirection, float maxPixelSize)
|
|
|
|
{
|
|
|
|
PVector startPoint = null;
|
|
|
|
Comparator comp = null;
|
|
|
|
boolean rowIsAlongXAxis = true;
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-02-17 23:52:07 +01:00
|
|
|
if (initialDirection == DRAW_DIR_SE || initialDirection == DRAW_DIR_NW)
|
|
|
|
{
|
|
|
|
rowIsAlongXAxis = true;
|
|
|
|
comp = xAscending;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rowIsAlongXAxis = false;
|
|
|
|
comp = yAscending;
|
|
|
|
}
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-02-17 23:52:07 +01:00
|
|
|
// now sort each row, reversing the direction after each row
|
|
|
|
boolean reverse = false;
|
|
|
|
for (Float rowCoord : inRows.keySet())
|
|
|
|
{
|
|
|
|
println("row: " + rowCoord);
|
|
|
|
List<PVector> row = inRows.get(rowCoord);
|
|
|
|
|
|
|
|
if (reverse)
|
|
|
|
{
|
|
|
|
// reverse it (descending)
|
|
|
|
Collections.sort(row, comp);
|
|
|
|
Collections.reverse(row);
|
2013-04-04 01:30:34 +02:00
|
|
|
// if (startPoint == null)
|
|
|
|
// {
|
|
|
|
// if (rowIsAlongXAxis)
|
|
|
|
// startPoint = new PVector(row.get(0).x+(maxPixelSize/2.0), row.get(0).y);
|
|
|
|
// else
|
|
|
|
// startPoint = new PVector(row.get(0).x, row.get(0).y-(maxPixelSize/2.0));
|
|
|
|
// }
|
2013-02-17 23:52:07 +01:00
|
|
|
reverse = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// sort row ascending
|
|
|
|
Collections.sort(row, comp);
|
2013-04-04 01:30:34 +02:00
|
|
|
// if (startPoint == null)
|
|
|
|
// {
|
|
|
|
// if (rowIsAlongXAxis)
|
|
|
|
// startPoint = new PVector(row.get(0).x-(maxPixelSize/2.0), row.get(0).y);
|
|
|
|
// else
|
|
|
|
// startPoint = new PVector(row.get(0).x, row.get(0).y+(maxPixelSize/2.0));
|
|
|
|
// }
|
2013-02-17 23:52:07 +01:00
|
|
|
reverse = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return startPoint;
|
|
|
|
}
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-02-17 23:52:07 +01:00
|
|
|
void sortPixelsInRows(SortedMap<Float, List<PVector>> inRows, int initialDirection)
|
|
|
|
{
|
|
|
|
PVector startPoint = null;
|
|
|
|
Comparator comp = null;
|
|
|
|
boolean rowIsAlongXAxis = true;
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-02-17 23:52:07 +01:00
|
|
|
if (initialDirection == DRAW_DIR_SE || initialDirection == DRAW_DIR_NW)
|
|
|
|
{
|
|
|
|
rowIsAlongXAxis = true;
|
|
|
|
comp = xAscending;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rowIsAlongXAxis = false;
|
|
|
|
comp = yAscending;
|
|
|
|
}
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-02-17 23:52:07 +01:00
|
|
|
// now sort each row, reversing the direction after each row
|
|
|
|
for (Float rowCoord : inRows.keySet())
|
|
|
|
{
|
|
|
|
println("row: " + rowCoord);
|
|
|
|
List<PVector> row = inRows.get(rowCoord);
|
|
|
|
// sort row ascending
|
|
|
|
Collections.sort(row, comp);
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-02-17 23:52:07 +01:00
|
|
|
if (initialDirection == DRAW_DIR_NW || initialDirection == DRAW_DIR_NE)
|
|
|
|
Collections.reverse(row);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void sendPixels(Set<PVector> pixels, String pixelCommand, int initialDirection, int startCorner, float maxPixelSize, boolean scaleSizeToDensity)
|
|
|
|
{
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-02-17 23:52:07 +01:00
|
|
|
// sort it into a map of rows, keyed by y coordinate value
|
|
|
|
SortedMap<Float, List<PVector>> inRows = divideIntoRows(pixels, initialDirection);
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-02-17 23:52:07 +01:00
|
|
|
sortPixelsInRowsAlternating(inRows, initialDirection, maxPixelSize);
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-02-17 23:52:07 +01:00
|
|
|
// that was easy.
|
|
|
|
// load the queue
|
|
|
|
// add a preamble
|
2013-04-04 01:30:34 +02:00
|
|
|
|
|
|
|
// set the first direction
|
2013-02-17 23:52:07 +01:00
|
|
|
int drawDirection = initialDirection;
|
|
|
|
String changeDir = CMD_CHANGEDRAWINGDIRECTION+getPixelDirectionMode()+"," + drawDirection +",END";
|
|
|
|
addToCommandQueue(changeDir);
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-02-17 23:52:07 +01:00
|
|
|
// reverse the row sequence if the draw is starting from the bottom
|
|
|
|
// and reverse the pixel sequence if it needs to be done (odd number of rows)
|
|
|
|
boolean reversePixelSequence = false;
|
|
|
|
List<Float> rowKeys = new ArrayList<Float>();
|
|
|
|
rowKeys.addAll(inRows.keySet());
|
|
|
|
Collections.sort(rowKeys);
|
|
|
|
if (startCorner == DRAW_DIR_SE || startCorner == DRAW_DIR_SW)
|
|
|
|
{
|
|
|
|
Collections.reverse(rowKeys);
|
|
|
|
if (rowKeys.size() % 2 == 0)
|
|
|
|
reversePixelSequence = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// and move the pen to just next to the first pixel
|
|
|
|
List<PVector> firstRow = inRows.get(rowKeys.get(0));
|
|
|
|
|
|
|
|
PVector startPoint = firstRow.get(0);
|
|
|
|
int startPointX = int(startPoint.x);
|
|
|
|
int startPointY = int(startPoint.y);
|
|
|
|
int halfSize = int(maxPixelSize/2.0);
|
|
|
|
|
|
|
|
print("Dir:");
|
|
|
|
if (initialDirection == DRAW_DIR_SE)
|
|
|
|
{
|
|
|
|
startPointX-=halfSize;
|
|
|
|
println("SE");
|
|
|
|
}
|
|
|
|
else if (initialDirection == DRAW_DIR_SW)
|
|
|
|
{
|
|
|
|
startPointY-=halfSize;
|
|
|
|
println("SW");
|
|
|
|
}
|
|
|
|
else if (initialDirection == DRAW_DIR_NW)
|
|
|
|
{
|
|
|
|
startPointX-=halfSize;
|
|
|
|
println("NW");
|
|
|
|
}
|
|
|
|
else if (initialDirection == DRAW_DIR_NE)
|
|
|
|
{
|
|
|
|
startPointY-=halfSize;
|
|
|
|
println("NE");
|
|
|
|
}
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-02-17 23:52:07 +01:00
|
|
|
if (startPoint != null)
|
|
|
|
{
|
|
|
|
String touchdown = CMD_CHANGELENGTH+int(startPointX)+","+int(startPointY)+",END";
|
|
|
|
addToCommandQueue(touchdown);
|
|
|
|
addToCommandQueue(CMD_PENDOWN+"END");
|
|
|
|
}
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-02-17 23:52:07 +01:00
|
|
|
boolean penLifted = false;
|
|
|
|
|
|
|
|
// so for each row
|
|
|
|
for (Float key : rowKeys)
|
|
|
|
{
|
|
|
|
List<PVector> row = inRows.get(key);
|
|
|
|
if (reversePixelSequence)
|
|
|
|
Collections.reverse(row);
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-02-17 23:52:07 +01:00
|
|
|
for (PVector v : row)
|
|
|
|
{
|
|
|
|
if (isHiddenPixel(v)) // check for masked pixels,
|
|
|
|
{
|
|
|
|
//println("It's outside the bright/dark threshold.");
|
|
|
|
if (liftPenOnMaskedPixels)
|
|
|
|
{
|
|
|
|
if (!penLifted) // if the pen isn't already up
|
|
|
|
{
|
|
|
|
String raisePen = CMD_PENUP + "END";
|
|
|
|
addToCommandQueue(raisePen);
|
|
|
|
penLifted = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-04-04 01:30:34 +02:00
|
|
|
// println("Pen is already lifted.");
|
2013-02-17 23:52:07 +01:00
|
|
|
}
|
|
|
|
// now convert to ints
|
|
|
|
int inX = int(v.x);
|
|
|
|
int inY = int(v.y);
|
|
|
|
int pixelSize = int(maxPixelSize);
|
|
|
|
// render a fully bright (255) pixel.
|
|
|
|
String command = pixelCommand+inX+","+inY+","+int(pixelSize+0.5)+",255,END";
|
|
|
|
addToCommandQueue(command);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//println("liftPenOnMaskedPixels is not selected.");
|
|
|
|
}
|
|
|
|
// so this pixel doesn't get added to the queue.
|
|
|
|
}
|
|
|
|
else // pixel wasn't masked - render it up
|
|
|
|
{
|
|
|
|
// now convert to ints
|
|
|
|
int inX = int(v.x);
|
|
|
|
int inY = int(v.y);
|
|
|
|
Integer density = int(v.z);
|
|
|
|
int pixelSize = int(maxPixelSize);
|
|
|
|
if (scaleSizeToDensity)
|
|
|
|
{
|
|
|
|
pixelSize = scaleDensity(density, 255, int(maxPixelSize));
|
|
|
|
density = 0;
|
|
|
|
}
|
|
|
|
int scaledPixelSize = int((pixelSize*getPixelScalingOverGridSize())+0.5);
|
|
|
|
String command = pixelCommand+inX+","+inY+","+scaledPixelSize+","+density+",END";
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-02-17 23:52:07 +01:00
|
|
|
// put the pen down if lifting over masked pixels is on
|
|
|
|
if (liftPenOnMaskedPixels && penLifted)
|
|
|
|
{
|
2013-04-04 01:30:34 +02:00
|
|
|
// println("Pen down.");
|
2013-02-17 23:52:07 +01:00
|
|
|
String lowerPen = CMD_PENDOWN + "END";
|
|
|
|
addToCommandQueue(lowerPen);
|
|
|
|
penLifted = false;
|
|
|
|
}
|
|
|
|
addToCommandQueue(command);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
drawDirection = flipDrawDirection(drawDirection);
|
|
|
|
String command = CMD_CHANGEDRAWINGDIRECTION+getPixelDirectionMode()+"," + drawDirection +",END";
|
|
|
|
addToCommandQueue(command);
|
|
|
|
}
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-02-17 23:52:07 +01:00
|
|
|
addToCommandQueue(CMD_PENUP+"END");
|
|
|
|
numberOfPixelsTotal = commandQueue.size();
|
|
|
|
startPixelTimer();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int flipDrawDirection(int curr)
|
|
|
|
{
|
|
|
|
if (curr == DRAW_DIR_SE)
|
|
|
|
return DRAW_DIR_NW;
|
|
|
|
else if (curr == DRAW_DIR_NW)
|
|
|
|
return DRAW_DIR_SE;
|
|
|
|
else if (curr == DRAW_DIR_NE)
|
|
|
|
return DRAW_DIR_SW;
|
|
|
|
else if (curr == DRAW_DIR_SW)
|
|
|
|
return DRAW_DIR_NE;
|
|
|
|
else return DRAW_DIR_SE;
|
|
|
|
}
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-02-17 23:52:07 +01:00
|
|
|
|
|
|
|
int getPixelDirectionMode()
|
|
|
|
{
|
|
|
|
return pixelDirectionMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void sendSawtoothPixels(Set<PVector> pixels)
|
|
|
|
{
|
|
|
|
sendPixels(pixels, CMD_DRAWSAWPIXEL, renderStartDirection, renderStartPosition, getGridSize(), false);
|
|
|
|
}
|
|
|
|
void sendCircularPixels(Set<PVector> pixels)
|
|
|
|
{
|
|
|
|
sendPixels(pixels, CMD_DRAWROUNDPIXEL, renderStartDirection, renderStartPosition, getGridSize(), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sendScaledSquarePixels(Set<PVector> pixels)
|
|
|
|
{
|
|
|
|
sendPixels(pixels, CMD_DRAWPIXEL, renderStartDirection, renderStartPosition, getGridSize(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sendSolidSquarePixels(Set<PVector> pixels)
|
|
|
|
{
|
|
|
|
for (PVector p : pixels)
|
|
|
|
{
|
|
|
|
if (p.z != MASKED_PIXEL_BRIGHTNESS)
|
|
|
|
p.z = 0.0;
|
|
|
|
}
|
|
|
|
sendPixels(pixels, CMD_DRAWPIXEL, renderStartDirection, renderStartPosition, getGridSize(), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sendSquarePixels(Set<PVector> pixels)
|
|
|
|
{
|
|
|
|
sendPixels(pixels, CMD_DRAWPIXEL, renderStartDirection, renderStartPosition, getGridSize(), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sendScribblePixels(Set<PVector> pixels)
|
|
|
|
{
|
|
|
|
sendPixels(pixels, CMD_DRAWSCRIBBLEPIXEL, renderStartDirection, renderStartPosition, getGridSize(), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void sendOutlineOfPixels(Set<PVector> pixels)
|
|
|
|
{
|
|
|
|
// sort it into a map of rows, keyed by y coordinate value
|
|
|
|
SortedMap<Float, List<PVector>> inRows = divideIntoRows(pixels, DRAW_DIR_SE);
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-02-17 23:52:07 +01:00
|
|
|
sortPixelsInRowsAlternating(inRows, DRAW_DIR_SE, getGridSize());
|
|
|
|
|
|
|
|
float halfGrid = getGridSize() / 2.0;
|
|
|
|
for (Float key : inRows.keySet())
|
|
|
|
{
|
|
|
|
for (PVector p : inRows.get(key))
|
|
|
|
{
|
|
|
|
PVector startPoint = new PVector(p.x-halfGrid, p.y-halfGrid);
|
|
|
|
PVector endPoint = new PVector(p.x+halfGrid, p.y+halfGrid);
|
|
|
|
String command = CMD_DRAWRECT + int(startPoint.x)+","+int(startPoint.y)+","+int(endPoint.x)+","+int(endPoint.y)+",END";
|
|
|
|
addToCommandQueue(command);
|
|
|
|
}
|
2013-04-04 01:30:34 +02:00
|
|
|
}
|
2013-02-17 23:52:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void sendOutlineOfRows(Set<PVector> pixels, int drawDirection)
|
|
|
|
{
|
|
|
|
// sort it into a map of rows, keyed by y coordinate value
|
|
|
|
SortedMap<Float, List<PVector>> inRows = divideIntoRows(pixels, drawDirection);
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-02-17 23:52:07 +01:00
|
|
|
sortPixelsInRows(inRows, drawDirection);
|
|
|
|
|
|
|
|
PVector offset = new PVector(getGridSize() / 2.0, getGridSize() / 2.0);
|
|
|
|
for (Float key : inRows.keySet())
|
|
|
|
{
|
|
|
|
PVector startPoint = inRows.get(key).get(0);
|
|
|
|
PVector endPoint = inRows.get(key).get(inRows.get(key).size()-1);
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-02-17 23:52:07 +01:00
|
|
|
if (drawDirection == DRAW_DIR_SE)
|
|
|
|
{
|
|
|
|
startPoint.sub(offset);
|
|
|
|
endPoint.add(offset);
|
|
|
|
}
|
|
|
|
else if (drawDirection == DRAW_DIR_NW)
|
|
|
|
{
|
|
|
|
startPoint.add(offset);
|
|
|
|
endPoint.sub(offset);
|
|
|
|
}
|
|
|
|
else if (drawDirection == DRAW_DIR_SW)
|
|
|
|
{
|
|
|
|
startPoint.add(offset);
|
|
|
|
endPoint.sub(offset);
|
|
|
|
}
|
|
|
|
else if (drawDirection == DRAW_DIR_NW)
|
|
|
|
{
|
|
|
|
startPoint.add(offset);
|
|
|
|
endPoint.sub(offset);
|
|
|
|
}
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-02-17 23:52:07 +01:00
|
|
|
String command = CMD_DRAWRECT + int(startPoint.x)+","+int(startPoint.y)+","+int(endPoint.x)+","+int(endPoint.y)+",END";
|
|
|
|
addToCommandQueue(command);
|
2013-04-04 01:30:34 +02:00
|
|
|
}
|
2013-02-17 23:52:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void sendGridOfBox(Set<PVector> pixels)
|
|
|
|
{
|
|
|
|
sendOutlineOfRows(pixels, DRAW_DIR_SE);
|
|
|
|
sendOutlineOfRows(pixels, DRAW_DIR_SW);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void sendOutlineOfBox()
|
|
|
|
{
|
|
|
|
// convert cartesian to native format
|
|
|
|
PVector tl = getDisplayMachine().inSteps(getBoxVector1());
|
|
|
|
PVector br = getDisplayMachine().inSteps(getBoxVector2());
|
|
|
|
|
|
|
|
PVector tr = new PVector(br.x, tl.y);
|
|
|
|
PVector bl = new PVector(tl.x, br.y);
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-02-17 23:52:07 +01:00
|
|
|
tl = getDisplayMachine().asNativeCoords(tl);
|
|
|
|
tr = getDisplayMachine().asNativeCoords(tr);
|
|
|
|
bl = getDisplayMachine().asNativeCoords(bl);
|
|
|
|
br = getDisplayMachine().asNativeCoords(br);
|
2013-04-28 11:47:01 +02:00
|
|
|
|
|
|
|
String cmd = (true) ? CMD_CHANGELENGTHDIRECT : CMD_CHANGELENGTH;
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-04-28 11:47:01 +02:00
|
|
|
String command = cmd+(int)tl.x+","+(int)tl.y+","+getMaxSegmentLength()+",END";
|
2013-02-17 23:52:07 +01:00
|
|
|
addToCommandQueue(command);
|
|
|
|
|
2013-04-28 11:47:01 +02:00
|
|
|
command = cmd+(int)tr.x+","+(int)tr.y+","+getMaxSegmentLength()+",END";
|
2013-02-17 23:52:07 +01:00
|
|
|
addToCommandQueue(command);
|
|
|
|
|
2013-04-28 11:47:01 +02:00
|
|
|
command = cmd+(int)br.x+","+(int)br.y+","+getMaxSegmentLength()+",END";
|
2013-02-17 23:52:07 +01:00
|
|
|
addToCommandQueue(command);
|
|
|
|
|
2013-04-28 11:47:01 +02:00
|
|
|
command = cmd+(int)bl.x+","+(int)bl.y+","+getMaxSegmentLength()+",END";
|
2013-02-17 23:52:07 +01:00
|
|
|
addToCommandQueue(command);
|
|
|
|
|
2013-04-28 11:47:01 +02:00
|
|
|
command = cmd+(int)tl.x+","+(int)tl.y+","+getMaxSegmentLength()+",END";
|
2013-02-17 23:52:07 +01:00
|
|
|
addToCommandQueue(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sendVectorShapes()
|
2013-03-30 15:10:12 +01:00
|
|
|
{
|
2013-04-20 01:41:27 +02:00
|
|
|
sendVectorShapes(getVectorShape(), vectorScaling/100, getVectorPosition(), PATH_SORT_NONE);
|
2013-03-30 15:10:12 +01:00
|
|
|
}
|
|
|
|
|
2013-04-20 01:41:27 +02:00
|
|
|
|
|
|
|
void sendVectorShapes(RShape vec, float scaling, PVector position, int pathSortingAlgorithm)
|
2013-02-17 23:52:07 +01:00
|
|
|
{
|
2013-03-20 15:15:06 +01:00
|
|
|
println("Send vector shapes.");
|
2013-03-30 15:10:12 +01:00
|
|
|
RPoint[][] pointPaths = vec.getPointsInPaths();
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-03-31 00:27:19 +01:00
|
|
|
// sort the paths to optimise the draw sequence
|
2013-04-20 01:41:27 +02:00
|
|
|
switch (pathSortingAlgorithm) {
|
|
|
|
case PATH_SORT_MOST_POINTS_FIRST: pointPaths = sortPathsLongestFirst(pointPaths, pathLengthHighPassCutoff); break;
|
|
|
|
case PATH_SORT_GREATEST_AREA_FIRST: pointPaths = sortPathsGreatestAreaFirst(vec, pathLengthHighPassCutoff); break;
|
|
|
|
case PATH_SORT_CENTRE_FIRST: pointPaths = sortPathsCentreFirst(vec, pathLengthHighPassCutoff); break;
|
|
|
|
}
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-02-17 23:52:07 +01:00
|
|
|
String command = "";
|
2013-03-20 15:15:06 +01:00
|
|
|
PVector lastPoint = new PVector();
|
|
|
|
boolean liftToGetToNewPoint = true;
|
2014-09-18 00:45:09 +02:00
|
|
|
|
2013-02-17 23:52:07 +01:00
|
|
|
// go through and get each path
|
|
|
|
for (int i = 0; i<pointPaths.length; i++)
|
|
|
|
{
|
|
|
|
if (pointPaths[i] != null)
|
|
|
|
{
|
|
|
|
boolean firstPointFound = false;
|
2013-03-31 19:25:21 +02:00
|
|
|
if (pointPaths[i].length > pathLengthHighPassCutoff)
|
2013-02-17 23:52:07 +01:00
|
|
|
{
|
2014-09-18 00:45:09 +02:00
|
|
|
List<PVector> filteredPoints = filterPoints(pointPaths[i], VECTOR_FILTER_LOW_PASS, minimumVectorLineLength, scaling, position);
|
|
|
|
if (!filteredPoints.isEmpty())
|
2013-02-17 23:52:07 +01:00
|
|
|
{
|
2014-09-18 00:45:09 +02:00
|
|
|
// draw the first one with a pen up and down to get to it
|
|
|
|
PVector p = filteredPoints.get(0);
|
|
|
|
if ( p.x == lastPoint.x && p.y == lastPoint.y )
|
|
|
|
liftToGetToNewPoint = false;
|
|
|
|
else
|
|
|
|
liftToGetToNewPoint = true;
|
|
|
|
|
|
|
|
// pen UP! (IF THE NEW POINT IS DIFFERENT FROM THE LAST ONE!)
|
|
|
|
if (liftToGetToNewPoint)
|
|
|
|
addToCommandQueue(CMD_PENUP+"END");
|
|
|
|
// move to this point and put the pen down
|
2016-03-28 16:37:20 +02:00
|
|
|
command = CMD_CHANGELENGTHDIRECT+Math.round(p.x)+","+Math.round(p.y)+","+getMaxSegmentLength()+",END";
|
2014-09-18 00:45:09 +02:00
|
|
|
addToCommandQueue(command);
|
|
|
|
if (liftToGetToNewPoint)
|
|
|
|
addToCommandQueue(CMD_PENDOWN+"END");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// then just iterate through the rest
|
|
|
|
for (int j=1; j<filteredPoints.size(); j++)
|
2013-03-31 19:25:21 +02:00
|
|
|
{
|
2014-09-18 00:45:09 +02:00
|
|
|
p = filteredPoints.get(j);
|
2016-03-28 16:37:20 +02:00
|
|
|
command = CMD_CHANGELENGTHDIRECT+Math.round(p.x)+","+Math.round(p.y)+","+getMaxSegmentLength()+",END";
|
2013-04-04 01:30:34 +02:00
|
|
|
addToCommandQueue(command);
|
2013-03-31 19:25:21 +02:00
|
|
|
}
|
2014-09-18 00:45:09 +02:00
|
|
|
lastPoint = new PVector(p.x, p.y);
|
2013-02-17 23:52:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-09 00:14:24 +02:00
|
|
|
addToCommandQueue(CMD_PENUP+"END");
|
2013-02-17 23:52:07 +01:00
|
|
|
println("finished.");
|
|
|
|
}
|
|
|
|
|
2013-04-20 01:41:27 +02:00
|
|
|
public RPoint[][] sortPathsLongestFirst(RPoint[][] pointPaths, int highPassCutoff)
|
2013-03-31 00:27:19 +01:00
|
|
|
{
|
|
|
|
// put the paths into a list
|
|
|
|
List<RPoint[]> pathsList = new ArrayList<RPoint[]>(pointPaths.length);
|
|
|
|
for (int i = 0; i<pointPaths.length; i++)
|
|
|
|
{
|
|
|
|
if (pointPaths[i] != null)
|
|
|
|
{
|
|
|
|
pathsList.add(pointPaths[i]);
|
|
|
|
}
|
|
|
|
}
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-03-31 00:27:19 +01:00
|
|
|
// sort the list
|
|
|
|
Collections.sort(pathsList, new Comparator<RPoint[]>() {
|
|
|
|
public int compare(RPoint[] o1, RPoint[] o2) {
|
2013-04-04 01:30:34 +02:00
|
|
|
if (o1.length > o2.length) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else if (o1.length < o2.length) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0;
|
|
|
|
}
|
2013-03-31 00:27:19 +01:00
|
|
|
}
|
2013-04-04 01:30:34 +02:00
|
|
|
}
|
|
|
|
);
|
2013-03-31 19:25:21 +02:00
|
|
|
|
|
|
|
// filter out some short paths
|
|
|
|
pathsList = removeShortPaths(pathsList, highPassCutoff);
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2013-03-31 19:25:21 +02:00
|
|
|
// and put them into a new array
|
2013-03-31 00:27:19 +01:00
|
|
|
for (int i=0; i<pathsList.size(); i++)
|
|
|
|
{
|
|
|
|
pointPaths[i] = pathsList.get(i);
|
|
|
|
}
|
2013-03-31 19:25:21 +02:00
|
|
|
|
2013-03-31 00:27:19 +01:00
|
|
|
return pointPaths;
|
|
|
|
}
|
|
|
|
|
2013-04-04 01:30:34 +02:00
|
|
|
public RPoint[][] sortPathsGreatestAreaFirst(RShape vec, int highPassCutoff)
|
|
|
|
{
|
|
|
|
// put the paths into a list
|
|
|
|
SortedMap<Float, RPoint[]> pathsList = new TreeMap<Float, RPoint[]>();
|
|
|
|
|
|
|
|
int noOfChildren = vec.countChildren();
|
|
|
|
for (int i=0; i < noOfChildren; i++)
|
|
|
|
{
|
|
|
|
float area = vec.children[i].getArea();
|
|
|
|
RPoint[] path = vec.children[i].getPointsInPaths()[0];
|
|
|
|
pathsList.put(area, path);
|
|
|
|
}
|
|
|
|
|
|
|
|
RPoint[][] pointPaths = vec.getPointsInPaths();
|
|
|
|
List<RPoint[]> filtered = new ArrayList<RPoint[]>();
|
|
|
|
|
|
|
|
// and put them into a new array
|
|
|
|
int i = 0;
|
|
|
|
for (Float k : pathsList.keySet())
|
|
|
|
{
|
|
|
|
if (k >= highPassCutoff)
|
|
|
|
{
|
|
|
|
filtered.add(pathsList.get(k));
|
|
|
|
println("Filtered kept path of area " + k);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
println("Filtered discarded path of area " + k);
|
|
|
|
}
|
|
|
|
|
|
|
|
pointPaths = new RPoint[filtered.size()][];
|
|
|
|
for (i = 0; i < filtered.size(); i++)
|
|
|
|
{
|
|
|
|
pointPaths[i] = filtered.get(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pointPaths;
|
|
|
|
}
|
|
|
|
|
|
|
|
public RPoint[][] sortPathsCentreFirst(RShape vec, int highPassCutoff)
|
|
|
|
{
|
|
|
|
// put the paths into a list
|
|
|
|
int noOfChildren = vec.countChildren();
|
|
|
|
List<RShape> pathsList = new ArrayList<RShape>(noOfChildren);
|
|
|
|
for (int i=0; i < noOfChildren; i++)
|
|
|
|
pathsList.add(vec.children[i]);
|
|
|
|
List<RShape> orderedPathsList = new ArrayList<RShape>(noOfChildren);
|
|
|
|
|
|
|
|
// make a tiny area in the centre of the shape,
|
|
|
|
// plan to increment the size of the area until it covers vec entirely
|
|
|
|
// (radius of area min = 0, max = distance from shape centre to any corner.)
|
|
|
|
|
|
|
|
float aspectRatio = vec.getHeight() / vec.getWidth();
|
|
|
|
int n = 0;
|
|
|
|
float w = 1.0;
|
|
|
|
float h = w * aspectRatio;
|
|
|
|
|
|
|
|
RPoint topLeft = vec.getTopLeft();
|
|
|
|
RPoint botRight = vec.getBottomRight();
|
|
|
|
|
|
|
|
PVector centre = new PVector(vec.getWidth()/2, vec.getHeight()/2);
|
|
|
|
|
|
|
|
float vecWidth = vec.getWidth();
|
|
|
|
|
|
|
|
while (w <= vecWidth)
|
|
|
|
{
|
|
|
|
w+=6.0;
|
|
|
|
h = w * aspectRatio;
|
|
|
|
|
|
|
|
//println(n++ + ". Rect w " + w + ", h " + h);
|
|
|
|
RShape field = RShape.createRectangle(centre.x-(w/2.0), centre.y-(h/2.0), w, h);
|
|
|
|
// add all the shapes that are entirely inside the circle to orderedPathsList
|
|
|
|
ListIterator<RShape> it = pathsList.listIterator();
|
|
|
|
int shapesAdded = 0;
|
|
|
|
while (it.hasNext())
|
|
|
|
{
|
|
|
|
RShape sh = it.next();
|
|
|
|
if (field.contains(sh.getCenter()))
|
|
|
|
{
|
|
|
|
orderedPathsList.add(sh);
|
|
|
|
// remove the shapes from pathsList (so it isn't found again)
|
|
|
|
shapesAdded++;
|
|
|
|
it.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// increase the size of the circle and try again
|
|
|
|
}
|
|
|
|
|
|
|
|
RPoint[][] pointPaths = new RPoint[orderedPathsList.size()][];// vec.getPointsInPaths();
|
|
|
|
for (int i = 0; i < orderedPathsList.size(); i++)
|
|
|
|
{
|
|
|
|
pointPaths[i] = orderedPathsList.get(i).getPointsInPaths()[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
return pointPaths;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-31 19:25:21 +02:00
|
|
|
List<RPoint[]> removeShortPaths(List<RPoint[]> list, int cutoff)
|
|
|
|
{
|
|
|
|
if (cutoff > 0)
|
|
|
|
{
|
2013-03-31 22:42:33 +02:00
|
|
|
int numberOfPaths = list.size();
|
|
|
|
ListIterator<RPoint[]> it = list.listIterator();
|
2013-04-04 01:30:34 +02:00
|
|
|
while (it.hasNext ())
|
2013-03-31 19:25:21 +02:00
|
|
|
{
|
2013-03-31 22:42:33 +02:00
|
|
|
RPoint[] paths = it.next();
|
|
|
|
if (paths == null || cutoff >= paths.length)
|
2013-03-31 19:25:21 +02:00
|
|
|
{
|
2013-03-31 22:42:33 +02:00
|
|
|
it.remove();
|
2013-03-31 19:25:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2014-09-18 00:45:09 +02:00
|
|
|
List<PVector> filterPoints(RPoint[] points, int filterToUse, long filterParam, float scaling, PVector position)
|
2013-02-17 23:52:07 +01:00
|
|
|
{
|
2013-03-31 00:27:19 +01:00
|
|
|
return filterPointsLowPass(points, filterParam, scaling, position);
|
2013-02-17 23:52:07 +01:00
|
|
|
}
|
|
|
|
|
2014-09-18 00:45:09 +02:00
|
|
|
List<PVector> filterPointsLowPass(RPoint[] points, long filterParam, float scaling, PVector position)
|
2013-02-17 23:52:07 +01:00
|
|
|
{
|
2014-09-18 00:45:09 +02:00
|
|
|
List<PVector> result = new ArrayList<PVector>();
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2014-09-18 00:45:09 +02:00
|
|
|
// scale and convert all the points first
|
|
|
|
List<PVector> scaled = new ArrayList<PVector>(points.length);
|
2016-03-28 16:37:20 +02:00
|
|
|
println("a filterPointsLowPass: Scaled length: " + points.length);
|
2013-02-17 23:52:07 +01:00
|
|
|
for (int j = 0; j<points.length; j++)
|
|
|
|
{
|
|
|
|
RPoint firstPoint = points[j];
|
|
|
|
PVector p = new PVector(firstPoint.x, firstPoint.y);
|
2013-03-31 00:27:19 +01:00
|
|
|
p = PVector.mult(p, scaling);
|
|
|
|
p = PVector.add(p, position);
|
2013-02-17 23:52:07 +01:00
|
|
|
p = getDisplayMachine().inSteps(p);
|
2014-08-22 20:13:41 +02:00
|
|
|
if (getDisplayMachine().getPictureFrame().surrounds(p))
|
2013-02-17 23:52:07 +01:00
|
|
|
{
|
|
|
|
p = getDisplayMachine().asNativeCoords(p);
|
2014-09-18 00:45:09 +02:00
|
|
|
scaled.add(p);
|
2013-02-17 23:52:07 +01:00
|
|
|
}
|
|
|
|
}
|
2013-04-04 01:30:34 +02:00
|
|
|
|
2016-03-28 16:37:20 +02:00
|
|
|
println("b filterPointsLowPass: Scaled length: " + scaled.size());
|
|
|
|
if (scaled.size() > 1.0)
|
2014-08-22 20:13:41 +02:00
|
|
|
{
|
2014-09-18 00:45:09 +02:00
|
|
|
PVector p = scaled.get(0);
|
|
|
|
result.add(p);
|
|
|
|
|
|
|
|
for (int j = 1; j<scaled.size(); j++)
|
2013-02-17 23:52:07 +01:00
|
|
|
{
|
2014-09-18 00:45:09 +02:00
|
|
|
p = scaled.get(j);
|
|
|
|
// and even then, only bother drawing if it's a move of over "x" steps
|
2018-05-28 00:01:08 +02:00
|
|
|
int diffx = abs(int(p.x) - int(result.get(result.size()-1).x));
|
|
|
|
int diffy = abs(int(p.y) - int(result.get(result.size()-1).y));
|
2014-09-18 00:45:09 +02:00
|
|
|
|
2018-05-28 00:01:08 +02:00
|
|
|
if (diffx > filterParam || diffy > filterParam)
|
2014-08-22 20:13:41 +02:00
|
|
|
{
|
2018-05-28 00:01:08 +02:00
|
|
|
println(j + ". Adding point " + p + " because diffx (" + diffx + ") or diffy (" + diffy + ") is > " + filterParam + ", last: " + result.get(result.size()-1));
|
2014-09-18 00:45:09 +02:00
|
|
|
result.add(p);
|
2013-04-04 01:30:34 +02:00
|
|
|
}
|
2013-02-17 23:52:07 +01:00
|
|
|
}
|
|
|
|
}
|
2014-09-18 00:45:09 +02:00
|
|
|
|
2016-03-28 16:37:20 +02:00
|
|
|
println("c filterPointsLowPass: Scaled length: " + result.size());
|
2014-09-18 00:45:09 +02:00
|
|
|
if (result.size() < 2)
|
|
|
|
result.clear();
|
|
|
|
|
|
|
|
//println("finished filter.");
|
2013-02-17 23:52:07 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void sendMachineStoreMode()
|
|
|
|
{
|
|
|
|
String overwrite = ",R";
|
|
|
|
if (!getOverwriteExistingStoreFile())
|
|
|
|
overwrite = ",A";
|
2013-04-04 01:30:34 +02:00
|
|
|
|
|
|
|
addToRealtimeCommandQueue(CMD_MACHINE_MODE_STORE_COMMANDS + getStoreFilename()+overwrite+",END");
|
2013-02-17 23:52:07 +01:00
|
|
|
}
|
|
|
|
void sendMachineLiveMode()
|
|
|
|
{
|
2015-09-05 17:00:22 +02:00
|
|
|
addToCommandQueue(CMD_MACHINE_MODE_LIVE+"END");
|
2013-02-17 23:52:07 +01:00
|
|
|
}
|
|
|
|
void sendMachineExecMode()
|
|
|
|
{
|
|
|
|
sendMachineLiveMode();
|
|
|
|
if (storeFilename != null && !"".equals(storeFilename))
|
|
|
|
addToCommandQueue(CMD_MACHINE_MODE_EXEC_FROM_STORE + getStoreFilename() + ",END");
|
|
|
|
}
|
|
|
|
void sendRandomDraw()
|
|
|
|
{
|
|
|
|
addToCommandQueue(CMD_RANDOM_DRAW+"END");
|
|
|
|
}
|
|
|
|
void sendStartSwirling()
|
|
|
|
{
|
|
|
|
addToCommandQueue(CMD_SWIRLING+"1,END");
|
|
|
|
}
|
|
|
|
void sendStopSwirling()
|
|
|
|
{
|
|
|
|
addToCommandQueue(CMD_SWIRLING+"0,END");
|
|
|
|
}
|
|
|
|
void sendDrawRandomSprite(String spriteFilename)
|
|
|
|
{
|
|
|
|
addToCommandQueue(CMD_DRAW_RANDOM_SPRITE+","+spriteFilename+",100,500,END");
|
2018-05-28 00:01:08 +02:00
|
|
|
}
|