Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

78
LINES

< > BotCompany Repo | #1014272 // Optimized "Marshall Servo Position" Gauge with background image v2 (paint only on change, OK)

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Uses 994K of libraries. Click here for Pure Java version (7037L/36K).

!7

p { pMain(Gauge); }

sclass Gauge extends PApplet {

/* *************  L3Dnam - may2015  ****************** 
This sketch demonstrate how to use PNG images from a gauge and an arrow, to make a fully functional
"real like" Gauge responding for the Mouse-X movement, showing angles for a Servo position (0º to 180º) 
for example!  Need 2 PNG images on Data subFolder inside the Sketch folder.
Marshall B&P gauge.png  and  marshall B&P ponteiro.png. -->  Both images must have no Background.
Create your own png images from real gauges or Other Objetcs and Enjoy.
*/

PImage mostrador, ponteiro; //both images on DATA subfolder
PFont fontA;
int Tx, Ty, P0, P180;       // Tx/Ty position text indicator  P0/P180 start & End point of Arrow
int Wsize1 = 300;   //Wsize1  &  Wsize2 = tamanho janela 
int Wsize2 = 300;
int gauge;       // Gauge1 and Gauge2 are 2 example gauges,  choose one of them on line 20
float value, maxValue = 180, precision = 0.1f;

void mouseMoved() {
  float oldValue = value, newValue = map(mouseX, 0, width, 0, maxValue);
  value = newValue;
  if (floorRatio(oldValue, precision) != floorRatio(newValue, precision))
    redraw();
}

void settings() {
  size (Wsize1,Wsize2 /*,OPENGL XXX*/);
}

void setup() {
/******************************************************************/  
 gauge = 1;     // Gauge Type 1,  choose 2 for another Gauge
/******************************************************************/   
switch (gauge) {
  case 1: 
      mostrador = loadImage(loadImageAsFilePath(#1101160)/*"Gauge B&P Marshall 180.png"*/);
      ponteiro = loadImage(loadImageAsFilePath(#1101161)/*"marshall B&P ponteiro.png"*/); //loadImage("Ponteiro_Vermelho.png");
      Tx=-20 ;  Ty=58; P0=0  ;  P180=272 ;
    break;
  case 2: 
      mostrador = loadImage("gauge.png");
      ponteiro = loadImage(loadImageAsFilePath(#1101162)/*"Ponteiro_Vermelho.png"*/); //loadImage("Ponteiro_Vermelho.png");
      Tx=-17 ;  Ty=74; P0=-226  ;  P180=46 ;
    break;
 }
 imageMode(CENTER);
 fontA = createFont(libraryPath(#1014271/*"dutcheb.ttf"*/), 20); //numeric indication of the Angle
 textFont(fontA);
 
 noLoop();
}


void draw() {
  background(177);
  stroke(153);
  translate(Wsize1/2, Wsize2/2); // posiciona o mostrador no centro da tela
  image(mostrador, 0 , 0 , Wsize1*0.9f, Wsize2*0.9f); // imagem, coluna, linha, Widt, Height
  float rodar = map(value, 0,maxValue,P0,P180); //mouseX movement 0 & 360 grauss for Arrow
  float angulo = map(value, 0,maxValue,0,181); //Numeric mouseX movement 0 & 360 grauss
     fill(255,255,255);                      // Text Color = Blank
     text((int) angulo, Tx,Ty);              // Position of Text with Numeric Angle
     rotate(radians((int) rodar));            // Rotate the Arrow as "rodar" value
switch(gauge) {
  case 1: 
      image(ponteiro, -22.9f, 23.1f, Wsize1*0.33f, Wsize2*0.33f); // imagem, coluna, linha, Widt, Height
    break;
  case 2: 
      image(ponteiro, 21.5f, 0.2f, Wsize1*0.43f, Wsize2*0.06f); // imagem, coluna, linha, Widt, Height
    break;     
  }
}

}

Author comment

Began life as a copy of #1014268

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

1 comment(s) hidden. show

Snippet ID: #1014272
Snippet name: Optimized "Marshall Servo Position" Gauge with background image v2 (paint only on change, OK)
Eternal ID of this version: #1014272/6
Text MD5: def57b74813770ee35bcbd6b08859cc7
Transpilation MD5: 9d9481047200ad2c50983c7d1073af34
Author: stefan
Category: javax
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-04-19 17:35:52
Source code size: 3119 bytes / 78 lines
Pitched / IR pitched: No / No
Views / Downloads: 694 / 1477
Version history: 5 change(s)
Referenced in: [show references]