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

25
LINES

< > BotCompany Repo | #1024600 // JAmplitudeGraph

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (2389L/15K).

1  
sclass JAmplitudeGraph extends JComponent {
2  
  float[] values;
3  
4  
  public void paint(Graphics g) {
5  
    int w = getWidth(), h = getHeight();
6  
    fillRect(g, 0, 0, w, h, getBackground());
7  
    float[] values = this.values;
8  
    if (empty(values)) ret;
9  
    Color fg = getForeground();
10  
    double factor = doubleRatio(l(values), w);
11  
    for x to w: {
12  
      int i1 = min(l(values)-1, ifloor(x*factor));
13  
      int i2 = max(i1+1, ifloor((x+1)*factor));
14  
      float val = 0;
15  
      for (int i = i1; i < i2; i++) val = max(val, values[i]);
16  
      int y = iround(val*h);
17  
      fillRect(g, x, h-y, 1, y, fg);
18  
    }
19  
  }
20  
  
21  
  void setValues(float[] values) {
22  
    this.values = values;
23  
    repaint();
24  
  }
25  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1024600
Snippet name: JAmplitudeGraph
Eternal ID of this version: #1024600/10
Text MD5: 3a33276da73b70c9e9fd8952cedaa3e2
Transpilation MD5: d7a22034fdaf638eadfcbdb2ce0b4b36
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-08-19 20:40:54
Source code size: 710 bytes / 25 lines
Pitched / IR pitched: No / No
Views / Downloads: 194 / 600
Version history: 9 change(s)
Referenced in: [show references]