mirror of
https://github.com/euphy/polargraphcontroller
synced 2025-01-09 19:55:16 +01:00
Vector scaling now scales from centre of shape (rather than handle) and
handle for grabbing is also now in the centre of the shape. Makes a bit more sense. Have also added a pixel previewing mechanism into the queue preview, but not sure if that's a good idea or not.
This commit is contained in:
parent
a2fa25cfaa
commit
6376efc12b
@ -368,12 +368,20 @@ class DisplayMachine extends Machine
|
|||||||
p = scaleToScreen(p);
|
p = scaleToScreen(p);
|
||||||
stroke(0);
|
stroke(0);
|
||||||
vertex(p.x, p.y);
|
vertex(p.x, p.y);
|
||||||
ellipse(p.x, p.y, 3, 3);
|
//ellipse(p.x, p.y, 3, 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
endShape();
|
endShape();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// draw spot at centre
|
||||||
|
PVector centroid = new PVector(getVectorShape().width/2, getVectorShape().height/2);
|
||||||
|
centroid = PVector.mult(centroid, (vectorScaling/100));
|
||||||
|
centroid = PVector.add(centroid, getVectorPosition());
|
||||||
|
centroid = scaleToScreen(centroid);
|
||||||
|
fill(255,0,0,128);
|
||||||
|
ellipse(centroid.x, centroid.y, 20,20);
|
||||||
|
noFill();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,8 +173,9 @@ void button_mode_renderCirclePixel()
|
|||||||
void button_mode_renderVectors()
|
void button_mode_renderVectors()
|
||||||
{
|
{
|
||||||
// turn off vector view and turn queue preview on
|
// turn off vector view and turn queue preview on
|
||||||
minitoggle_mode_showVector(false);
|
//minitoggle_mode_showVector(false);
|
||||||
minitoggle_mode_showQueuePreview(true);
|
minitoggle_mode_showQueuePreview(true);
|
||||||
|
println("here");
|
||||||
sendVectorShapes();
|
sendVectorShapes();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -388,7 +389,27 @@ void numberbox_mode_resizeImage(float value)
|
|||||||
|
|
||||||
void numberbox_mode_resizeVector(float value)
|
void numberbox_mode_resizeVector(float value)
|
||||||
{
|
{
|
||||||
|
// get current size of vector in local coordinates
|
||||||
|
PVector oldVectorSize = new PVector(getVectorShape().width, getVectorShape().height);
|
||||||
|
oldVectorSize = PVector.mult(oldVectorSize, (vectorScaling/100));
|
||||||
|
// and current centre point of vector
|
||||||
|
PVector oldCentroid = new PVector(oldVectorSize.x / 2.0, oldVectorSize.y / 2.0);
|
||||||
|
|
||||||
|
// get newly scaled size of vector
|
||||||
|
PVector newVectorSize = new PVector(getVectorShape().width, getVectorShape().height);
|
||||||
|
newVectorSize = PVector.mult(newVectorSize, (value/100));
|
||||||
|
// and new centre point of vector
|
||||||
|
PVector newCentroid = new PVector(newVectorSize.x / 2.0, newVectorSize.y / 2.0);
|
||||||
|
|
||||||
|
// difference is current centre minus new centre
|
||||||
|
PVector difference = PVector.sub(oldCentroid, newCentroid);
|
||||||
|
|
||||||
|
// add difference onto vector position
|
||||||
|
PVector newVectorPosition = PVector.add(vectorPosition, difference);
|
||||||
|
vectorPosition = newVectorPosition;
|
||||||
|
|
||||||
vectorScaling = value;
|
vectorScaling = value;
|
||||||
|
|
||||||
}
|
}
|
||||||
void toggle_mode_moveVector(boolean flag)
|
void toggle_mode_moveVector(boolean flag)
|
||||||
{
|
{
|
||||||
|
@ -423,9 +423,9 @@ Map<String, Controller> initialiseNumberboxValues(Map<String, Controller> map)
|
|||||||
}
|
}
|
||||||
else if (MODE_RESIZE_VECTOR.equals(key))
|
else if (MODE_RESIZE_VECTOR.equals(key))
|
||||||
{
|
{
|
||||||
n.setDecimalPrecision(0);
|
n.setDecimalPrecision(1);
|
||||||
n.setValue(vectorScaling);
|
n.setValue(vectorScaling);
|
||||||
n.setMin(1);
|
n.setMin(0.1);
|
||||||
n.setMax(1000);
|
n.setMax(1000);
|
||||||
n.setMultiplier(0.5);
|
n.setMultiplier(0.5);
|
||||||
}
|
}
|
||||||
|
27
drawing.pde
27
drawing.pde
@ -638,9 +638,12 @@ void sendOutlineOfBox()
|
|||||||
|
|
||||||
void sendVectorShapes()
|
void sendVectorShapes()
|
||||||
{
|
{
|
||||||
|
println("Send vector shapes.");
|
||||||
RPoint[][] pointPaths = getVectorShape().getPointsInPaths();
|
RPoint[][] pointPaths = getVectorShape().getPointsInPaths();
|
||||||
|
|
||||||
String command = "";
|
String command = "";
|
||||||
|
PVector lastPoint = new PVector();
|
||||||
|
boolean liftToGetToNewPoint = true;
|
||||||
|
|
||||||
// go through and get each path
|
// go through and get each path
|
||||||
for (int i = 0; i<pointPaths.length; i++)
|
for (int i = 0; i<pointPaths.length; i++)
|
||||||
@ -648,7 +651,6 @@ void sendVectorShapes()
|
|||||||
if (pointPaths[i] != null)
|
if (pointPaths[i] != null)
|
||||||
{
|
{
|
||||||
boolean firstPointFound = false;
|
boolean firstPointFound = false;
|
||||||
PVector lastPoint = null;
|
|
||||||
|
|
||||||
List<PVector> filteredPoints = filterPoints(pointPaths[i], VECTOR_FILTER_LOW_PASS, minimumVectorLineLength);
|
List<PVector> filteredPoints = filterPoints(pointPaths[i], VECTOR_FILTER_LOW_PASS, minimumVectorLineLength);
|
||||||
//println(filteredPoints);
|
//println(filteredPoints);
|
||||||
@ -656,12 +658,26 @@ void sendVectorShapes()
|
|||||||
{
|
{
|
||||||
// draw the first one with a pen up and down to get to it
|
// draw the first one with a pen up and down to get to it
|
||||||
PVector p = filteredPoints.get(0);
|
PVector p = filteredPoints.get(0);
|
||||||
// pen UP!
|
if (
|
||||||
addToCommandQueue(CMD_PENUP+"END");
|
p.x == lastPoint.x
|
||||||
|
&& p.y == lastPoint.y
|
||||||
|
// p.x <= lastPoint.x+2
|
||||||
|
// && p.x >= lastPoint.x-2
|
||||||
|
// && p.y <= lastPoint.y+2
|
||||||
|
// && p.y >= lastPoint.y-2
|
||||||
|
)
|
||||||
|
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
|
// move to this point and put the pen down
|
||||||
command = CMD_CHANGELENGTHDIRECT+(int)p.x+","+(int)p.y+","+getMaxSegmentLength()+",END";
|
command = CMD_CHANGELENGTHDIRECT+(int)p.x+","+(int)p.y+","+getMaxSegmentLength()+",END";
|
||||||
addToCommandQueue(command);
|
addToCommandQueue(command);
|
||||||
addToCommandQueue(CMD_PENDOWN+"END");
|
if (liftToGetToNewPoint)
|
||||||
|
addToCommandQueue(CMD_PENDOWN+"END");
|
||||||
|
|
||||||
// then just iterate through the rest
|
// then just iterate through the rest
|
||||||
for (int j=1; j<filteredPoints.size(); j++)
|
for (int j=1; j<filteredPoints.size(); j++)
|
||||||
@ -670,7 +686,10 @@ void sendVectorShapes()
|
|||||||
command = CMD_CHANGELENGTHDIRECT+(int)p.x+","+(int)p.y+","+getMaxSegmentLength()+",END";
|
command = CMD_CHANGELENGTHDIRECT+(int)p.x+","+(int)p.y+","+getMaxSegmentLength()+",END";
|
||||||
addToCommandQueue(command);
|
addToCommandQueue(command);
|
||||||
}
|
}
|
||||||
|
lastPoint = new PVector(p.x,p.y);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println("finished.");
|
println("finished.");
|
||||||
|
@ -46,8 +46,8 @@ import controlP5.*;
|
|||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
|
|
||||||
int majorVersionNo = 1;
|
int majorVersionNo = 1;
|
||||||
int minorVersionNo = 2;
|
int minorVersionNo = 3;
|
||||||
int buildNo = 5;
|
int buildNo = 0;
|
||||||
|
|
||||||
String programTitle = "Polargraph Controller v" + majorVersionNo + "." + minorVersionNo + " build " + buildNo;
|
String programTitle = "Polargraph Controller v" + majorVersionNo + "." + minorVersionNo + " build " + buildNo;
|
||||||
ControlP5 cp5;
|
ControlP5 cp5;
|
||||||
@ -794,8 +794,13 @@ void drawMoveImageOutline()
|
|||||||
{
|
{
|
||||||
RPoint[][] pointPaths = getVectorShape().getPointsInPaths();
|
RPoint[][] pointPaths = getVectorShape().getPointsInPaths();
|
||||||
RG.ignoreStyles();
|
RG.ignoreStyles();
|
||||||
stroke(1);
|
stroke(100);
|
||||||
strokeWeight(1);
|
strokeWeight(1);
|
||||||
|
|
||||||
|
// offset mouse vector so it grabs the centre of the shape
|
||||||
|
PVector centroid = new PVector(getVectorShape().width/2, getVectorShape().height/2);
|
||||||
|
centroid = PVector.mult(centroid, (vectorScaling/100));
|
||||||
|
PVector offsetMouseVector = PVector.sub(getDisplayMachine().scaleToDisplayMachine(getMouseVector()), centroid);
|
||||||
if (pointPaths != null)
|
if (pointPaths != null)
|
||||||
{
|
{
|
||||||
for (int i = 0; i<pointPaths.length; i++)
|
for (int i = 0; i<pointPaths.length; i++)
|
||||||
@ -807,9 +812,8 @@ void drawMoveImageOutline()
|
|||||||
{
|
{
|
||||||
PVector p = new PVector(pointPaths[i][j].x, pointPaths[i][j].y);
|
PVector p = new PVector(pointPaths[i][j].x, pointPaths[i][j].y);
|
||||||
p = PVector.mult(p, (vectorScaling/100));
|
p = PVector.mult(p, (vectorScaling/100));
|
||||||
p = PVector.add(p, getDisplayMachine().scaleToDisplayMachine(getMouseVector()));
|
p = PVector.add(p, offsetMouseVector);
|
||||||
p = getDisplayMachine().scaleToScreen(p);
|
p = getDisplayMachine().scaleToScreen(p);
|
||||||
stroke(0);
|
|
||||||
vertex(p.x, p.y);
|
vertex(p.x, p.y);
|
||||||
}
|
}
|
||||||
endShape();
|
endShape();
|
||||||
@ -1421,8 +1425,11 @@ void mouseClicked()
|
|||||||
}
|
}
|
||||||
else if (currentMode.equals(MODE_MOVE_VECTOR))
|
else if (currentMode.equals(MODE_MOVE_VECTOR))
|
||||||
{
|
{
|
||||||
PVector mVect = getDisplayMachine().scaleToDisplayMachine(getMouseVector());
|
// offset mouse vector so it grabs the centre of the shape
|
||||||
vectorPosition = mVect;
|
PVector centroid = new PVector(getVectorShape().width/2, getVectorShape().height/2);
|
||||||
|
centroid = PVector.mult(centroid, (vectorScaling/100));
|
||||||
|
PVector offsetMouseVector = PVector.sub(getDisplayMachine().scaleToDisplayMachine(getMouseVector()), centroid);
|
||||||
|
vectorPosition = offsetMouseVector;
|
||||||
}
|
}
|
||||||
else if (mouseOverQueue())
|
else if (mouseOverQueue())
|
||||||
{
|
{
|
||||||
@ -1564,8 +1571,9 @@ void setChromaKey(PVector p)
|
|||||||
|
|
||||||
boolean isPreviewable(String command)
|
boolean isPreviewable(String command)
|
||||||
{
|
{
|
||||||
if ((command.startsWith(CMD_CHANGELENGTHDIRECT)
|
if (command.startsWith(CMD_CHANGELENGTHDIRECT)
|
||||||
|| command.startsWith(CMD_CHANGELENGTH)))
|
|| command.startsWith(CMD_CHANGELENGTH)
|
||||||
|
|| command.startsWith(CMD_DRAWPIXEL))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1583,31 +1591,13 @@ void previewQueue()
|
|||||||
{
|
{
|
||||||
PVector startPoint = null;
|
PVector startPoint = null;
|
||||||
|
|
||||||
// if (!commandHistory.isEmpty())
|
|
||||||
// {
|
|
||||||
// Integer commandPosition = commandHistory.size()-1;
|
|
||||||
// String lastCommand = "";
|
|
||||||
// while (commandPosition>=0)
|
|
||||||
// {
|
|
||||||
// lastCommand = commandHistory.get(commandPosition);
|
|
||||||
// if (isPreviewable(lastCommand))
|
|
||||||
// {
|
|
||||||
// String[] splitted = split(lastCommand, ",");
|
|
||||||
// fullList.add(splitted);
|
|
||||||
//// fullList.add(lastCommand);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// commandPosition--;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (commandQueue.hashCode() != lastCommandQueueHash)
|
if (commandQueue.hashCode() != lastCommandQueueHash)
|
||||||
{
|
{
|
||||||
println("regenerating preview queue.");
|
println("regenerating preview queue.");
|
||||||
previewCommandList.clear();
|
previewCommandList.clear();
|
||||||
for (String command : commandQueue)
|
for (String command : commandQueue)
|
||||||
{
|
{
|
||||||
if ((command.startsWith(CMD_CHANGELENGTHDIRECT) || command.startsWith(CMD_CHANGELENGTH)))
|
if (command.startsWith(CMD_CHANGELENGTHDIRECT) || command.startsWith(CMD_CHANGELENGTH) || command.startsWith(CMD_DRAWPIXEL))
|
||||||
{
|
{
|
||||||
String[] splitted = split(command, ",");
|
String[] splitted = split(command, ",");
|
||||||
|
|
||||||
@ -1623,14 +1613,17 @@ void previewQueue()
|
|||||||
|
|
||||||
pv.x = endPoint.x;
|
pv.x = endPoint.x;
|
||||||
pv.y = endPoint.y;
|
pv.y = endPoint.y;
|
||||||
|
pv.z = -1.0;
|
||||||
|
|
||||||
|
if (command.startsWith(CMD_DRAWPIXEL))
|
||||||
|
{
|
||||||
|
String densStr = splitted[4];
|
||||||
|
pv.z = Integer.parseInt(densStr);
|
||||||
|
}
|
||||||
|
|
||||||
previewCommandList.add(pv);
|
previewCommandList.add(pv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
lastCommandQueueHash = commandQueue.hashCode();
|
lastCommandQueueHash = commandQueue.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1654,6 +1647,15 @@ void previewQueue()
|
|||||||
stroke(200,0,0);
|
stroke(200,0,0);
|
||||||
line(startPoint.x, startPoint.y, p.x, p.y);
|
line(startPoint.x, startPoint.y, p.x, p.y);
|
||||||
startPoint = p;
|
startPoint = p;
|
||||||
|
|
||||||
|
if (pv.z >= 0.0)
|
||||||
|
{
|
||||||
|
noStroke();
|
||||||
|
fill(255,pv.z,pv.z);
|
||||||
|
ellipse(p.x, p.y, 5,5);
|
||||||
|
noFill();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (startPoint != null)
|
if (startPoint != null)
|
||||||
@ -1663,6 +1665,7 @@ void previewQueue()
|
|||||||
ellipse(startPoint.x, startPoint.y, 15,15);
|
ellipse(startPoint.x, startPoint.y, 15,15);
|
||||||
noFill();
|
noFill();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isHiddenPixel(PVector p)
|
boolean isHiddenPixel(PVector p)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user