Loading...
Logo
Processing Forum
lukas.arvidsson's Profile
9 Posts
15 Responses
0 Followers

Activity Trend

Last 30 days
Show:
Private Message
    Hi!

    I cannot seem to set transparency on a loaded .svg in P2D or P3D. Can someone please verify if this is working for you:

    Here is the sample code:

    1. PShape test;
    2.     
    3. void setup()
    4.     {
    5.         size(1000,700,P2D);
    6.         background(0);
    7.         stroke(255);
    8.     }

    9. void draw()
    10.     {
    11.         frameRate(30);
    12.         stroke(255);
    13.         strokeWeight(0);
    14.         background(70, 20,10);

    15.         test = loadShape("Guy_20130912.svg");
    16.         test.disableStyle();
    17.         fill(200,200,0,mouseX);
    18.         
    19.         test.setFill(20, 30);
    20.         
    21.         shape(test, 50,50);  
    22.     }
    The test-svg can be downloaded here:  https://dl.dropboxusercontent.com/u/21219639/Guy_20130912.svg

    If you change to size(1000,700) you will see that it is working. I cannot seem to set transparency using the .setFill on the PShapre either...

    Anyhow any info on this would be much appreciated!

    Thank you


    Hi!

    I have a problem that when I run my sketch in full screen on a 3rd party IDE the screen is offset from its original position. This is only true if I run the P2D or P3D mode. Here is how my main class looks:

    1. import processing.core.*;
    2. import processing.opengl.*;

    3. public class MainVecField extends PApplet 
    4. {
    5. public static void main(String args[]) 
    6. {
    7. PApplet.main(new String[] { "--present", "MainVecField" });
    8. }

    Is there any way to fix this? Currently I am using the IntelliJ IDE (Which is great otherwise for processing IMO), but the problem is there with eclipse as well. I will attach an image so you can see how it looks.



    Thank you
    Hi!

    I am currently rendering a quite large image (to an offscreen PGraphics) and once i hit 10000px * 7000px I get the following error:

    Exception in thread "Animation Thread" java.lang.OutOfMemoryError: Java heap space
    at java.awt.image.DataBufferInt.<init>(DataBufferInt.java:75)
    at java.awt.image.Raster.createPackedRaster(Raster.java:467)
    at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1032)
    at java.awt.image.BufferedImage.<init>(BufferedImage.java:331)
    at processing.core.PImage.saveImageIO(PImage.java:3117)
    at processing.core.PImage.save(PImage.java:3297)
    at OffScreenRender.stopRender(OffScreenRender.java:38)
    at MainVecField.draw(MainVecField.java:93)
    at processing.core.PApplet.handleDraw(PApplet.java:2305)
    at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:243)
    at processing.core.PApplet.run(PApplet.java:2176)
    at java.lang.Thread.run(Thread.java:724)

    If I have the image at 9000px * 7000px everything is fine. 

    I am using IntelliJ idea as my IDE and I have increased the standard heap space from 512 to 2048mb. The image with the resolution  9000px * 7000px renders fine with 512mb heapspace, but the one with  10000px * 7000px does not (even with 2048 mb heap space). 

    This is my offScreenRender class:
    1. import processing.core.*;
    2. /**
    3.  * Renders the ProcessingSketch to a ".jpg" file at specified resolution.
    4.  */

    5. public class OffScreenRender
    6. {
    7.     PApplet parent; // The parent PApplet
    8.     PGraphics render;
    9.     PGraphics original;
    10.     int width;
    11.     int height;
    12.     int resFactor;

    13.     OffScreenRender(PApplet p, int width_, int height_, int resFactor_)
    14.     {
    15.         //Initialize variables
    16.         parent = p;
    17.         width = width_;
    18.         height = height_;
    19.         resFactor = resFactor_;

    20.         render = parent.createGraphics(width, height);
    21.     }

    22.     //Render the image
    23.     void startRender()
    24.     {
    25.         parent.beginRecord(render);
    26.         render.scale(resFactor);
    27.     }

    28.     //Render the image
    29.     void stopRender()
    30.     {
    31.         parent.endRecord();
    32.         render.save("hej.jpg");
    33.     }
    34. }
    This is my draw() function:

    1. public void draw() 
    2. {
    3.       frameRate(30);
    4.       stroke(255);

    5.        //Check if the render should be saved
    6.        if(offScreenRenderSwitch == true){screenRender.startRender();}
    7.       background(0,0,0);

    8.       //Run vector field with action input
    9.       vecField.run(action.get());
    10.       action.display(g); //Display the action input

    11.       //Load vector forces into drawGraphic
    12.        graphic.loadVectorGuide(vecField.getForceVectors());

    13.        //Render the background object
    14.               backgroundVisual.display();

    15.       //Draw the graphic from vectorForces
    16.        graphic.display();

    17.        if(offScreenRenderSwitch == true)
    18.        {
    19.             screenRender.stopRender();
    20.             offScreenRenderSwitch = false;
    21.        }
    22.     }
    So is this a Java error or do you think it could be a problem with the structure of my program?

    Thank you!
    Hi!

    I am quite new to this so please bear with me if what I am thinking here is stupid :). What I want to do is to have a separate class that can handle the recording to a new PGraphics object.

    For example I want the draw() function to be able to look like this:


    1. OffScreenRender screenRender;

    2. public void setup() 
    3. {
    4.             screenRender = new OffScreenRender(this, 1000, 700);
    5.         }
    6. public void draw() 
    7. {
    8. background(0,0,0);

    9.         //Render the graphics to an offScreen buffer
    10.         screenRender.startRender();
    11.         rect(600,50,230,150);
    12.         .......................................
    13.         etc....
    14.         //Stop the render and save image
    15.         screenRender.stopRender();
    16.     }

    The  OffScreenRender-class should look like this:

    1. import processing.core.*
    2. /**
    3.  * Renders the processingsketch to a .jpg
    4.  */
    5. public class OffScreenRender
    6. {
    7.     PApplet parent; // The parent PApplet
    8.     PGraphics render;
    9.     int width;
    10.     int height;

    11.     OffScreenRender(PApplet p, int width_, int height_)
    12.     {
    13.         //Initialize variables
    14.         parent = p;
    15.         width = width_;
    16.         height = height_;

    17.         render = parent.createGraphics(width, height);
    18.     }

    19.     //Render the image
    20.     void startRender()
    21.     {
    22.         render.beginDraw();
    23.     }

    24.     //Render the image
    25.     void stopRender()
    26.     {
    27.         render.endDraw();
    28.         render.save("hej.jpg");
    29.     }
    30. }

    So basically i want the PGraphics called "render" to listen and record while commands are executed in draw(). Is this possible? Right now I only get a black image.

    Thank you!
    Hi!

    I am having this peculiar problem that seems to be related to Eclipse. I cannot get to show the stroke on imported .svg graphics. For example the very simple code:
    1. import processing.core.*;
    2. import processing.opengl.*;

    3. public class TestClassProcessing extends PApplet 
    4. {
    5. public static void main(String args[]) 
    6. {
    7.       PApplet.main(new String[] { "--present", "TestClassProcessing" });
    8. }
    9. //Global variables
    10. PShape s;
    11. public void setup() 
    12. {
    13.       size(1000,700,P3D);
    14.       background(0);
    15.       s = loadShape("tri2.svg");
    16. }

    17. public void draw() 
    18. {
    19.       frameRate(30);
    20.       stroke(255);
    21.       background(0);
    22.       s.disableStyle();
    23.       pushStyle();
    24.       strokeWeight(10);
    25.       fill(255,20,10);
    26.       stroke(255,255,20);
    27.       shape(s,300,300,70,70);
    28.       rect(400,400,70,70);
    29.       popStyle();
    30.       PApplet.println("ny draw");
    31.       }
    32. }

    Generates a very simple rectangle (svg) that does not have any stroke and a rectangle with correct stroke width. See picture.


    When running the same application in the standard processing IDE i get the following result (where the thickness of the stroke is due to the sacling of the .svg graphics).




    Anyone have any ideas why this is so?


    Thank you!

    Lukas


    Hi!

    I have a problem with processing and eclipse when running in OpenGL, the window when running in application mode the processing window is not centred on screen. All the interactions are centered though. I am running on a MacBook Pro 13" with intel HD4000. It has worked before and I have not updated anything as far as I know.... Here are some sample code:

    1. import processing.core.*;
    2. import controlP5.*;
    3. public class ProcessingSketch extends PApplet {
    4.       public static void main(String args[]) 
    5.       {
    6.           PApplet.main(new String[] { "--present", "ProcessingSketch" });
    7.       }
    8. /* SETUP WORLD */
    9.       public void setup() 
    10.       {
    11.             size(1200,750,P3D);
    12.             background(0);
    13.       }
    14.       public void draw() 
    15.       {
    16.             stroke(255);
    17.             line(mouseX,mouseY,0,0);
    18.             frameRate(24);
    19.       }
    20. }



    As you can see the result is not what it is supposed to be... Any ideas how to solve this?

    Hi!

    I have a question regarding how array works. I will attch a small piece of sample code so you can see what I mean.

    The first case is this, in a small processing application, I declare a float array named data. I pass that float array into the function loadData which returns a float array. The returned data is of correct length and with the correct values. So far so good.
    1. float[] data;

    2. public void setup() 
    3. {
    4.               data = chartData.loadData("oc", loadFileGdp);
    5.  }
    But how does it work when I have a two dimensional array named data instead of a one dimensional? Like this example:

    1. float[][] data;
    2.  String[] dataNames = new String[3];
    3.       
    4.  dataNames[0] = "naData";
    5.  dataNames[1] = "euData";
    6.  dataNames[2] = "asData";

    7.  data = new float[dataNames.length][];

    8. public void setup() 
    9. {
    10.             
    11.        for(int i = 0; i < dataNames.length; i++)
    12.        {
    13.              data[i][] = chartData.loadData(dataNames[i], loadFileGdp);
    14.       }
    15.  }
    I cannot get this to work, I know there are many workarounds that I can take to make it work, but I am interested to why this is wrong, to me it seems pretty logical.

    Thank you very much for your help & many thanks to the processing team!

    Kind regards,
    Lukas
    Hi!

    I have searched for this for quite a while now, but I have not really reached any answers about how to do this. I am working with an XML-file that is tagged in indesign. It is basically just alot of text with a few words here and there that are tagged. The basic structure is like this:

    <?xml version="1.0"?>
    <root>
     <text>Hello, My name is <name>Mariel</name> and I am an excellent dancer. Just as good as the more famous <name >Mariel</name> who stole my name.</text>
    </root>

    what I want to do is exchange the words within the <name> tags with something else. The text I am working on is quite large and there are maybe fifty different tags that needs to be recognized and changed (many tags like <name> show up in different parts of the text). So i need some kind of system for it.

    I have managed to load the xml file and put the contents of the tags in an String-array and change it like how i want to have it. But I dont know who to write it back to an xml file? What would you guys do if you were facing the same problem?

    Thanks in advance,
    Regards
    Lukas Arvidsson
    Hi! 

    I have this problem which I hope you guys could help me out with. I am using eclipse just so you know.

    I have a "main" class that is called ProcessingSketch, which looks like this:


    import processing.core.*;
    import processing.opengl.PGraphicsOpenGL;

    public class ProcessingSketch extends PApplet {
    public static void main(String args[]) {
       PApplet.main(new String[] { "--present", "ProcessingSketch" });
    }
    Button button1;
    Scrollbar bar;
    PImage img;
    int color1 = 204;
    int color2 = 255;
    int color3 = color(20,20,180);
    public void setup() 
    {
    frameRate(120);
    size(1022, 488,PGraphicsOpenGL.OPENGL);
    smooth();
    fill(0);
    strokeWeight(1);
    background(120);

    bar = new Scrollbar(this, 10, height-10, 1000, 7, -511.0f, 511.0f);
    button1 = new Button(this, true, width/2, height-40, 20, color1, color2, color3);
    img = loadImage("faith-love-peace.jpg");
    }
    public void draw()
    {
    background(204);
    int x = (int)(bar.getPos());
    image(img, x, 0);
    bar.update(mouseX, mouseY);
    bar.display();
    button1.update(mouseX, mouseY);
    button1.display();
    }

    public void changeImage()
    {
    println("CIAO");
    }
    public void mousePressed()
    {
    bar.press(mouseX, mouseY);
    button1.press();
    }
    public void mouseReleased()
    {
    bar.release();
    button1.release();
    }

    }

    I have two classes that I work with Button and Scrollbar. But my problem is general. From the Button class I want to be able to call the ornage marked method above. How do I do this? Do I have to use a static method? I will attach the button class aswell below so you can see it:

    import processing.core.PApplet;

    public class Button

    {
    int x, y; // The x- and y-coordinates
    int size; // Dimension (width and height)
    int baseGray; // Default gray value
    int overGray; // Value when mouse is over the button
    int pressGray; // Value when mouse is over and pressed
    boolean over = false; // True when the mouse is over
    boolean pressed = false; // True when the mouse is over and pressed
    boolean circleRect = false; //True when circle, False when rectangle
    PApplet parent;
    Button(PApplet q, boolean cR, int xp, int yp, int s, int b, int o, int p)
    {
    x = xp;
    y = yp;
    size = s;
    baseGray = b;
    overGray = o;
    pressGray = p;
    parent = q;
    circleRect = cR;
    }
    // Updates the over field every frame
    void update(int mx, int my)
    {
    //CHECK RECTANGLE
    if(circleRect == false) 
    {
    if ((mx >= x-(size/2)) && (mx <= x-(size/2)+size) && (my >= y-(size/2)) && (my <= y-(size/2)+size))
    {
    over = true;
    }
    else
    {
    over = false;
    }
    }
    //CHECK CIRCLE
    else if(circleRect == true)
    {
    if (PApplet.dist(mx, my, x, y) < size/2)
    {
    over = true;
    }
    else
    {
    over = false;
    }
    }
    }
    boolean press()
    {
    if (over == true)
    {
    pressed = true;
    xxxxx.changeimage();
    return true;
    }
    else
    {
    return false;
    }
    }
    void release()
    {
    pressed = false; // Set to false when the mouse is released
    }
    void display()
    {
    if (pressed == true)
    {
    parent.fill(pressGray);
    }
    else if (over == true)
    {
    parent.fill(overGray);
    }
    else
    {
    parent.fill(baseGray);
    }
    if(circleRect == false)
    {
    parent.stroke(255);
    parent.rect(x-(size/2), y-(size/2), size, size);
    }
    else if(circleRect == true)
    {
    parent.stroke(255);
    parent.ellipse(x, y, size, size);
    }
    }
    }

    If anyone has any ideas on how to best do this, please let me know! Thank you!

    Best regards
    Lukas