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

72
LINES

< > BotCompany Repo | #1014268 // Processing: "Marshall Servo Position" Gauge with background image (OK)

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

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

1  
!7
2  
3  
p { pMain(Gauge); }
4  
5  
sclass Gauge extends PApplet {
6  
7  
/* *************  L3Dnam - may2015  ****************** 
8  
This sketch demonstrate how to use PNG images from a gauge and an arrow, to make a fully functional
9  
"real like" Gauge responding for the Mouse-X movement, showing angles for a Servo position (0º to 180º) 
10  
for example!  Need 2 PNG images on Data subFolder inside the Sketch folder.
11  
Marshall B&P gauge.png  and  marshall B&P ponteiro.png. -->  Both images must have no Background.
12  
Create your own png images from real gauges or Other Objetcs and Enjoy.
13  
*/
14  
15  
PImage mostrador, ponteiro; //both images on DATA subfolder
16  
PFont fontA;
17  
int Tx, Ty, P0, P180;       // Tx/Ty position text indicator  P0/P180 start & End point of Arrow
18  
int Wsize1 = 300;   //Wsize1  &  Wsize2 = tamanho janela 
19  
int Wsize2 = 300;
20  
int gauge;       // Gauge1 and Gauge2 are 2 example gauges,  choose one of them on line 20
21  
22  
void settings() {
23  
  size (Wsize1,Wsize2 /*,OPENGL XXX*/);
24  
}
25  
26  
void setup() {
27  
/******************************************************************/  
28  
 gauge = 1;     // Gauge Type 1,  choose 2 for another Gauge
29  
/******************************************************************/   
30  
switch (gauge) {
31  
  case 1: 
32  
      mostrador = loadImage(loadImageAsFilePath(#1101160)/*"Gauge B&P Marshall 180.png"*/);
33  
      ponteiro = loadImage(loadImageAsFilePath(#1101161)/*"marshall B&P ponteiro.png"*/); //loadImage("Ponteiro_Vermelho.png");
34  
      Tx=-20 ;  Ty=58; P0=0  ;  P180=272 ;
35  
    break;
36  
  case 2: 
37  
      mostrador = loadImage("gauge.png");
38  
      ponteiro = loadImage(loadImageAsFilePath(#1101162)/*"Ponteiro_Vermelho.png"*/); //loadImage("Ponteiro_Vermelho.png");
39  
      Tx=-17 ;  Ty=74; P0=-226  ;  P180=46 ;
40  
    break;
41  
 }
42  
 imageMode(CENTER);
43  
 fontA = createFont(libraryPath(#1014271/*"dutcheb.ttf"*/), 20); //numeric indication of the Angle
44  
 textFont(fontA);
45  
 
46  
 // Uncomment the following two lines to see the available fonts 
47  
 // String[] fontList = PFont.list();
48  
 //  printArray(fontList);
49  
}
50  
51  
52  
void draw() {
53  
  background(177);
54  
  stroke(153);
55  
  translate(Wsize1/2, Wsize2/2); // posiciona o mostrador no centro da tela
56  
  image(mostrador, 0 , 0 , Wsize1*0.9f, Wsize2*0.9f); // imagem, coluna, linha, Widt, Height
57  
  float rodar = map(mouseX, 0,width,P0,P180); //mouseX movement 0 & 360 grauss for Arrow
58  
  float angulo = map(mouseX, 0,width,0,181); //Numeric mouseX movement 0 & 360 grauss
59  
     fill(255,255,255);                      // Text Color = Blank
60  
     text((int) angulo, Tx,Ty);              // Position of Text with Numeric Angle
61  
     rotate(radians((int) rodar));            // Rotate the Arrow as "rodar" value
62  
switch(gauge) {
63  
  case 1: 
64  
      image(ponteiro, -22.9f, 23.1f, Wsize1*0.33f, Wsize2*0.33f); // imagem, coluna, linha, Widt, Height
65  
    break;
66  
  case 2: 
67  
      image(ponteiro, 21.5f, 0.2f, Wsize1*0.43f, Wsize2*0.06f); // imagem, coluna, linha, Widt, Height
68  
    break;     
69  
  }
70  
}
71  
72  
}

Author comment

https://github.com/L3Dnam/Professional-Gauges-with-Processing

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1014268
Snippet name: Processing: "Marshall Servo Position" Gauge with background image (OK)
Eternal ID of this version: #1014268/14
Text MD5: 86fd1717f793cab1d2414b5a7042f539
Transpilation MD5: 7a3c58308ba66563cd11a86500a635bf
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 16:12:05
Source code size: 2978 bytes / 72 lines
Pitched / IR pitched: No / No
Views / Downloads: 427 / 1794
Version history: 13 change(s)
Referenced in: [show references]