Hi, i ve just completed a little project where a tablet is connected to an arduino then connected to processing and output drawing made from the tablet to the processing draw window (320x240) that simulate a lcd that i ll receive soon. The drawing are looking fine, but i want to add a feature, i want to whenever a line is finished ( or maybe after i press a key, or event ) the drawing resize itself to fit the entire lcd. but can work also backward, if i start to add line outside the the range it scales back to fit with the new drawing.
Any idea on how i could achieve that on arduino or processing laguage ?
Difficult to say without seeing your code, but one way would be to store all end points as fixed- or floating-point variables, and scale them appropriately.
However, this will impact on performance.
Perfomance might not be a problem as i only need the drawing to be shown after resizing, heres my processing code. I m thinkig "bounding box", how to add bouding box to my drawing and then scale it...maybe.
import processing.serial.*;
Serial myPort; // The serial port
int x = 0;
int y = 0;
int oldx = 0;
int oldy = 0;
int penStatus = 0;
void setup()
{
size(320,240);
frameRate(25);
background(0);
smooth();
stroke (255);
strokeWeight(1);
strokeJoin(ROUND);
myPort = new Serial(this, "COM5", 115200);
myPort.bufferUntil('\n');
}
void serialEvent(Serial myPort) {
oldx = x;
oldy = y;
// read the serial buffer:
String myString = myPort.readStringUntil('\n');
// if you got any bytes other than the linefeed:
myString = trim(myString);
// split the string at the commas
// and convert the sections into integers:
int sensors[] = int(split(myString, ','));
// print out the values you got:
for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) {
//print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t");
//println();
penStatus = sensors[0];
x = sensors[1];
y = sensors[2];
print(oldx);
print(oldy);
print(x);
println(y);
if (penStatus == 1) // if pen is pressed on tablet
{
line (oldx, oldy, x, y);
}
}
}
void draw() {
}
void keyPressed() {
if (key == ' ') {
// clear screen
background(0);
}
if (key == 's') {
//Saves a jpeg file named "image.jpeg"
saveFrame("filename-####.jpg");
}
}
if (key == 's') {
//Saves a jpeg file named "image.jpeg"
saveFrame("filename-####.jpg");
}
I m thinkig "bounding box", how to add bouding box to my drawing and then scale it...maybe.
Defining the bounding box is simple. Define with an array of 4 values, representing the left and right values, and the top and bottom. Count the number of lines drawn, starting at 0. When the first point is added, set the left and right, and top and bottom values to that point. Then, as each additional point is added, if it is less than the left or bottom, update the left or bottom (or both). If it is greater than top or right, update top or right (or both).
Scaling is easy. At any time, you know how big the window is, and how big the data to go in the window is, so calculating horizontal and vertical scale values is easy. You can decide whether the scaling should be the same in both directions, or not.
Now, the hard part is that you are not saving any of the data as it is used, so redrawing the window after defining a new scale value is going to be difficult.
haha yeah the comments not matching the code, is actually a pasted code where i began to change things but not yet finished
For the rest, the array thing make sense, the goal is to achieve resizing only when the pen is leaving the tablet, mean when penStatus == 0 after beeing at 1.
So even i if add a bigger drawing ( let say a circle around the current drawing ) and i need to scale down i only have to use the the bounding box of the circle, and scale down everything else down, but as you say the old drawing is not save data...maybe a way of saving the drawing data everytime the pen is leaving the tablet before a resize... hmmm sounds difficult.
maybe a way of saving the drawing data everytime the pen is leaving the tablet before a resize... hmmm sounds difficult.
You would need to save the data every time you drew a line, so that the data is available when the scale/redraw operation occurs. You can't wait to save data based on the pixels that are lit up.