Loading...
Logo
Processing Forum
owaunandrew's Profile
92 Posts
223 Responses
0 Followers

Activity Trend

Last 30 days
Show:
Private Message
    Here is the code I revised from this post

    http://forum.processing.org/topic/switching-renderers-on-the-fly

    What I like about Processing is that you can find multiple ways of doing the same thing, but cooler each time.
    I also like the borderless windows but you can still drag them.

    Processing rocks!!

    import java.awt.MouseInfo;
    import java.awt.Point;
    Point mouse;

    //
    //void draw() {
    //  Point mouse;
    //  mouse = MouseInfo.getPointerInfo().getLocation();
    //  println( "X=" + mouse.x + " Y=" + mouse.y );}



    int maxwindows = 10;

    Point [] _mouse = new Point[maxwindows];
    boolean [] mouseup= new boolean [maxwindows];
    Rectangle [] rm = new Rectangle[maxwindows];
    int [] _offx = new int[maxwindows];
    int [] _offy = new int[maxwindows];

    import javax.swing.JFrame;
    public PImage a;
    public int mmx;
    public int mmy;
    public JFrame [] new_window= new JFrame[maxwindows];
    MApplet sketchviewer;
    public int frameWidth =0;//10
    public int frameHeight =0; //25
    public String rmode = "P3D";
    void init()
    {
      frame.removeNotify();
      frame.setUndecorated(true);
      frame.addNotify();
      super.init();
    }

    int w;
    int h;

    void setup(){
      for (int i=0;i<maxwindows;i++){
        mouseup[i]=true;
        _offx[i]=0;
        _offy[i]=0;
      }
      w=255;
      h=255;
      a=createImage(w,h,ARGB);
      size(w,h,P3D);

      background(233,23,23);
      this.frame.setLocation(screen.width/2,screen.height/2);
      r = frame.getBounds();
    }
    Rectangle r ;
    //= frame.getBounds();
    void mousePressed(){
      r = frame.getBounds();
      if(mup){
        offx=mouseX;
        offy=mouseY;
      }
      mup=false;
    }
    boolean mup=true;
    void mouseReleased(){
      mup=true;
    }
    public int windowcount=0;
    void keyPressed(){
      if(key=='n')   loadNewWindow();
      if (key=='r')setup();

      if (key=='1') {
        rmode  = "P3D";
        loadNewWindow();
      }
      if (key=='2') {
        rmode  = "P2D";
        loadNewWindow();
      }
      if (key=='3') {
        rmode  = "JAVA2D";
        loadNewWindow();
      }

    }
    int offx,offy;
    void draw(){

      mouse = MouseInfo.getPointerInfo().getLocation();
      r = frame.getBounds();
      this.frame.setTitle(str(r.x)+ " - " + str(r.y));
      if (pmouseX!=mouseX && pmouseY!=mouseY)
      {
        //this.frame.setTitle(str(mouseX)+ " - " + str(mouseY));
        this.frame.setTitle(str(r.x)+ " - " + str(r.y));
      }
      //  else
      //  {
      //    this.frame.setTitle(str(mmx)+ " - " + str(mmy));
      //  }
      background(255,0,0);
      //if (a!=null)background(a);
      mmx= mouseX;
      mmy=mouseY;
      ellipse(mouseX,mouseY,20,20);

    }
    void mouseDragged(){
      //to do calculate offsets and move from the point where you clicked

        frame.setLocation(mouse.x-offx,mouse.y-offy);

    }

    public int inc=0;
    void loadNewWindow()
    {
      windowcount++;
      if (windowcount<maxwindows){
        // if(new_window == null){ // omitting this allows multiple windows
        new_window[windowcount] = new JFrame();

        sketchviewer = new MApplet();

        new_window[windowcount].getContentPane().add(sketchviewer, BorderLayout.CENTER);

        //
        new_window[windowcount].removeNotify();
        new_window[windowcount].setUndecorated(true);
        new_window[windowcount].addNotify();
        new_window[windowcount].setLocation(inc, 100);
        //
        inc+=255;
        new_window[windowcount].setVisible(true);

        sketchviewer.init();
        //  }


        new_window[windowcount].setSize(w + frameWidth, h + frameHeight);

      }
    }

    boolean viewhead = false;
    public class MApplet extends PApplet{
      public PApplet pgx;
      public Robot robot;
      Frame framex;


      void mouseDragged(){
        new_window[windowcount].setLocation(mouse.x-_offx[windowcount],mouse.y-_offy[windowcount]);
        // this.setLocation(mouseX, 100);
      }

      //<Insert sketch Code here>
      // Shining Particle by harukit
      // Created with Processing 68 alpha on September 11 , 2004
      // http://www.harukit.com


      int pNum =4;
      Particle[] p = new Particle[pNum];
      float rr,gg,bb,dis;
      int gain = 5;
      float[] cc = new float[3];

      public void setup(){
        framex = new Frame();
        if (rmode=="P3D") size(w,h,P3D);
        if (rmode=="P2D") size(w,h,P2D);
        if (rmode=="JAVA2D")size(w,h,JAVA2D);

        loadPixels();
        noStroke();
        background(0);
        for(int i=0;i<3;i++){
          cc[i]=random(40)+random(40)+random(40)+random(40)+random(40);
        }
        for(int i=0;i<pNum;i++){
          p[i] = new Particle(random(width),random(height),random(0.1,0.3));
        }

        try
        {

          robot = new Robot();



        }
        catch (AWTException e) {
          e.printStackTrace();
        }

      }

      public void draw(){
        //mouse = MouseInfo.getPointerInfo().getLocation();
        rm[windowcount] = new_window[windowcount].getBounds();
        this.mouseX=mmx;
        this.mouseY=mmy;
        //  for(int i=0;i<pNum;i++){
        //    p[i].update();
        //  }
        for(int y=0;y<height;y++){
          for(int x=0;x<width;x++){
            int pos=y*width+x;
            color col = pixels[pos];
            rr = col >> 16 & 0xff;
            gg = col >> 8 & 0xff;
            bb = col  & 0xff;
            // for(int i=0;i<pNum;i++){
            //dis =dist(p[i].xpos,p[i].ypos,x,y)/2;
            //dis = dist2(mouseX,mouseY,x,y,24);
            dis = dist(mouseX,mouseY,x,y)/2;
            rr += cc[0]/dis-gain;
            gg += cc[1]/dis-gain;
            bb += cc[2]/dis-gain;
            //  }
            pixels[pos]=color(rr,gg,bb);
            a.pixels[pos]=color(rr,gg,bb);
          }
        }
        if (rmode=="JAVA2D"){
          updatePixels();
        }

        if (this.keyPressed){
          robot.keyPress(18);
          robot.keyPress(154);
          robot.keyRelease(18); // <<Important
          robot.keyRelease(154);// <<Important

          if (key=='v')viewhead =!viewhead ;


        }
        //this.setLocation(mouse.x,mouse.y);
        // this.frame.setLocation(mouse.x+55,mouse.y);
      }

      public void mousePressed(){
        //  background(0);
        Particle[] p = new Particle[pNum];

        rm[windowcount] = new_window[windowcount].getBounds();
        if(mouseup[windowcount]){
          _offx[windowcount]=this.mouseX;
          _offy[windowcount]=this.mouseY;
        }
        mouseup[windowcount]=false;

      }

      public void mouseReleased(){
        for(int i=0;i<3;i++){
          cc[i]=random(40)+random(40)+random(40)+random(40)+random(40);
        }
        // background(0);
        for(int i=0;i<pNum;i++){
          p[i] = new Particle(random(width),random(height),random(0.1,0.3));
        }
        mouseup[windowcount]=true;
      }

      class Particle{
        float xpos,ypos,del;
        Particle(float x,float y,float d){
          xpos=x;
          ypos=y;
          del = d;
        }
        void update(){
          xpos += (mouseX-xpos)*del;
          ypos += (mouseY-ypos)*del;
        }
      }

    }

    float fastDist( float x1, float y1, float z1, float x2, float y2, float z2 )
    {
      float fdist = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) + (z2 - z1) * (z2 - z1);

      return fdist;
    }

    float dist2( float x1, float y1, float x2, float y2,float val)
    {
      float fdist = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
      fdist = fdist / val;
      return fdist;
    }



     


    Is there any code available to copy image data from the clipboard and use it in processing.

    The alternative is convert the image to text copy it to the clipboard and then copy the text from the clipboard to image,
    manipulate it and then copy the image back to the clipboard.

    Either method requires a knowledge of both readying and writing image data to and from the clipboard.
    Check out http://www.bit-101.com/blog/?p=3251

    I am trying to use the code to create the image on the site

    However all I am able to get done are greyscale bands



















    Here is my processing code
    1.  PImage imageData;
       void setup(){
       size(255,255,P3D);
                        imageData = createImage(255,255,ARGB);
           for(int y = 0; y < imageData.height; y += 1) {
           for(int x = 0; x < imageData.width; x += 1) {
           //offset = x * 4 + y * 4 * imageData.width;

           //imageData.data[offset] = Math.sin(x * 0.01) * 127 + 128;
           //imageData.set(x+1,y+3,color(sin(x * 0.01) * 127 + 128));
      //     imageData.data[offset + 1] = Math.sin(y * 0.02) * 127 + 128;
        //   imageData.data[offset + 2] = Math.cos(x * 0.04 + y * 0.03) * 127 + 128;
        // imageData.set((x*4)+2,y,color(cos(x * 0.04 + y * 0.03) * 127 + 128));
         imageData.set((x*2),(y*1),color(cos(x * 0.04 + y * 0.03) * 127 + 128));
         //imageData.set((x*2)+1,(y*1),color(cos(x * 0.04 + y * 0.03) * 127 + 128));
          imageData.set((x*2)+1,(y*1)+1,color(cos(x * 0.04 + y * 0.03) * 127 + 128));
          // imageData.data[offset + 3] = 255;
           }
           }

         image(imageData,0,0);

      }


    Here is the original on the site
         for (y = 0; y < imageData.height; y += 1) {
             for (x = 0; x < imageData.width; x += 1) {
                 offset = x * 4 + y * 4 * imageData.width;
                 imageData.data[offset] = Math.sin(x * 0.01) * 127 + 128;
                 imageData.data[offset + 1] = Math.sin(y * 0.02) * 127 + 128;
                 imageData.data[offset + 2] = Math. cos (x * 0.04 + y * 0.03) * 127 + 128;
                 imageData.data[offset + 3] = 255;
             }
         }
     

    Here is what I can get done so far



    Saving files to the web from Processing requires signing the application.

    I have a question.

    If you use one of the file synching programs like dropbox.com or sugarsync.com; would it be possible to use those as
    some sort of centralized data storage for apps.

    It would not be realtime but it would be better as you can store entire folders of processing applets and .jar files.
    I found this code on the old forums

    It allows you to edit the
      - Window icon
     - Task Bar icon
    -  Task Manager icon
    1. void setup1()
      {


       
        PGraphics icon = createGraphics(16, 16, JAVA2D);
        icon.beginDraw();
        icon.noStroke();
        icon.fill(#55AAFF);
        icon.ellipse(8, 8, 16, 16);
        icon.fill(#FFEE22);
        icon.ellipse(9, 6, 8, 6);
        icon.stroke(#FFEE22);
        icon.strokeWeight(3);
        icon.line(6, 6, 6, 12);
        icon.endDraw();
        frame.setIconImage(icon.image);
      }

    I did a small proof of concept to calculate distance in 3D using a greyscale 2D image.

    Here is the sketch on openprocessing
    http://openprocessing.org/visuals/?visualID=19725

    I assume the two items are on the same plane (i.e. looking directly at one another) so the camera can see both along the z-axis, sorta like a slice of an apple where you cut along the z-axis that connects the two points.

    Here is a screencap


    Here is the writeup

    An experiment using a greyscale image of ellipses reducing in grey intensity. The brightness is used a test of distance. This is to be translated to 3D where each ellipse represents a sphere.

    As the items goes further away i.e. down the z-axis , up the y axis or across the x axis it is assumed the two objects are on the same plane.

     



    Currently Processing has the dist() function to determine the distance between two points.
    However this requires the square root function to be used.

    Does anyone have a faster algorithm that does not require square roots (and/or division) ?
    How is it possible to remove the effect of rotating an object using the P3D renderer and portions that are rendered first disregarding there are farther back in the scene ?

    I believe it has to do something with enabling depth sorting.
    I would like to know if anyone knows of a cool way to create glossy effects using Processing.

    I was thinking about sunflow but Hipsterinc's version can't do it but the recent ones seem to.
    For example this picture



    Do you think these type of graphics can be done with Processing ?
    Basically I want to sign java sketches so when they run in the browser you can have access to basically the user's pc input and output processes (serial port, webcam, keyboard, whatever) However signing app after after app can become tedious.

    Plus I don't know how to get it done in the first place. When I finally find out how to do it so I can actually show others (basically my yard-stick for knowing how to do something, if you can show it to others and they get it)

    Is it possible to have that sketch call other sketches and still be signed where in the jar does not change just what it refers.


    As I am aware, save() or any core function of processing does not work when running as an applet; after you have exported it as an online applet and the application is run via the launch of the index.html

    Is php or ftp access the only way to save program data to the server side location ?

    Basically I want to save either a basic text file (.csv) or  a .png to a specified folder on the server side location (pc running the application) and I am accessing the application remotely.

    It can work as a standalone application on the intranet but I would like to know how to get it done via the internet; if there are any alternatives to php or ftp access.

    Also if I sign the applet, does this help ?
    Some friends at work want to develop an in-and-out tracking program. Now you can use any programming language you prefer.

    I want to use processing however I want to access the database using sql and also store the data in images using the pixels.

    I know basic SQL but how can I develop an algorithm to search the images based on specific criteria ?


    Example

    Database name : Employee.dbf
    Name : Owaun
    Age : 33
    Occupation : Computer Programmer
    Location : In_house

    A basic sql is
    Select * from employee where Location = "in_house"

    How would it best to develop an algorithm to search images where this data is stored ?

    Any ideas?



    I do a lot of image pixel manipulation sketches.

    So i create colours a lot using e.g color k = color(c/2,c*2,c/2,c/2);

    Now how do I change this on the fly so I can say k = color (c/3,c,c/4,c/3);

    ...without declaring fixed colours, and selecting the variables I already have present ?