Change Rotation Point From 0,0 to 200, 200 on a 400x400 screen
in
Programming Questions
•
1 year ago
- Hi guys, new to the forum. Ive been doing a lot of Arduino stuff, but this is my first Processing projects. I am planning on doing a digital dash for one of my cars, with a VGA to Arduino interface. Right now Im working on one guage at a time. I need to find a way to set different center points for each guage needle for the rotation. Ive read that I have to translate the needle to 0,0, do the rotation, then translate them back to their original position. Im going to have about 12 needles on the dash, this seems like it would take up a bit of CPU power. Is there an easier way? Ive attatched my code for both the SIN-COS calculated needles, and the "rotate" calculated needles. Any help would be appreciated. Thanks, Jesse.
- // MPH Gauge Trials 1
- // SIN and COS calcualtions
- import processing.serial.*;
- float val;
- float val1;
- int mph = 0;
- String arduinoPort = Serial.list()[1];
- float easing = 0.05;
- int easedVal;
- Serial port;
- float angle = 0.0;
- float offset = 200;
- float scalar = 150;
- float speed = 0;
- void setup() {
- size(400,400);
- textSize(26);
- smooth();
- port = new Serial(this, arduinoPort, 9600);
- }
- void draw(){
- // background ();
- if ( port.available() > 0) { // If data is available,
- val = port.read(); // read it and store it in val
- background(150);
- val1 = map(val, 0, 255, 12, 35); // Convert the values, sets needle max and min
- }
- //NEEDLE SWEEP CALCULATIONS
- float x1 = offset + cos(angle) * scalar;
- float y1 = offset + sin(angle) * scalar;
- fill(255, 0, 0);
- triangle( 195, 200, 205, 200, x1, y1); //NEEDLE CENTER POINT AND SWEEP
- angle = val1 / 5; //SWEEP ADJUST
- float mph = map(val, 0, 255, 0, 180);
- int mph1 = round(mph);
- fill(0,0,0);
- textAlign(CENTER);
- text(mph1, 200, 245);
- text("MPH", 200, 275);
- }
- //rotate calculator
- import processing.serial.*;
- float val;
- float val1;
- int mph = 0;
- String arduinoPort = Serial.list()[1];
- float easing = 0.05;
- int easedVal;
- Serial port;
- float angle = 0.0;
- float offset = 200;
- float scalar = 150;
- float speed = 0;
- void setup() {
- size(400,400);
- textSize(26);
- smooth();
- port = new Serial(this, arduinoPort, 9600);
- }
- void draw(){
- // background ();
- if ( port.available() > 0) { // If data is available,
- val = port.read(); // read it and store it in val
- background(150);
- val1 = map(val, 0, 255, 12, 35); // Convert the values, sets needle max and min
- }
- //text labels
- float mph = map(val, 0, 255, 0, 180);
- int mph1 = round(mph);
- fill(0,0,0);
- textAlign(CENTER);
- text(mph1, 200, 245);
- text("MPH", 200, 275);
- //NEEDLE SWEEP CALCULATIONS
- //float x1 = offset + cos(angle) * scalar;
- //float y1 = offset + sin(angle) * scalar;
- fill(255, 0, 0);
- rotate(angle);
- triangle( 195, 200, 205, 200, 200, 50); //NEEDLE CENTER POINT AND SWEEP
- angle = val1 / 5; //SWEEP ADJUST
- }
1