<commit_before>import processing.sound.*;
SoundFile music;

FFT fft;
Amplitude amp;
int bands = 512;
float[] sum = new float[bands];

float smoothFactor = 0.2;

float min = 2000;

Segment firstSeg, lastSeg;

int numSegs = 0;
int segSize = 5;

PVector startPoint = new PVector(400, 300);

float factor = 1;

void setup() {
  
  size(2560, 1440, P2D);
  fill(128);
  noStroke();
  //stroke(255);
  colorMode(HSB, 255);
  
  // music
  music = new SoundFile(this, "play.mp3");
  music.loop();
  
  fft = new FFT(this, bands);
  fft.input(music);
  
  background(32);
  
}

void draw() {
  
  //background(32);
  fill(32, 32);
  rect(0, 0, width, height);
  fill((getFourier(bands) * 3 + 96) % 255, 128, 255, 4);
  rect(0, 0, width, height);
  fill((getFourier(bands) * 3 + 96) % 255, 128, 255);
  
  fft.analyze();
  
  for (int i = 0; i < bands; i++) {
    
    sum[i] += (fft.spectrum[i] - sum[i]) * smoothFactor;
    
  }
  
  if (firstSeg != null) {
    
    firstSeg.update();
    
    beginShape();
    {
      //vertex(startPoint.x, startPoint.y, firstSeg.startNormal().x, firstSeg.startNormal().y);
      
      firstSeg.drawVis();
      firstSeg.drawBase();
    }
    endShape();
    
  }
  
}

void addSegment() {
  
  if (firstSeg == null) {
    
    lastSeg = firstSeg = new Segment(mouseX, mouseY, mouseX, mouseY);
    numSegs = 1;
    
  }
  
  if (dist(lastSeg.end.x, lastSeg.end.y, mouseX, mouseY) > segSize) {
    
    lastSeg.addSegment(new Segment(lastSeg.end.x, lastSeg.end.y, mouseX, mouseY));
    
  }
  
}

void keyPressed() {
  
  switch(keyCode) {
    case 82: // R (reset)
      firstSeg = null;
      lastSeg = null;
      numSegs = 0;
      break;
    case 83: // S (set start)
      startPoint.x = mouseX;
      startPoint.y = mouseY;
      min = 1000;
      break;
    default:
      println(keyCode);
  }
  
}

void mouseClicked() { addSegment(); }
void mouseDragged() { addSegment(); }

float getFourier(int n) {
  
  //return (sin((float) n / 10 + ((float)frameCount / 20)) + 1) * 50;
  //println(spectrum[n % bands]);
  //return spectrum[n % bands] * 200 * factor;
  
  float t = 100 * sum[n % (bands / 2)] * (n % (bands / 2) + 1) - 0.25;
  if (t < min && t > 0) {
    min = t;
    println(min);
  }
  return t;
}

class Segment {
  
  PVector start, end;
  PVector normal;<commit_msg>Removed neg sizes in draw vis<commit_after>import processing.sound.*;
SoundFile music;

FFT fft;
Amplitude amp;
int bands = 512;
float[] sum = new float[bands];

float smoothFactor = 0.2;

float min = 2000;

Segment firstSeg, lastSeg;

int numSegs = 0;
int segSize = 5;

PVector startPoint = new PVector(400, 300);

float factor = 1;

void setup() {
  
  size(2560, 1440, P2D);
  fill(128);
  noStroke();
  //stroke(255);
  colorMode(HSB, 255);
  
  // music
  music = new SoundFile(this, "play.mp3");
  music.loop();
  
  fft = new FFT(this, bands);
  fft.input(music);
  
  background(32);
  
}

void draw() {
  
  //background(32);
  fill(32, 32);
  rect(0, 0, width, height);
  fill((getFourier(bands) * 3 + 96) % 255, 128, 255, 4);
  rect(0, 0, width, height);
  fill((getFourier(bands) * 3 + 96) % 255, 128, 255);
  
  fft.analyze();
  
  for (int i = 0; i < bands; i++) {
    
    sum[i] += (fft.spectrum[i] - sum[i]) * smoothFactor;
    
  }
  
  if (firstSeg != null) {
    
    firstSeg.update();
    
    beginShape();
    {
      //vertex(startPoint.x, startPoint.y, firstSeg.startNormal().x, firstSeg.startNormal().y);
      
      firstSeg.drawVis();
      firstSeg.drawBase();
    }
    endShape();
    
  }
  
}

void addSegment() {
  
  if (firstSeg == null) {
    
    lastSeg = firstSeg = new Segment(mouseX, mouseY, mouseX, mouseY);
    numSegs = 1;
    
  }
  
  if (dist(lastSeg.end.x, lastSeg.end.y, mouseX, mouseY) > segSize) {
    
    lastSeg.addSegment(new Segment(lastSeg.end.x, lastSeg.end.y, mouseX, mouseY));
    
  }
  
}

void keyPressed() {
  
  switch(keyCode) {
    case 82: // R (reset)
      firstSeg = null;
      lastSeg = null;
      numSegs = 0;
      break;
    case 83: // S (set start)
      startPoint.x = mouseX;
      startPoint.y = mouseY;
      min = 1000;
      break;
    default:
      println(keyCode);
  }
  
}

void mouseClicked() { addSegment(); }
void mouseDragged() { addSegment(); }

float getFourier(int n) {
  
  //return (sin((float) n / 10 + ((float)frameCount / 20)) + 1) * 50;
  //println(spectrum[n % bands]);
  //return spectrum[n % bands] * 200 * factor;
  
  return 100 * sum[n % (bands / 2)] * (n % (bands / 2) + 1);
}

class Segment {
  
  PVector start, end;
  PVector normal;
{'fraction_non_alphanumeric': 0.16363636363636364, 'fraction_numerical': 0.045125958378970425, 'mean_word_length': 2.453857791225416, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3850174', 'n_tokens_mistral': 1967, 'n_tokens_neox': 1771, 'n_words': 422}