everybody... post novelty stuffs here!

edited January 2018 in Share Your Work

Yo. you can put all of your cool little or big projects here. let's see what you make of it!

Comments

  • edited January 2018

    novelty #1

    closeit.pde

    import java.util.Timer;
    import java.util.TimerTask;
    
    int col;
    
    Timer timer;
    void setup() {
      size(150, 150);
      surface.setTitle("quick!");
      timer = new Timer();
      colorMode(HSB, 255, 255, 255);
      col = 0;
      timer.scheduleAtFixedRate(new TimerTask(){
        public void run() {
          runSketch(new String[]{"closeit"}, new closeit());
        }
      }, (long)random(3000, 5000), (long)random(9000, 12000));
    }
    
    void draw() {
      background(col, 255, 255);//LOL RGB
      col ++;//LOL MORE RGB
      if (col > 255) col = 0;//LOL KEEP RGBING
    }
    

    you won't keep up counting them...

  • Error: Line 15: The class "closeit" does not exist. ...Tried to replacing line 15 with "runSketch(new String[]{"closeit"});"... And it then started very slowly creating new windows until crashing... And it crashes on 3rd or 4th window, either with line 21 erroring with "missing a pushMatrix() to go with that popMatrix()"(wut?), or "handleDraw() called before finishing" on no particular line...

    Also, code picky wise, you can replace lines 22 and 23 with col=(col+1)%255; and have your sketch... eat... 1hz of cpu time.. less.... performance boost... a little but you know...

  • edited January 2018
    // hello shader hello java
    // shader version http - glslsandbox.com/e#44638.0
    // nabr  - 2017 ^;.;^
    void setup() {
      size(640, 360);
      loadPixels();
    }
    void draw() {
      // 
      float t = sin(millis()*.001f)*.5+.5;
      int x = (int)(width*height);
      while(0<--x)
        pixels[x] =
        0xff<<24|
          (int)((1.f*(x%width)/width)*0xff)<<16|
          (int)((1.f*(x/height*.5)/height)*0xff)<<8|
          (int)(t*0xff);
      updatePixels();
    }
    
  • Makes a rainbow cycle of color like OP's

    void draw(){
     int H = frameCount%1536;
     background(color(abs(H-765)-256,512-abs(H-512),512-abs(H-1024))); 
    }
    

    Return lowest int larger than 'n' with same number of 1's in it's binary representation as n.

    int snob(int n) {
    int a=n&-n, b=a+n;
    return b|(n^b)/a>>2;
    }
    

    Obtuse way to loop 1 -> 10 inclusive

    for(int i=0;;println(i))i:{if(i++<10)break i;break;}
    

    Minimal Game of Life

    void setup() {
      background(~0);fill(0);
      text("Game of life",9,9);
      loadPixels();
    }
    void draw() {
      int n,i=0,j,l=10000;
      int[]a=new int[l],p=pixels;
      for (;i<l;a[i]=n==5?-1<<24:n==6?p[i]:-1,i++)
      for (j=n=0; j<9; j++)n+=j!=4?p[(i+l-1+j%3+100*(j/3-1))%l]&1:0;
      arrayCopy(a,p);
      updatePixels();
    }
    
  • Architector_4... the sketch is supposed to be called closeit... so, no code errors.

  • The code-golf-y Game of Life example is fun. For people interested in studying a slightly de-obfuscated version of the same code, here it is with the loops and ternaries unpacked:

    void setup() {
      background(255);
      fill(0);
      text("Game of life", 9, 9);
      loadPixels();
    }
    void draw() {
      int n = 0;
      int l = 10000;
      int[]a = new int[l];
      int[]p = pixels;
      int nPos;
      for (int i=0; i<l; i++) { // loop through pixels
        n=0;
        // check pixel neighbors on current frame
        for (int j=0; j<9; j++) {
          if (j!=4) {
            // calculate index of current neighbor
            nPos = (i+l-1+j%3+100*(j/3-1));
            // add value of neighbor to total
            n += p[nPos%l]&1;
          }
        }
        // update pixel state on next frame
        // according to the Game of Life rules
        if (n==5) {
          a[i] = -1<<24;
        } else if (n==6) {
          a[i] = p[i];
        } else {
          a[i] = -1;
        }
      }
      // copy next frame to current
      arrayCopy(a, p);
      updatePixels();
    }
    
  • it sounds like 'vyry nysh' and then musics

  • you can change the language somewhere. btw.

    for me it sounds more like vyry nysh with german accent :)

  • PMatrix3D transform;
    PShader cube;
    String[] 
    frag = { 
    "void main() { gl_FragColor = vec4(1); }" 
    } ,
    vert= {
    "#define NNN vec3(-1),",
    "#define NNP vec3(-1,-1, 1),",
    "#define NPN vec3(-1, 1,-1),",
    "#define NPP vec3(-1, 1, 1),",
    "#define PNN vec3( 1,-1,-1),",
    "#define PNP vec3( 1,-1, 1),",
    "#define PPN vec3( 1, 1,-1),",
    "#define PPP vec3(1),",
    "const vec3 verts[36] = {",
    "NPP PPP NNP PNP PPP NNP",
    "NPN PPN NNN PNN PPN NNN",
    "NNP PNP NNN PNN PNP NNN",
    "NPP PPP NPN PPN PPP NPN",
    "NNP NPP NNN NPN NPP NNN",
    "PNP PPP PNN PPN PPP PNN",
    "};",
    "uniform mat4 u_transform;",
    "void main(){",
    "vec4 foo = vec4(verts[gl_VertexID],1) * u_transform;",
    "gl_Position = vec4(foo.xy/foo.z,0,1) ;",
    "}"
    };
    void setup(){
     size(500,500,P3D);
     cube = new PShader(this, vert, frag);
    }
    void draw(){
    background(100);
    transform = new PMatrix3D();
    transform.translate(0,0,mouseY/100.0);
    transform.rotateY(mouseX/100.);
    transform.rotateX(mouseY/100.);
    transform.scale(0.5);
    cube.set("u_transform",transform);
    shader(cube);
    for(int i=0;i<12;i++)triangle(0,0,0,0,0,0);
    }
    
  • edited February 2018

    @prince_polka

    updated glsl version >=110
    the problem is you cant not have a constat array anymore https://www.opengl.org/discussion_boards/showthread.php/170193-Constant-vec3-array-no-go

    a wonder that it compiles with gl_VertexID. Java is awesome :)

    String[] frag ={
     "#version 330" ,
     "in vec3 vCol;" ,
     "out vec4 fragColor;" ,
     "void main()" ,
     "{" ,
       "fragColor=vec4(vCol,1);" ,
     "}" 
     },vert= {
    "#version 330" ,
     "#define NNN vec3(-1)," ,
     "#define NNP vec3(-1,-1,1)," ,
     "#define NPN vec3(-1,1,-1)," ,
     "#define NPP vec3(-1,1,1)," ,
     "#define PNN vec3( 1,-1,-1)," ,
     "#define PNP vec3( 1,-1,1)," ,
     "#define PPN vec3( 1,1,-1)," ,
     "#define PPP vec3(1)," ,
     "const vec3 verts[36] = vec3[](",
     "NPP PPP NNP PNP PPP NNP",
     "NPN PPN NNN PNN PPN NNN",
     "NNP PNP NNN PNN PNP NNN",
     "NPP PPP NPN PPN PPP NPN",
     "NNP NPP NNN NPN NPP NNN",
     "PNP PPP PNN PPN PPP vec3( 1,-1,-1));",
     "uniform mat4 u_transform;" ,
     "out vec3 vCol;" ,
     "void main()" ,
     "{" ,
       "vec4 v=vec4(verts[gl_VertexID],1)*u_transform;" ,
       "gl_Position=vec4(v.xy/(v.z*.5),0,1);" ,
       "vCol=vec3[3u](vec3(1.f,0.f,0.f),vec3(0.f,1.f,0.f),vec3(0.f,0.f,1.f))[gl_VertexID%3];" ,
     "}"
     };
    // will also works in version higher then 110
    {
     PJOGL.profile = 3;
    }
    PMatrix3D transform;
    PShader cube;
    void setup() {
      size(500, 500, P3D);
    
    
      // changed from draw to setup
      transform = new PMatrix3D();
    
      cube = new PShader(this, vert, frag);
      shader(cube);
    
    }
    void draw() {
      background(100);
    
      transform.translate(0, 0, mouseY/100.0);
      transform.rotateY(mouseX/100.);
      transform.rotateX(mouseY/100.);
      transform.scale(0.5);
      cube.set("u_transform", transform);
    
    
      // changed reset to Identity matrix, avoid stack, - popMatrix() in processing
      transform.reset();
    
      for (int i=0; i<12; i++) triangle(0, 0, 0, 0, 0, 0);
    }
    
  • edited February 2018
    /** 
     * Write Shaders From Inline Strings
     *
     * ^;.;^
     * nabr (2018/Feb/12)
     *
     * forum.processing.org/two/discussion/comment/117009/#Comment_117009
     */
    
    // Note: best when the Scetch is saved to your local HD, otherwise look in the tmp folder  
    
    String[] vertSource={"#version 150"
      , "in vec4 position;"
      , "uniform mat4 transform ;"
      , "void main() {"
      , "gl_Position =transform*position;"
      , "}"
    };
    String[] fragSource={"#version 150"
      , "out vec4 fragColor;"
      , "void main() {"
      , "fragColor =vec4(1.,0.,0.,1.);"
      , "}"
    };
    
    PShader shdr;
    
    void setup() {
      size(800, 600, P3D);
      noStroke();
    
      // run once at lunch  
      /**/ 
      PrintWriter O = createWriter("data/vertSource.txt");
      for (String s : vertSource) O.println(s);
      O.flush();
      O.close();
      O = createWriter("data/fragSource.txt");
      for (String s : fragSource) O.println(s);
      O.flush();
      O.close();
      exit();
      /**/
    
      shdr=loadShader("fragSource.txt","vertSource.txt");
      shader(shdr);
    
    }
    
    void draw() {
      background(0);
      translate(width/2, height/2);
      rotateY(frameCount*.1f);
      box(100);
    }
    
  • @nabr
    The code i posted runs for me, but did not run for someone I sent it to.
    Was aware of the trailing comma due to the macros which I see you spotted, but that's valid in C which glsl is based on so maybe the omission of version was the problem?

    In your first skech this gives me an error,
    "vCol=vec3[3u](vec3(1f,0f,0f),vec3(0f,1f,0f),vec3(0f,0f,1f))[gl_VertexID%3];" , replacing it with this works for me "vCol=mat3(1,0,0, 0,1,0, 0,0,0)[gl_VertexID%3];" ,

    Your second code just closes, after removing line 42 which sais exit(); it runs though is neat.
    I was not aware of the Automatically generated transformation matrix, that's why I used the PMatrix3D

  • @prince_polka

    my second code: Yes it is generating two *.txt files in the data folder of processing sketch and exti(), after that, you can comment it out. I posted it becourse -> your cube sketch works, but inline shader in processing are per default version 110. and i want to use [3u] unsigned int and f suffix for float. so i update it.

    Strange. I works on my pc : )

    What are you specs ?

    /** 
     * What are you specs ?
     *
     * ^;.;^
     * nabr (2018/Feb/12)
     *
     * forum.processing.org/two/discussion/comment/117009/
     */
    
    import com.jogamp.opengl.GL;
    import com.jogamp.opengl.GL2ES2;
    
    void setup() {
    
      size(200, 200, P3D);
    
      GL2ES2 gl = ((PJOGL)beginPGL()).gl.getGL2ES2();
    
      println("Vendor: " + gl.glGetString( GL.GL_VENDOR ) );
      println("Renderer: " + gl.glGetString( GL.GL_RENDERER) );
      println("Version: " + gl.glGetString( GL.GL_VERSION) );
    
    }  
    

    Vendor: NVIDIA Corporation
    Renderer: GeForce GTX 1050 Ti/PCIe/SSE2
    Version: 4.6.0 NVIDIA 390.77

  • edited February 2018

    @nabr

    Vendor: ATI Technologies Inc.
    Renderer: 67EF:CF
    Version: 4.5.13469 Core Profile Context 21.19.525.0

  • @prince_polka

    ..."but did not run for someone I sent it to."

    life is about survival of the fittest :)

  • @prince_polka

    ok so, it seems i have to use 1.f as suffix that was the error.
    https://bl.ocks.org/tolkanabroski/ea65ae19cb1a028c59eee642c3429a4e

    windows/angel bug, - whatever, i changed my comment.

  • This will print This program wasn't written in Processing it was built for C if ran in processing.
    And if ran in C (gcc or clang) it'll print the opposite

    void setup(){//\
    System.out.
    printf("This program wasn't written in %s it was built for %s !",//\
    "Processing","C"//\
    /*
    "C","Processing"//\
    */
    );}//\
    /*
    main(){setup();}//*/
    
Sign In or Register to comment.