Loading...
Logo
Processing Forum
leanderlike's Profile
18 Posts
19 Responses
0 Followers

Activity Trend

Last 30 days

Loading Chart...

Show:
Private Message
    Hello experts, 

    I'm running a sketch in fullscreen mode on a Mac. The user has to control the sketch using the keyboard. 
    On a Mac you can quit a sketch using the "command+q". I don't want the user to do this, so do you have any idea how to block all system related shortcuts on a keyboard?. Probably this is rather a question for a mac-user forum, but I hope you have some ideas!!

    Thanks!!!
    Hello, 

    in my sketch I want to capture an image with my webcam (just one single image not an image capturing all the time). 
    After that I want to place an animation on top of it. So in the sketch below you should take a picture and then an ellipse moves over the screen and over the image. 

    My Problem: For an animation I think I need to call "background" all the time. When doing this my captured image from the webcam is gone, as the background lays over it. Is there any simple way to work around this problem?
    This would be great!! 
    1. import processing.video.*;
    2. boolean animation = false; 
    3. int ellipseX = 0; 

    4. Capture myCapture; 

    5. void setup() {
    6.   size (800, 600); 
    7.   smooth();
    8.   noStroke();
    9.   myCapture = new Capture(this, width/3, height/3, 30);
    10.   ellipseMode(CENTER);
    11. }

    12. void draw() {
    13.   if (animation) animation();
    14. }

    15. void foto() {
    16.   image(myCapture, 0, 0, width, height);
    17.   filter(GRAY);
    18. }

    19. void mouseReleased() {
    20.   foto();
    21.   animation = true;
    22. }

    23. void animation() {
    24.   ellipseX +=5;
    25.   if (ellipseX > width) {
    26.     ellipseX = 0;
    27.   }
    28.   ellipse (ellipseX, 100, 20, 20);
    29. }

    30. void captureEvent(Capture myCapture) {
    31.   myCapture.read();
    32. }

    Hallo, 

    I'm working with the Keystone Library and I want to move and control the two layers seperately. So when pressing 'c' I only want to move and control the red layer and when pressing 'v' only the green layer should be moved. 
    As it's much easier to control the position of the layers when only one layer is selected. 
    I hope you guys may help me!!! When executing my script both layers are moveable when pressing either 'c' oder 'v'. 

    1. import deadpixel.keystone.*;

    2. Keystone ksRed;
    3. Keystone ksGreen; 
    4. CornerPinSurface surfaceRed, surfaceGreen;

    5. PGraphics offscreenRed, offscreenGreen;

    6. void setup() {
    7.   size(800, 600, P3D);
    8.   ksRed = new Keystone(this);
    9.   ksGreen = new Keystone(this);

    10.   surfaceRed = ksRed.createCornerPinSurface(400, 300, 20);
    11.   offscreenRed = createGraphics(400, 300, P2D);

    12.   surfaceGreen = ksGreen.createCornerPinSurface(200, 150, 20);
    13.   offscreenGreen = createGraphics(200, 150, P2D);
    14. }

    15. void draw() {
    16.   offscreenRed.beginDraw();
    17.   offscreenRed.background(255, 30, 0);
    18.   offscreenRed.endDraw();

    19.   offscreenGreen.beginDraw();
    20.   offscreenGreen.background(0, 255, 30);
    21.   offscreenGreen.endDraw();

    22.   background(0);

    23.   surfaceRed.render(offscreenRed);
    24.   surfaceGreen.render(offscreenGreen);
    25. }

    26. void keyPressed() {
    27.   switch(key) {
    28.   case 'c':
    29.     ksGreen.toggleCalibration();
    30.     break;
    31.   case 'v':
    32.     ksRed.toggleCalibration();
    33.     break;
    34.   }
    35. }
    Hello, 

    when starting my script I want to capture an image from my webcam. 
    When pressing my mouse I want the image to be "freezed". When clicking the mouse again it should play again. 

    Right now it starts playing, but as soon as I stopped the capturing for the first time it doesn't play again. 

    1. import processing.video.*;
    2. Capture myCapture;
    3. boolean photo = true; 
    4. void setup() 
    5. {
    6.   size(screen.width, screen.height);
    7.   myCapture = new Capture(this, width, height, 30);
    8. }

    9. void captureEvent(Capture myCapture) {

    10.   myCapture.read();
    11. }

    12. void draw() {
    13.   image(myCapture, 0, 0);
    14.   filter(GRAY);
    15. }

    16. void mouseReleased() {
    17.   if (photo == true) {
    18.     myCapture.stop();
    19.     photo = false;
    20.   }
    21.   else if (photo == false) {
    22.     myCapture.read();
    23.     photo=true;
    24.   }
    25. }

    Hello, 

    I have a rather simple question, but can't figure out how to do it. 
    So I have a couple of String variables. I want to check whether they contain the combination #11#. 
    If so, I want to replace the #11# by a "and". 

    So let's say like this: 

    string1 = "Tony#11#Susan. It contains a #11# and I want to "rewrite" this String as "Tony and Susan". 

    I know that when using equals() I can check whether a whole string equals a specific word. 
    But I just want to check if there are certain parts of a string equal to my #11#. 

    I'm glad for any help!!!
    Hello, 

    I have a simple piece of code (see below). I don't want to save my xml file to the sketch folder, but to an external hard drive. 
    I guess all that is important to change is the following line of code. This is actually the destination I want to save the file to. 
    1.   xmlIO.saveElement(xmlPulses, "/Volumes/Public/Test/test.xml");
    Running the sketch like this it saves the xml inside my data folder and creates new subfolders calledVolumes/Public/Test and inside the "Test" folder it saves the xml.
    How do I get it to not create new folders but take the given destination and save it there? 

    1. import proxml.*;

    2. int posX; 
    3. int posY; 

    4. XMLInOut xmlIO;
    5. proxml.XMLElement xmlPulses;

    6. void setup() {
    7.   size(400, 400);
    8.     xmlIO = new XMLInOut(this);
    9.   try {
    10.     xmlIO.loadElement("test.xml");
    11.   } 
    12.   catch (Exception e) {
    13.     xmlEvent(new proxml.XMLElement("pulses"));
    14.   }
    15. }

    16. void xmlEvent(proxml.XMLElement element) {
    17.   xmlPulses = element;
    18. }

    19. void draw() {
    20.   background(0);
    21.   posX = mouseX;
    22.   posY = mouseY;
    23. }

    24. void mousePressed() {
    25.   saveData();
    26. }

    27. void saveData() {
    28.   proxml.XMLElement newPulse = new proxml.XMLElement("datensatz");
    29.   xmlPulses.addChild(newPulse);
    30.   proxml.XMLElement value1 = new proxml.XMLElement("value1");
    31.   proxml.XMLElement value2 = new proxml.XMLElement("value2");
    32.   value1.addAttribute("value1", posX);
    33.   value2.addAttribute("value2", posY);
    34.   newPulse.addChild(value1);   
    35.   newPulse.addChild(value2);    
    36.   xmlIO.saveElement(xmlPulses, "/Volumes/Public/Test/test.xml");
    37. }
    Hallo, 

    I'm just wondering if it is possible to load more than one xml file into a sketch. 
    I have several xml files of this structure. 

    1. <?xml version="1.0" encoding="ISO-8859-1"?>
    2. <pulses>
    3.    <circle>
    4.     <data posX="230" posY="121" col="200" rad="20"/>
    5.   </circle>
    6.    <circle>
    7.     <data posX="139" posY="201" col="130" rad="23"/>
    8.   </circle>
    9.    <circle>
    10.     <data posX="230" posY="243" col="54" rad="17"/>
    11.   </circle>
    12. </pulses>
    When executing the script it only loads and prints out all attributes of the first xml file.
    Is there a way how to load several xml files separately into one sketch? This would be great!!!!
    Thanks in advance!!

    1. import proxml.*;

    2. // ----------------------------------------------------------------------
    3. // GLOBAL VARIABLES
    4. // ----------------------------------------------------------------------
    5. XMLInOut xmlIO;
    6. XMLInOut xmlIO1;
    7. proxml.XMLElement myList;
    8. proxml.XMLElement myList1;

    9. // ----------------------------------------------------------------------
    10. // BUILT-IN FUNCTIONS
    11. // ----------------------------------------------------------------------
    12. void setup() {
    13.   size(400, 400);
    14.   readData();
    15.   readData1();
    16. }

    17. void xmlEvent(proxml.XMLElement element) {
    18.   myList = element;
    19.   myList1 = element;
    20. }

    21. void draw() {
    22. }

    23. // ----------------------------------------------------------------------
    24. // READ DATA
    25. // ----------------------------------------------------------------------

    26. void readData () {
    27.   xmlIO = new XMLInOut(this);
    28.   try {
    29.     xmlIO.loadElement("test.xml");
    30.   } 
    31.   catch (Exception e) {
    32.     xmlEvent(new proxml.XMLElement("myList"));
    33.   }
    34.   while (myList == null) {
    35.   }
    36.   proxml.XMLElement[] allData = myList.getChildren();
    37.   for (int i = 0; i< allData.length; i++) {
    38.     proxml.XMLElement data = allData[i];
    39.     proxml.XMLElement param = data.getChild(0);
    40.     if (!param.getName().equals("data")) continue;
    41.     String posX, posY, col, rad;
    42.     posX = param.getAttribute ("posX");
    43.     posY = param.getAttribute("posY");
    44.     col = param.getAttribute("col");
    45.     rad = param.getAttribute("rad");
    46.     println("posX:" + posX + " " + "posY:" + posY +  " " + "col:" + col + " " + "rad:" + rad);
    47.   }
    48. }


    49. void readData1() {
    50.   xmlIO1 = new XMLInOut(this);
    51.   try {
    52.     xmlIO1.loadElement("test1.xml");
    53.   } 
    54.   catch (Exception e) {
    55.     xmlEvent(new proxml.XMLElement("myList1"));
    56.   }
    57.   while (myList1 == null) {
    58.   }
    59.   proxml.XMLElement[] allData = myList1.getChildren();
    60.   for (int i = 0; i< allData.length; i++) {
    61.     proxml.XMLElement data = allData[i];
    62.     proxml.XMLElement param = data.getChild(0);
    63.     if (!param.getName().equals("data")) continue;
    64.     String posX, posY, col, rad;
    65.     posX = param.getAttribute ("posX");
    66.     posY = param.getAttribute("posY");
    67.     col = param.getAttribute("col");
    68.     rad = param.getAttribute("rad");
    69.     println("posX:" + posX + " " + "posY:" + posY +  " " + "col:" + col + " " + "rad:" + rad);
    70.   }
    71. }

    Hello, 

    I have a xml file containing some data and a processing sketch to read this data.
    Want I want to do:

    In my xml file I have several childs containing 4 attributes: Name, Surname, Age and City. 
    First I want to display the Name, 1 second later the surname, 1 second later the age and another second later the city. This animation has to work for the first three childs in my xml file at once. After about 6 seconds it has to display the 4th, 5th and 6th entry. And so on and so on. So no matter how many childs are in my xml file I only want to display three at one time. 

    Right now I am able to read through my whole xml file and get all of the children. But I only want the first three to appear with the animation of first showing the name, then the surname, age and the city. 
    Second Problem: As I want this as an animation I need to write my script into the draw(). Sadly the text becomes quite ugly as it overwrites the text every time it loops through draw. 
    Do have any suggestions how to figure this out? Do I need to use arrays or something to address the text outside the loop? I tried to work with pullMatrix () and pushMatrix() but this doesn't work. 

    So below you'll find my code so far and the content of my xml file. I'm glad for any help!!!!!

    XML FILE
    1. <?xml version="1.0" encoding="ISO-8859-1"?>
    2. <pulses>
    3.    <Person>
    4.     <werte name="John" surname="Smith" age="39" city="London"/>
    5.   </Person>
    6.    <Person>
    7.     <werte name="Claire" surname="Walker" age="22" city="Paris"/>
    8.   </Person>
    9.    <Person>
    10.     <werte name="Ron" surname="Bolton" age="34" city="Madrid"/>
    11.   </Person>
    12.    <Person>
    13.     <werte name="Chris" surname="Summer" age="28" city="Rome"/>
    14.   </Person>
    15.    <Person>
    16.     <werte name="Anne" surname="Gordon" age="26" city="Munich"/>
    17.   </Person>
    18.    <Person>
    19.     <werte name="Mary" surname="Miller" age="30" city="Barcelona"/>
    20.   </Person>
    21. </pulses>
    PROCESSING CODE
    1. import proxml.*;

    2. XMLInOut xmlIO;
    3. proxml.XMLElement myList;

    4. int w = 800; 
    5. int h = 600; 
    6. boolean readData = true; 
    7. String name, surname, city, age;
    8. PFont font; 

    9. void setup() {
    10.   size (w, h);
    11.   smooth();
    12.   font = createFont("Times", 60);
    13.   textFont(font);
    14.   xmlIO = new XMLInOut(this);
    15.   try {
    16.     xmlIO.loadElement("myData.xml");
    17.   } 
    18.   catch (Exception e) {
    19.     xmlEvent(new proxml.XMLElement("myList"));
    20.   }
    21. }

    22. void draw() {
    23.   if (readData) readData();
    24. }  

    25. void xmlEvent(proxml.XMLElement element) {
    26.   myList = element;
    27. }

    28. void readData () {
    29.   proxml.XMLElement[] allData = myList.getChildren();

    30.   for (int i = 0; i< allData.length; i++) {
    31.     proxml.XMLElement data = allData[i];
    32.     proxml.XMLElement param = data.getChild(0);
    33.     if (!param.getName().equals("werte")) continue; // Ignore unknown child
    34.     name = param.getAttribute ("name");
    35.     surname = param.getAttribute("surname");
    36.     age = param.getAttribute("age");
    37.     city = param.getAttribute("city");

    38.     textFont (font);
    39.     textSize(20);    
    40.     fill (255);
    41.     text(name, 20+i*100, 100);
    42.     if (millis()> 3000) {
    43.       text(surname, 20+i*100, 125);
    44.     }
    45.     if (millis()>4000) {
    46.       text(age, 20+i*100, 150);
    47.     }
    48.     if (millis()>5000) {
    49.       text(city, 20+i*100, 175);
    50.     }
    51.   }
    52. }

    Hello, 

    I have a xml file with the following structure: 
    1. <?xml version="1.0" encoding="ISO-8859-1"?>
    2. <data>
    3.   <person>
    4.     <Name Name="John"/>
    5.     <Surname Surname="Smith"/>
    6.   </person>
    7. </data>
    By using xml I get both elements into variables. But I now want to write the elements as text into my sketch. 
    When using the following lines of code I get this: <Name Name="John"/> But I only want to have "John" saved in the variable stringName.

    1.     stringName = person.getChild(0).toString();
    2.     println(stringName);
    How can I seperate the single Name from the rest of the line? So that I only have "John" saved to the variable stringName. 

    Thanks everyone!!
    Hey all, 

    i'm just working on some webcam capturing. It basically works fine so I use the built-in webcam of my macbook and display the image on the screen. But: As soon as I run the sketch on fullscreen the frameRate breaks down from 33 to 4 or 5 fps. I tested without using the filter(); -- this improved to frameRate up to 10 fps. But I need the captured image to be grayscale, so I don't want to get rid of this. 
    Do you have any suggestions how to keep the frameRate high? At least a few more fps than now. 

    1. import processing.video.*;

    2. Capture myCapture;

    3. void setup() 
    4. {
    5.   size(screen.width, screen.height);
    6.   myCapture = new Capture(this, width, height, 30);
    7.   frameRate(100);
    8. }

    9. void captureEvent(Capture myCapture) {
    10.   myCapture.read();
    11. }

    12. void draw() {
    13.   println(frameRate);
    14.   image(myCapture, 0, 0);
    15.   filter(GRAY);
    16. }

    Hi all, 

    I want to have the image of my webcam displayed on the screen, but just in grayscale with no colours.
    I tried doing it this way: 
    1.   myCapture.filter(GRAY);
    2.   image(myCapture, 0, 0);
    But sadly the coloured webcam image pops up from time to time. It's just for a split second but it destroys the gray filter... 
    So do you have any ideas how to solve this? 
    When using the OpenCV library they have a function like this
    1. opencv.convert(OpenCV.GRAY);
    But the convert does not work without the CV library. So, I'm glad for any suggestions. 
    Just as an additional information: I'm using the webcam thing on fullscreen, so probably this makes some trouble?

    So below you'll find the whole code: 
    1. import processing.video.*;
    2. Capture myCapture;

    3. void setup() 
    4. {
    5.   size(1920, 1200);
    6.   myCapture = new Capture(this, width, height, 30);
    7. }

    8. void captureEvent(Capture myCapture) {
    9.   myCapture.read();
    10. }

    11. void draw() {
    12.   myCapture.filter(GRAY);
    13.   image(myCapture, 0, 0);
    14. }



    Hello, 

    I just worked through the spriteButton tutorial of the control P5. 
    I want to read out the state of the buttons. So when I have the mouse over the button / when it is clicked...
    I found the function getState() but it doesn't work. Any suggestions how to read out the state of the button? 
    Below you'll find the code of the spriteButton example. 

    Thank you guys!!!!

    1. /**
    2.  * ControlP5 SpriteButton
    3.  
    4. import controlP5.*;
    5. import processing.opengl.*;
    6. ControlP5 controlP5;

    7. void setup() {
    8.   size(800,400,OPENGL);
    9.   smooth();
    10.   frameRate(30);
    11.   controlP5 = new ControlP5(this);
    12.   
    13.   ControllerSprite sprite = new ControllerSprite(controlP5,loadImage("buttonSprite.png"),75,75);
    14.   sprite.setMask(loadImage("buttonSpriteMask.png"));
    15.   sprite.enableMask();
    16.   
    17.   controlP5.Button b = controlP5.addButton("play",100,20,40,50,50);
    18.   b.setSprite(sprite);  
    19.   
    20.   b = controlP5.addButton("play2",101,120,40,50,50);
    21.   b.setSprite(sprite);  
    22.   
    23.   
    24. }

    25. void draw() {
    26.   background(200);
    27. }

    28. public void play(int theValue) {
    29.   println("playing : " + theValue); 
    30. }
    Hello, 

    I started working with the Keystone library (great!!!!)
    When working with the basic example "Corner Pin" I asked myself how to change the form of the layers from a rectangle to a triangle. Right now you have a white rectangle with a green-filled circle in it. How can I change the form of the layer from a rectangle to a triangle? So do I have to change something about the createGraphics()? 

    This would be great!!! 

    1. import deadpixel.keystone.*;

    2. Keystone ks;
    3. CornerPinSurface surface;

    4. PGraphics offscreen;

    5. void setup() {
    6.   size(800, 600, P3D);

    7.   ks = new Keystone(this);
    8.   surface = ks.createCornerPinSurface(400, 300, 20);
    9.   offscreen = createGraphics(400, 300, P2D);
    10. }

    11. void draw() {
    12.   PVector surfaceMouse = surface.getTransformedMouse();
    13.   offscreen.beginDraw();
    14.   offscreen.background(0);
    15.   offscreen.fill(0, 255, 0);
    16.   offscreen.ellipse(surfaceMouse.x, surfaceMouse.y, 75, 75);
    17.   offscreen.endDraw();
    18.   background(0);
    19.  
    20.   surface.render(offscreen);
    21. }

    22. void keyPressed() {

    23.   switch(key) {
    24.   case 'c':
    25.     ks.toggleCalibration();
    26.     break;

    27.   case 'l':
    28.     ks.load();
    29.     break;

    30.   case 's':
    31.     ks.save();
    32.     break;
    33.   }
    34. }
    Hello guys, 

    this problem is driving me crazy as it can't be that complicated...
    I want to run a sketch which is using open gl2. 
    I'm working with the latest version of processing (2.0 a4) and also tried 1.5.1 
    And whenever I try to start running the programm I get as an error: "No library found for processing.opengl2"

    I read through this link 

    And it says, that the new open gl2 is already implemented....

    Hm, so does anyone has an idea how to get this working?? Thanks!!!!
    Hey, 

    I just looked at this Google Doodles and thought of making this nice particle effect in Processing.

    I set up a grid of ellipses and now want to create this particle effect while the mouse "flows" over the ellipses. So as soon as the mouse comes closer to an ellipse this one has to grow in size and other ellipses around have to go back to their normal size. 

    I'm not sure whether this is the right way, so to put all my code in the "draw". Or do I have to work with arrays to address each ellipse individually when the mouse comes closer? Thanks for your help in advance!!! 
     
    1. int ellipseSize = 15; 

    2. void setup() {
    3.   size (800,600);
    4.   noStroke();
    5.   fill (30,200,200);
    6.   smooth();
    7. }

    8. void draw() {
    9.   background (255);
    10.   for (int i = 0; i<width+ellipseSize; i+=20) {
    11.     for (int j = 0; j<height+ellipseSize; j+=20) {
    12.       ellipse (i,j,ellipseSize,ellipseSize);
    13.     }
    14.   }
    15. }


    Hey, 

    I just have this code and to draw all the lines I use mouseX and mouseY. 
    Now I just want to start the programm and see how the lines grow without using the mouse. Do you have any experience how to simulate mouseX and mouseY? I tried to use random, but this does not give a nice effect at all. 

    1. ArrayList history = new ArrayList();
    2. float distthresh = 60;
    3. float factor = 2; 

    4. void setup() {
    5.   size(800,500); 
    6.   background(255);
    7.   smooth();
    8. }

    9. void draw() {
    10.   stroke(0,random(100,200));
    11.   strokeWeight (random(0.2,0.8));
    12.   strokeCap (SQUARE);
    13.   strokeJoin(MITER);
    14.   animate();
    15. }

    16. void animate() {
    17.   PVector d = new PVector(mouseX,mouseY,0);
    18.   history.add(0,d);

    19.   for (int p=0; p<history.size(); p++) {
    20.     PVector v = (PVector) history.get(p);
    21.     float joinchance = p/history.size() + d.dist(v)/distthresh;
    22.     if (joinchance < random(0.5,factor))  line(d.x,d.y,v.x,v.y);
    23.   }
    24. }

    25. void keyPressed() {
    26.   if (key == 'c') {
    27.     background(255);
    28.     history.clear();
    29.   }
    30. }

    Hey, 

    I just want to save images from my current sketch to a specific folder outside my sketch folder. 
    It nearly works when using this code to save.

    1. void keyReleased() {
    2.   imageCount ++;
    3.   if (key == 's'') save("/Users/myName/Desktop/test-file/data/"+saveFile("imageName"+imageCount+".png"));
    4. }
    When running this script it saves the image inside the "data" folder, but builds up several more subfolders. So when looking for the saved image I find it inside: "Users/myName/Desktop/test-file/data/ Users/myName/Desktop/test-file/data". Any ideas why this happens? I don't want all these subfolders rebuilded in the original data folder. I just want to save all images in the data folder addressed within the save-function. 

    Thanks for your help!!