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

81
LINES

< > BotCompany Repo | #1014275 // PGauge - gauge display in Processing

JavaX fragment (include)

1  
sclass PGauge extends PApplet2 {
2  
3  
  PImage mostrador, ponteiro; //both images on DATA subfolder
4  
  PFont fontA;
5  
  int Tx, Ty, P0, P180;       // Tx/Ty position text indicator  P0/P180 start & End point of Arrow
6  
  int Wsize1 = 300;   //Wsize1  &  Wsize2 = tamanho janela 
7  
  int Wsize2 = 300;
8  
  int gauge = 1; // Gauge1 and Gauge2 are 2 example gauges
9  
  float value, maxValue = 180, precision = 0.1f;
10  
  bool demo;
11  
  
12  
  void mouseMoved() {
13  
    if (demo)
14  
      setValue(map(mouseX, 0, width, 0, maxValue));
15  
  }
16  
  
17  
  bool setValue(double newValue, S title) {
18  
    setTitle(title);
19  
    ret setValue(newValue);
20  
  }
21  
  
22  
  bool setValue(double newValue) {
23  
    ret setValue((float) newValue);
24  
  }
25  
  
26  
  bool setValue(float newValue) {
27  
    float oldValue = value;
28  
    value = newValue;
29  
    if (floorRatio(oldValue, precision) != floorRatio(newValue, precision))
30  
      ret true with redraw();
31  
    false;
32  
  }
33  
  
34  
  void settings() {
35  
    size (Wsize1,Wsize2 /*,OPENGL XXX*/);
36  
  }
37  
  
38  
  void setup() {
39  
    super.setup();
40  
  switch (gauge) {
41  
    case 1: 
42  
        mostrador = loadImage(loadImageAsFilePath(#1101160)/*"Gauge B&P Marshall 180.png"*/);
43  
        ponteiro = loadImage(loadImageAsFilePath(#1101161)/*"marshall B&P ponteiro.png"*/); //loadImage("Ponteiro_Vermelho.png");
44  
        Tx=-20 ;  Ty=58; P0=0  ;  P180=272 ;
45  
      break;
46  
    case 2: 
47  
        mostrador = loadImage(loadImageAsFilePath(#1101163)/*"gauge.png"*/);
48  
        ponteiro = loadImage(loadImageAsFilePath(#1101162)/*"Ponteiro_Vermelho.png"*/); //loadImage("Ponteiro_Vermelho.png");
49  
        Tx=-17 ;  Ty=74; P0=-226  ;  P180=46 ;
50  
      break;
51  
   }
52  
   imageMode(CENTER);
53  
   fontA = createFont(libraryPath(#1014271/*"dutcheb.ttf"*/), 20); //numeric indication of the Angle
54  
   textFont(fontA);
55  
   
56  
   noLoop();
57  
  }
58  
  
59  
  
60  
  void draw() {
61  
    background(177);
62  
    stroke(153);
63  
    translate(Wsize1/2, Wsize2/2); // posiciona o mostrador no centro da tela
64  
    image(mostrador, 0 , 0 , Wsize1*0.9f, Wsize2*0.9f); // imagem, coluna, linha, Widt, Height
65  
    float rodar = min(P180*1.05f, map(value, 0,maxValue,P0,P180)); //mouseX movement 0 & 360 grauss for Arrow
66  
    float angulo = map(value, 0,maxValue,0,181); //Numeric mouseX movement 0 & 360 grauss
67  
       fill(255,255,255);                      // Text Color = Blank
68  
       text((int) angulo, Tx,Ty);              // Position of Text with Numeric Angle
69  
       rotate(radians((int) rodar));            // Rotate the Arrow as "rodar" value
70  
  switch(gauge) {
71  
    case 1: 
72  
        image(ponteiro, -22.9f, 23.1f, Wsize1*0.33f, Wsize2*0.33f); // imagem, coluna, linha, Widt, Height
73  
      break;
74  
    case 2: 
75  
        image(ponteiro, 21.5f, 0.2f, Wsize1*0.43f, Wsize2*0.06f); // imagem, coluna, linha, Widt, Height
76  
      break;     
77  
    }
78  
  }
79  
  
80  
  PGauge type(int type) { gauge = type; this; }
81  
}

Author comment

Began life as a copy of #1014272

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1014275
Snippet name: PGauge - gauge display in Processing
Eternal ID of this version: #1014275/19
Text MD5: 51a61742980ed4322a037085e77aa49d
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-06-30 15:35:49
Source code size: 2861 bytes / 81 lines
Pitched / IR pitched: No / No
Views / Downloads: 348 / 920
Version history: 18 change(s)
Referenced in: [show references]