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

79
LINES

< > BotCompany Repo | #1016727 // PGauge_processing2 - gauge display in Processing 2

JavaX fragment (include) [tags: archive]

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

Author comment

Began life as a copy of #1014275

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): cfunsshuasjs, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1016727
Snippet name: PGauge_processing2 - gauge display in Processing 2
Eternal ID of this version: #1016727/3
Text MD5: 31d02287b6633f7451f965cc9a3a4fe9
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): Yes
Created/modified: 2018-06-30 14:57:36
Source code size: 2844 bytes / 79 lines
Pitched / IR pitched: No / No
Views / Downloads: 375 / 405
Version history: 2 change(s)
Referenced in: [show references]