mirror of
https://github.com/euphy/polargraphcontroller
synced 2024-11-15 02:37:56 +01:00
Shapes that go off the drawing area no longer cause long joining lines when they re-appear.
PictureFrame now crops the vector art.
This commit is contained in:
parent
255e63434e
commit
95b569b1a5
@ -519,21 +519,34 @@ class DisplayMachine extends Machine
|
||||
{
|
||||
if (pointPaths[i] != null)
|
||||
{
|
||||
beginShape();
|
||||
boolean inShape = false;
|
||||
for (int j = 0; j<pointPaths[i].length; j++)
|
||||
{
|
||||
PVector p = new PVector(pointPaths[i][j].x, pointPaths[i][j].y);
|
||||
p = PVector.mult(p, scaling);
|
||||
p = PVector.add(p, position);
|
||||
if (getPage().surrounds(inSteps(p)))
|
||||
if (getPictureFrame().surrounds(inSteps(p)))
|
||||
{
|
||||
if (!inShape)
|
||||
{
|
||||
beginShape();
|
||||
inShape = true;
|
||||
}
|
||||
p = scaleToScreen(p);
|
||||
stroke(strokeColour);
|
||||
vertex(p.x, p.y);
|
||||
//ellipse(p.x, p.y, 3, 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (inShape)
|
||||
{
|
||||
endShape();
|
||||
inShape = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
endShape();
|
||||
if (inShape) endShape();
|
||||
}
|
||||
}
|
||||
if (drawCentroid)
|
||||
|
139
drawing.pde
139
drawing.pde
@ -674,7 +674,7 @@ void sendVectorShapes(RShape vec, float scaling, PVector position, int pathSorti
|
||||
String command = "";
|
||||
PVector lastPoint = new PVector();
|
||||
boolean liftToGetToNewPoint = true;
|
||||
|
||||
|
||||
// go through and get each path
|
||||
for (int i = 0; i<pointPaths.length; i++)
|
||||
{
|
||||
@ -684,35 +684,38 @@ void sendVectorShapes(RShape vec, float scaling, PVector position, int pathSorti
|
||||
|
||||
if (pointPaths[i].length > pathLengthHighPassCutoff)
|
||||
{
|
||||
List<PVector> filteredPoints = filterPoints(pointPaths[i], VECTOR_FILTER_LOW_PASS, minimumVectorLineLength, scaling, position);
|
||||
if (!filteredPoints.isEmpty())
|
||||
List<List<PVector>> filteredPaths = filterPoints(pointPaths[i], VECTOR_FILTER_LOW_PASS, minimumVectorLineLength, scaling, position);
|
||||
for (List<PVector> filteredPoints : filteredPaths)
|
||||
{
|
||||
// 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
|
||||
command = CMD_CHANGELENGTHDIRECT+(int)p.x+","+(int)p.y+","+getMaxSegmentLength()+",END";
|
||||
addToCommandQueue(command);
|
||||
if (liftToGetToNewPoint)
|
||||
addToCommandQueue(CMD_PENDOWN+"END");
|
||||
|
||||
|
||||
|
||||
// then just iterate through the rest
|
||||
for (int j=1; j<filteredPoints.size(); j++)
|
||||
if (!filteredPoints.isEmpty())
|
||||
{
|
||||
p = filteredPoints.get(j);
|
||||
// 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
|
||||
command = CMD_CHANGELENGTHDIRECT+(int)p.x+","+(int)p.y+","+getMaxSegmentLength()+",END";
|
||||
addToCommandQueue(command);
|
||||
if (liftToGetToNewPoint)
|
||||
addToCommandQueue(CMD_PENDOWN+"END");
|
||||
|
||||
|
||||
|
||||
// then just iterate through the rest
|
||||
for (int j=1; j<filteredPoints.size(); j++)
|
||||
{
|
||||
p = filteredPoints.get(j);
|
||||
command = CMD_CHANGELENGTHDIRECT+(int)p.x+","+(int)p.y+","+getMaxSegmentLength()+",END";
|
||||
addToCommandQueue(command);
|
||||
}
|
||||
lastPoint = new PVector(p.x, p.y);
|
||||
}
|
||||
lastPoint = new PVector(p.x, p.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -876,17 +879,18 @@ List<RPoint[]> removeShortPaths(List<RPoint[]> list, int cutoff)
|
||||
return list;
|
||||
}
|
||||
|
||||
List<PVector> filterPoints(RPoint[] points, int filterToUse, long filterParam, float scaling, PVector position)
|
||||
List<List<PVector>> filterPoints(RPoint[] points, int filterToUse, long filterParam, float scaling, PVector position)
|
||||
{
|
||||
return filterPointsLowPass(points, filterParam, scaling, position);
|
||||
}
|
||||
|
||||
List<PVector> filterPointsLowPass(RPoint[] points, long filterParam, float scaling, PVector position)
|
||||
List<List<PVector>> filterPointsLowPass(RPoint[] points, long filterParam, float scaling, PVector position)
|
||||
{
|
||||
List<PVector> result = new ArrayList<PVector>();
|
||||
List<List<PVector>> result = new ArrayList<List<PVector>>();
|
||||
|
||||
// scale and convert all the points first
|
||||
List<PVector> scaled = new ArrayList<PVector>(points.length);
|
||||
// scale and convert all the points first, and filter them by area.
|
||||
List<List<PVector>> areaFiltered = new ArrayList<List<PVector>>();
|
||||
List<PVector> scaledPoints = null;
|
||||
for (int j = 0; j<points.length; j++)
|
||||
{
|
||||
RPoint firstPoint = points[j];
|
||||
@ -894,37 +898,64 @@ List<PVector> filterPointsLowPass(RPoint[] points, long filterParam, float scali
|
||||
p = PVector.mult(p, scaling);
|
||||
p = PVector.add(p, position);
|
||||
p = getDisplayMachine().inSteps(p);
|
||||
if (getDisplayMachine().getPage().surrounds(p))
|
||||
|
||||
// Check if the point is on the drawable area
|
||||
if (getDisplayMachine().getPictureFrame().surrounds(p))
|
||||
{
|
||||
p = getDisplayMachine().asNativeCoords(p);
|
||||
scaled.add(p);
|
||||
}
|
||||
}
|
||||
|
||||
if (scaled.size() > 1)
|
||||
{
|
||||
PVector p = scaled.get(0);
|
||||
result.add(p);
|
||||
|
||||
for (int j = 1; j<scaled.size(); j++)
|
||||
{
|
||||
p = scaled.get(j);
|
||||
// and even then, only bother drawing if it's a move of over "x" steps
|
||||
int diffx = int(p.x) - int(result.get(result.size()-1).x);
|
||||
int diffy = int(p.y) - int(result.get(result.size()-1).y);
|
||||
|
||||
if (abs(diffx) > filterParam || abs(diffy) > filterParam)
|
||||
if (scaledPoints == null)
|
||||
{
|
||||
//println("Adding point " + p + ", last: " + result.get(result.size()-1));
|
||||
result.add(p);
|
||||
scaledPoints = new ArrayList<PVector>(points.length);
|
||||
}
|
||||
p = getDisplayMachine().asNativeCoords(p);
|
||||
scaledPoints.add(p);
|
||||
}
|
||||
else
|
||||
{ // if the point is NOT in the drawable area, then check to see if there is a
|
||||
// scaledPoints list, and if there is, that means this is the first point in
|
||||
// the current path that is NOT in the drawable area. That is, the line was on
|
||||
// the drawable area, but it's just gone off it.
|
||||
// In this case, append the current list of scaled points into the results list,
|
||||
// and then nullify scaledPoints so it'll be restarted as a new list if a
|
||||
// subsequent point ends up coming back on the drawable area.
|
||||
if (scaledPoints != null && scaledPoints.size() > 0)
|
||||
{
|
||||
areaFiltered.add(scaledPoints);
|
||||
scaledPoints = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (result.size() < 2)
|
||||
result.clear();
|
||||
|
||||
//println("finished filter.");
|
||||
// Now filter by length
|
||||
if (!areaFiltered.isEmpty())
|
||||
{
|
||||
for (List<PVector> filteredPoints : areaFiltered)
|
||||
{
|
||||
List<PVector> lengthFiltered = new ArrayList<PVector>();
|
||||
PVector p = filteredPoints.get(0);
|
||||
lengthFiltered.add(p);
|
||||
|
||||
for (int j = 1; j<filteredPoints.size(); j++)
|
||||
{
|
||||
p = filteredPoints.get(j);
|
||||
// and even then, only bother drawing if it's a move of over "x" steps
|
||||
int diffx = int(p.x) - int(lengthFiltered.get(lengthFiltered.size()-1).x);
|
||||
int diffy = int(p.y) - int(lengthFiltered.get(lengthFiltered.size()-1).y);
|
||||
|
||||
if (abs(diffx) > filterParam || abs(diffy) > filterParam)
|
||||
{
|
||||
//println("Adding point " + p + ", last: " + result.get(result.size()-1));
|
||||
lengthFiltered.add(p);
|
||||
}
|
||||
}
|
||||
if (lengthFiltered.size() >= 2)
|
||||
{
|
||||
result.add(lengthFiltered);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
println("finished filter.");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user