can someone explain to me how this code does what it does without any libaries ?

JaiJai
edited February 2016 in Questions about Code
boolean overLeftButton = false;
boolean overRightButton = false;

void setup() {
  size(200, 200);
}

void draw() {
  background(204);

  // Left buttom
  if (overLeftButton == true) {
    fill(255);
  } else {
    noFill();
  }
  rect(20, 60, 75, 75);
  rect(50, 90, 15, 15);

  // Right button
  if (overRightButton == true) {
    fill(255);
  } else {
    noFill();
  }
  rect(105, 60, 75, 75);
  line(135, 105, 155, 85);
  line(140, 85, 155, 85);
  line(155, 85, 155, 100);
}

void mousePressed() {
  if (overLeftButton) { 
    link("http:" + "//www.processing.org");
  } else if (overRightButton) {
    link("http:" + "//www.processing.org", "_new");
  }
}

void mouseMoved() { 
  checkButtons(); 
}

void mouseDragged() {
  checkButtons(); 
}

void checkButtons() {
  if (mouseX > 20 && mouseX < 95 && mouseY > 60 && mouseY < 135) {
    overLeftButton = true;   
  } else if (mouseX > 105 && mouseX < 180 && mouseY > 60 && mouseY <135) {
    overRightButton = true; 
  } else {
    overLeftButton = overRightButton = false;
  }
}

Answers

  • There is no clear shell commands from my pc telling it to open my browser nor any class or code saying anything remotely "here open this page" i seen code that does this type of action and is far more complex/detail in its approach.

  • Answer ✓

    lines 24 and 36, link()

    it's not in the reference but a quick search of the forum brings up this, which suggests it used to exist:

    https://forum.processing.org/one/topic/link-opening-hundreds-of-web-pages.html

  • right so if it used to exist how is it still working ? does this mean i can use this link() to call searches online ? i try using link("http:" + "//www.google.com", "_processing"); hoping i would open up a page with the processing search already performed but nothing just straight to google.

  • edited February 2016

    Which version of processing are you running? I'm running 3.0.1 and I get an error saying the method link(String) isn't applicable for the arguments (String, String), referring to line 36.

  • i'm guessing it still exists in the code but is no longer in the reference.

    the second argument to the call isn't defined anywhere but i doubt you can just put _processing in there. _new feels like a reserved word

    hoping i would open up a page with the processing search already performed but nothing just straight to google

    try

    link("https:" + "//www.google.co.uk/search?q=site:processing.org+" + keyword);
    
  • JaiJai
    edited February 2016

    no i get what you guys are saying, and no _new is not a reserved syntax else i would have had an error when i ran the code. and the link("https:" + "//www.google.co.uk/search?q=site:processing.org+" + keyword); will work because your telling it explicitly where to go to if you was to paste that in any browser you would get directed to where the link says the thing was to make a variable with many diff addresses or even better to use the sound library to have the mic input the word you want to search and that will get placed in the constructor to that '_new" and now when you run the code it will work with that new word capture by the mic which will already have had a variable store in the global

  • edited February 2016

    AFaIK, link() always existed even as far back as Processing 1.5.1.
    We can still see its web reference from pJS site: http://ProcessingJS.org/reference/link_/
    Some forum threads w/ link() tag: https://forum.Processing.org/two/discussions/tagged?Tag=link()

    P.S.: I've tried out to include links() in p5.js lib. Unfortunately it was refused w/ prejudice: X(
    https://GitHub.com/processing/p5.js/pull/532

  • hmmm thats funny prejudice

  • JaiJai
    edited February 2016

    so theres no way to make use of that link("http:" + "//www.google.com", "_processing");? for search query

  • edited February 2016

    Hmmm... that's funny "prejudice".

    Yes, prejudice! B/c not only in that particular time, but all times, she had sided w/ the JS side in all matters.
    There wasn't even a single time where she had favored Processing's familiarity when a JS-sided voice was raised!
    BtW, there ain't 1 Processing side voice there for years. I was the only 1. [-(

  • boolean overLeftButton = false;
    boolean overRightButton = false;
    
    void setup() {
      size(200, 200);
    }
    
    void draw() {
      background(204);
    
      // Left buttom
      if (overLeftButton == true) {
        fill(255);
      } else {
        noFill();
      }
      rect(20, 60, 75, 75);
      rect(50, 90, 15, 15);
    
      // Right button
      if (overRightButton == true) {
        fill(255);
      } else {
        noFill();
      }
      rect(105, 60, 75, 75);
      line(135, 105, 155, 85);
      line(140, 85, 155, 85);
      line(155, 85, 155, 100);
    }
    
    void mousePressed() {
      if (overLeftButton) { 
        link("http:" + "//www.processing.org");
        overLeftButton = false;
        overRightButton = false;
      } else if (overRightButton) {
        link("https:"
          +"//www.google.de/search?q="
          +"processing"
          +"&ie=utf-8&oe=utf-8");
        overLeftButton = false;
        overRightButton = false;
      }
    }
    
    void mouseMoved() { 
      checkButtons();
    }
    
    void mouseDragged() {
      checkButtons();
    }
    
    void checkButtons() {
      if (mouseX > 20 && mouseX < 95 && mouseY > 60 && mouseY < 135) {
        overLeftButton = true;
      } else if (mouseX > 105 && mouseX < 180 && mouseY > 60 && mouseY <135) {
        overRightButton = true;
      } else {
        overLeftButton = overRightButton = false;
      }
    }
    
  • Chrisir thanks for the effort but this is not using any variables to call on a query, this is doing the same thing that koogs already suggested, what we needed was a way to set a variable var/int/char/string = Tomatoes; //what ever lol then use that variable to change its search when place in the link("https:"+"//www.google.com/search?q="+VARIABLE HERE);

  • This variable will change according to the input from the microphone and its input then will be stored in the variable

  • can you grab the input from the microphone and turn it into text?

  • yes, im using arduino for the HW setup and serial to tx to processing i can even use visual studio to do this using the speech engine in the pc as well

  • parsing XML files with preloaded data is another technique

  • edited February 2016 Answer ✓
    String myTextInput;
    
    //     myTextInput = ......... ; //  get this from Mic; e.g.
    myTextInput = "processing"; 
    
         link("https:"
              +"//www.google.de/search?q="
              +myTextInput
              +"&ie=utf-8&oe=utf-8");
    
  • thanks Chrisir! when i finish i the entire setup ill post here to share with the community

  • Answer ✓

    Thank you, Jai!

Sign In or Register to comment.