computerscare-vcv-modules

ComputerScare modules for VCV Rack
Log | Files | Refs

pointFunctions.hpp (1449B)


      1 #pragma once
      2 
      3 namespace rack {
      4 namespace app {
      5 struct Points {
      6 
      7   std::vector<Vec> points;
      8   Points() {
      9 
     10   }
     11   void linear(int num, Vec offset, Vec slope) {
     12     points.resize(num);
     13     for (int i = 0; i < num; i++) {
     14       points[i] = Vec(offset.x + slope.x * i / num, offset.y + slope.y * i / num);
     15     }
     16   }
     17   void grid(int numx, int numy, Vec size) {
     18     int N = numx * numy;
     19     points.resize(N);
     20     for (int i = 0; i < N; i++) {
     21       points[i] = Vec((i % numx) * size.x, (i - i % numx) / numx * size.y);
     22     }
     23   }
     24   void triangle(Vec lengths, Vec angles) {
     25     points.resize(3);
     26     points[0] = Vec(0, 0);
     27     Vec b = Vec(lengths.x * cos(angles.x), lengths.x * sin(angles.x));
     28     Vec cMinusB = Vec(lengths.y * cos(angles.y), lengths.y * sin(angles.y));
     29     points[1] = b;
     30     points[2] = b.plus(cMinusB);
     31   }
     32   void spray(int n) {
     33     points.resize(n);
     34     for (int i = 0; i < n; i++) {
     35       points[i] = Vec(random::normal(), random::normal());
     36     }
     37   }
     38   void offset(Vec dz) {
     39     for (unsigned int i = 0; i < points.size(); i++) {
     40       points[i] = points[i].plus(dz);
     41     }
     42   }
     43   void scale(Vec s) {
     44     for (unsigned int i = 0; i < points.size(); i++) {
     45       points[i] = points[i].mult(s);
     46     }
     47   }
     48   void waveBlob() {
     49 
     50   }
     51   void wtf(float buf[16][512]) {
     52     int n = buf[0][0] * (1 + buf[1][0]);
     53     for (int i = 0; i < n; i++) {
     54       points.push_back(Vec(i, i));
     55     }
     56   }
     57   std::vector<Vec> get() {
     58     return points;
     59   }
     60 };
     61 }
     62 }