mirror of
https://github.com/euphy/polargraphcontroller
synced 2024-11-13 01:47:57 +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);
|
||||
stroke(0);
|
||||
vertex(p.x, p.y);
|
||||
ellipse(p.x, p.y, 3, 3);
|
||||
//ellipse(p.x, p.y, 3, 3);
|
||||
}
|
||||
}
|
||||
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()
|
||||
{
|
||||
// turn off vector view and turn queue preview on
|
||||
minitoggle_mode_showVector(false);
|
||||
//minitoggle_mode_showVector(false);
|
||||
minitoggle_mode_showQueuePreview(true);
|
||||
println("here");
|
||||
sendVectorShapes();
|
||||
}
|
||||
|
||||
@ -388,7 +389,27 @@ void numberbox_mode_resizeImage(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;
|
||||
|
||||
}
|
||||
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))
|
||||
{
|
||||
n.setDecimalPrecision(0);
|
||||
n.setDecimalPrecision(1);
|
||||
n.setValue(vectorScaling);
|
||||
n.setMin(1);
|
||||
n.setMin(0.1);
|
||||
n.setMax(1000);
|
||||
n.setMultiplier(0.5);
|
||||
}
|
||||
|
27
drawing.pde
27
drawing.pde
@ -638,9 +638,12 @@ void sendOutlineOfBox()
|
||||
|
||||
void sendVectorShapes()
|
||||
{
|
||||
println("Send vector shapes.");
|
||||
RPoint[][] pointPaths = getVectorShape().getPointsInPaths();
|
||||
|
||||
String command = "";
|
||||
PVector lastPoint = new PVector();
|
||||
boolean liftToGetToNewPoint = true;
|
||||
|
||||
// go through and get each path
|
||||
for (int i = 0; i<pointPaths.length; i++)
|
||||
@ -648,7 +651,6 @@ void sendVectorShapes()
|
||||
if (pointPaths[i] != null)
|
||||
{
|
||||
boolean firstPointFound = false;
|
||||
PVector lastPoint = null;
|
||||
|
||||
List<PVector> filteredPoints = filterPoints(pointPaths[i], VECTOR_FILTER_LOW_PASS, minimumVectorLineLength);
|
||||
//println(filteredPoints);
|
||||
@ -656,12 +658,26 @@ void sendVectorShapes()
|
||||
{
|
||||
// draw the first one with a pen up and down to get to it
|
||||
PVector p = filteredPoints.get(0);
|
||||
// pen UP!
|
||||
addToCommandQueue(CMD_PENUP+"END");
|
||||
if (
|
||||
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
|
||||
command = CMD_CHANGELENGTHDIRECT+(int)p.x+","+(int)p.y+","+getMaxSegmentLength()+",END";
|
||||
addToCommandQueue(command);
|
||||
addToCommandQueue(CMD_PENDOWN+"END");
|
||||
if (liftToGetToNewPoint)
|
||||
addToCommandQueue(CMD_PENDOWN+"END");
|
||||
|
||||
// then just iterate through the rest
|
||||
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";
|
||||
addToCommandQueue(command);
|
||||
}
|
||||
lastPoint = new PVector(p.x,p.y);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
println("finished.");
|
||||
|
@ -46,8 +46,8 @@ import controlP5.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
int majorVersionNo = 1;
|
||||
int minorVersionNo = 2;
|
||||
int buildNo = 5;
|
||||
int minorVersionNo = 3;
|
||||
int buildNo = 0;
|
||||
|
||||
String programTitle = "Polargraph Controller v" + majorVersionNo + "." + minorVersionNo + " build " + buildNo;
|
||||
ControlP5 cp5;
|
||||
@ -794,8 +794,13 @@ void drawMoveImageOutline()
|
||||
{
|
||||
RPoint[][] pointPaths = getVectorShape().getPointsInPaths();
|
||||
RG.ignoreStyles();
|
||||
stroke(1);
|
||||
stroke(100);
|
||||
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)
|
||||
{
|
||||
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);
|
||||
p = PVector.mult(p, (vectorScaling/100));
|
||||
p = PVector.add(p, getDisplayMachine().scaleToDisplayMachine(getMouseVector()));
|
||||
p = PVector.add(p, offsetMouseVector);
|
||||
p = getDisplayMachine().scaleToScreen(p);
|
||||
stroke(0);
|
||||
vertex(p.x, p.y);
|
||||
}
|
||||
endShape();
|
||||
@ -1421,8 +1425,11 @@ void mouseClicked()
|
||||
}
|
||||
else if (currentMode.equals(MODE_MOVE_VECTOR))
|
||||
{
|
||||
PVector mVect = getDisplayMachine().scaleToDisplayMachine(getMouseVector());
|
||||
vectorPosition = mVect;
|
||||
// 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);
|
||||
vectorPosition = offsetMouseVector;
|
||||
}
|
||||
else if (mouseOverQueue())
|
||||
{
|
||||
@ -1564,8 +1571,9 @@ void setChromaKey(PVector p)
|
||||
|
||||
boolean isPreviewable(String command)
|
||||
{
|
||||
if ((command.startsWith(CMD_CHANGELENGTHDIRECT)
|
||||
|| command.startsWith(CMD_CHANGELENGTH)))
|
||||
if (command.startsWith(CMD_CHANGELENGTHDIRECT)
|
||||
|| command.startsWith(CMD_CHANGELENGTH)
|
||||
|| command.startsWith(CMD_DRAWPIXEL))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -1583,31 +1591,13 @@ void previewQueue()
|
||||
{
|
||||
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)
|
||||
{
|
||||
println("regenerating preview queue.");
|
||||
previewCommandList.clear();
|
||||
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, ",");
|
||||
|
||||
@ -1623,14 +1613,17 @@ void previewQueue()
|
||||
|
||||
pv.x = endPoint.x;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
lastCommandQueueHash = commandQueue.hashCode();
|
||||
}
|
||||
|
||||
@ -1654,6 +1647,15 @@ void previewQueue()
|
||||
stroke(200,0,0);
|
||||
line(startPoint.x, startPoint.y, p.x, p.y);
|
||||
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)
|
||||
@ -1663,6 +1665,7 @@ void previewQueue()
|
||||
ellipse(startPoint.x, startPoint.y, 15,15);
|
||||
noFill();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
boolean isHiddenPixel(PVector p)
|
||||
|
Loading…
Reference in New Issue
Block a user