erhankubat@hotmail.com
digital technology

Processing ile görsel sinüs dalga oluşturma

// Sinüs Dalga Oluşturma ve Düzenleme Hazırlayan Erhan Kubat 01.03.2021
ArrayList<Dalga> sinus = new ArrayList<Dalga>();
void setup() {
  size(1920, 1024);
  frameRate(600);
  sinus.add(new Dalga());
  sinus.add(new Dalga());
  sinus.get(1).x1 = 550;
  sinus.get(1).x2 = 750;
  sinus.get(1).x3 = 750;
  sinus.get(1).x4 = 950;
  sinus.add(new Dalga());
  sinus.get(2).y1 = 400;
  sinus.get(2).y2 = 300;
  sinus.get(2).y3 = 500;
  sinus.get(2).y4 = 400;
}
void draw() {
  arkaPlan();
  mouseMove();
}
void mouseMove() {
  for (int x=0; x<sinus.size(); x++) { // < <
    sinus.get(x).mouseMoveT();
    if (mouseX > sinus.get(x).x4-10 && mouseX < sinus.get(x).x4+10 && 
        mouseY > sinus.get(x).y4-10 && mouseY < sinus.get(x).y4+10 ||
        mouseX > sinus.get(x).x3-10 && mouseX < sinus.get(x).x3+10 && 
        mouseY > sinus.get(x).y3-10 && mouseY < sinus.get(x).y3+10 ||
        mouseX > sinus.get(x).x2-10 && mouseX < sinus.get(x).x2+10 && 
        mouseY > sinus.get(x).y2-10 && mouseY < sinus.get(x).y2+10 ||
        mouseX > sinus.get(x).x1-10 && mouseX < sinus.get(x).x1+10 && 
        mouseY > sinus.get(x).y1-10 && mouseY < sinus.get(x).y1+10) {
      cursor(HAND);
    } else cursor(ARROW);
  }
}
void mousePressed() {
  for (int x=0; x<sinus.size(); x++) sinus.get(x).mousePressedT();
}
void mouseReleased() {
  for (int x=0; x<sinus.size(); x++) sinus.get(x).mouseReleasedT();
}
void arkaPlan() {
  background(200);
  stroke(155);
  for (int x=0; x<width; x+=50) {
    line(0, x, width, x);
    fill(255);
    text(x, x+1, 10);
  }
  for (int x=0; x<width; x+=50) {
    line(x, 0, x, height);
    fill(255);
    text(x, 1, x);
  }
  stroke(190);
  for (int x=25; x<width; x+=50) {
    line(0, x, width, x);
  }
  for (int x=25; x<width; x+=50) {
    line(x, 0, x, height);
  }
}

class Dalga {
int x1 = 50;
int y1 = 200;
int x2 = 250;
int y2 = 100;
int x3 = 250;
int y3 = 300;
int x4 = 450;
int y4 = 200;
int adim = 25;
  int xSakla1=x1, 
      ySakla1=y1, 
      xSakla2=x2, 
      ySakla2=y2, 
      xSakla3=x3, 
      ySakla3=y3, 
      xSakla4=x4, 
      ySakla4=y4;
  boolean sakla4=false;
  boolean sakla3=false;
  boolean sakla2=false;
  boolean sakla1=false;  
  public Dalga() {
    stroke(0);
    noFill();
    bezier(x1, y1, x2, y2, x3, y3, x4, y4);
    stroke(255, 255, 200);
    line(x1, y1, x2, y2);
    line(x3, y3, x4, y4);
  }
  void mouseMoveT() {
    stroke(0);
    noFill();
    bezier(x1, y1, x2, y2, x3, y3, x4, y4);
    stroke(255, 255, 200);
    line(x1, y1, x2, y2);
    line(x3, y3, x4, y4);
    text("x1 "+ x1, x1, y1+10); 
    text("y1 "+ y1, x1, y1+20);
    text("x2 "+ x2, x2, y2+10); 
    text("y2 "+ y2, x2, y2+20);
    text("x3 "+ x3, x3, y3+10); 
    text("y3 "+ y3, x3, y3+20);
    text("x4 "+ x4, x4, y4+10); 
    text("y4 "+ y4, x4, y4+20);
    if (sakla4) {
      x4=mouseX;
      y4=mouseY;
    }
    if (sakla3) {
      x3=mouseX;
      y3=mouseY;
    }
    if (sakla2) {
      x2=mouseX;
      y2=mouseY;
    }
    if (sakla1) {
      x1=mouseX;
      y1=mouseY;
    }
  }
  void mousePressedT() {
    if (mouseX > x4-10 && mouseX < x4+10 && mouseY > y4-10 && mouseY < y4+10) {
      xSakla4 = x4;
      ySakla4 = y4;
      sakla4=true;
    }
    if (mouseX > x3-10 && mouseX < x3+10 && mouseY > y3-10 && mouseY < y3+10) {
      xSakla3 = x3;
      ySakla3 = y3;
      sakla3=true;
    }
    if (mouseX > x2-10 && mouseX < x2+10 && mouseY > y2-10 && mouseY < y2+10) {
      xSakla2 = x2;
      ySakla2 = y2;
      sakla2=true;
    }
    if (mouseX > x1-10 && mouseX < x1+10 && mouseY > y1-10 && mouseY < y1+10) {
      xSakla1 = x1;
      ySakla1 = y1;
      sakla1=true;
    }
  }
  void mouseReleasedT() {
    if (sakla4) {
      sakla4=false;
      x4=((int)mouseX/25) * 25;
      y4=((int)mouseY/25) * 25;
      if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {
        xSakla4 = x4;
        ySakla4 = y4;
      }
    }
    if (sakla3) {
      sakla3=false;
      x3=((int)mouseX/25) * 25;
      y3=((int)mouseY/25) * 25;
      if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {
        xSakla3 = x3;
        ySakla3 = y3;
      }
    }
    if (sakla2) {
      sakla2=false;
      x2=((int)mouseX/25) * 25;
      y2=((int)mouseY/25) * 25;
      if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {
        xSakla2 = x2;
        ySakla2 = y2;
      }
    }
    if (sakla1) {
      sakla1=false;
      x1=((int)mouseX/25) * 25;
      y1=((int)mouseY/25) * 25;
      if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {
        xSakla1 = x1;
        ySakla1 = y1;
      }
    } 
  }
}