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

35
LINES

< > BotCompany Repo | #1006365 // rgbMakeGraph

JavaX fragment (include)

sclass rgbMakeGraph_Info {
  // input
  float overdrive = 1f;
  
  // output
  float min, max;
  
  public S toString() {
    ret "min: " + min + ", max: " + max;
  }
}

static RGBImage rgbMakeGraph(float[] data) {
  ret rgbMakeGraph(data, null);
}

static RGBImage rgbMakeGraph(float[] data, rgbMakeGraph_Info info) {
  if (empty(data)) ret new RGBImage(1, 1);
  float min = min(data), max = max(min+0.0001f, max(data));
  if (info != null) {
    info.min = min;
    info.max = max;
  }
  int w = l(data), h = 60;
  RGBImage img = new RGBImage(w, h, Color.white);
  Color foreground = Color.red;
  for x to w: {
    float f = (data[x]-min)/(max-min);
    if (info != null) f *= info.overdrive;
    int y1 = max(0, iround(h*(1-f)));
    for (int y = y1; y < h; y++)
      img.setPixel(x, y, foreground);
  }
  ret img;
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1006365
Snippet name: rgbMakeGraph
Eternal ID of this version: #1006365/1
Text MD5: bdc85dc1260d1b6a0350751ac8d9427a
Author: stefan
Category: javax / imaging
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-12-29 22:16:24
Source code size: 854 bytes / 35 lines
Pitched / IR pitched: No / No
Views / Downloads: 576 / 576
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)