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).

sclass JAmplitudeGraph extends JComponent {
  float[] values;

  public void paint(Graphics g) {
    int w = getWidth(), h = getHeight();
    fillRect(g, 0, 0, w, h, getBackground());
    float[] values = this.values;
    if (empty(values)) ret;
    Color fg = getForeground();
    double factor = doubleRatio(l(values), w);
    for x to w: {
      int i1 = min(l(values)-1, ifloor(x*factor));
      int i2 = max(i1+1, ifloor((x+1)*factor));
      float val = 0;
      for (int i = i1; i < i2; i++) val = max(val, values[i]);
      int y = iround(val*h);
      fillRect(g, x, h-y, 1, y, fg);
    }
  }
  
  void setValues(float[] values) {
    this.values = values;
    repaint();
  }
}

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: 259 / 689
Version history: 9 change(s)
Referenced in: #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)