Loading...
Logo
Processing Forum
I am trying to make a .pde display fullscreen using processing.js and the <canvas> tag.

But it is not taking into account the browser menu etc.

Can anyone help?

Copy code
  1. // Global variables
    float radius = 10.0;
    int X, Y;
    int nX, nY;
    int delay = 16;

    // Setup the Processing Canvas
    void setup(){
      size(screen.width,screen.height);
        strokeWeight( 10 );
      frameRate( 25 );
      X = width / 2;
      Y = height / 2;
      nX = X;
      nY = Y;
      smooth(); 
    }

    // Main draw loop
    void draw(){
     
      radius = radius + sin( frameCount / 4 );
     
      // Track circle to new destination
      X+=(nX-X)/delay;
      Y+=(nY-Y)/delay;
     
      // Fill canvas grey
      background( 100 );
     
      // Set fill-color to blue
      //fill( 0, 121, 184 );
      noFill();
     
      // Set stroke-color white
      stroke(0);
     
      // Draw circle
      ellipse( X, Y, radius, radius );                 
    }


    // Set circle's next destination
    void mouseMoved(){
      nX = mouseX;
      nY = mouseY; 
    }

Replies(6)

Hey, I recently tried doing this and I found the best way to do this was to use javascript event listeners. If you're new to that, then I'd suggest using jQuery. Something like this in void setup:

Make sure that you import jquery before your pjs loads.

Copy code
  1. // Gauge the proper height
  2. if( jQuery(document).height() > jQuery(window).height() )
  3.     setupHeight = jQuery(document).height();
  4. else
  5.     setupHeight = jQuery(window).height();
  6. jQuery('canvas').width(jQuery(window).width());
  7. jQuery('canvas').height(setupHeight);
  8. size(jQuery(window).width(), setupHeight);

You could be sneaky and abstract that part to a function so that when you call window.resize()  it modifies again. Then don't forget your stylesheet:

Copy code
  1. canvas {
  2.   margin:  0px;
  3.   padding: 0px;
  4.   position: fixed;
  5. }

An example of this I made here.


http://jonobr1.com/
In fact. Thinking about it now. Did you make sure that your stylesheet modified the canvas tag in such a way? Inherently browsers have a default padding / margin and that would force scrollbars on something that was width: 100%, height: 100%

Got an example of what you're trying to do?


http://jonobr1.com/
Thanks for the help.

Do i put the "guage the proper height" in the void setup in the .pde file?

I like your website, its what I am trying to do myself. Having a background canvas element full screen and having content on top.

I managed to get the app to display full screen by putting the <canvas> tag inside of a <div style=" position: fixed; width="100%"; height="100%"; >

but no other content is visible even if I am setting the z-index's.
Actually never mind it wasn't working in coda. Forgot to test it in firefox.

It works perfectly thanks for your help. But when I put any <divs> on top of the background the mouseMoved() is not recognised and doesn't animate.

Any idea on how to fix?
Glad that helped. To answer your first question, yes the "gauge proper height" is in void setup

To answer your next question. The problem is that your processing void mouseMoved or equivalent is bound to the <canvas> which is under your other div via css z-index. Don't fret though, there is an easy way around this. You need to just send that mouse data that is bound to your document, not the <canvas>

Put this in your .pjs:

Copy code
  1. void mouseMoved(float xpos, float ypos) {

  2. // put what you'd normally put here
  3. // for mouse movement
  4. }

  5. jQuery(document).mousemove(function(e) {
  6.     mouseMoved(e.pageX, e.pageY);
  7.     if(!mousePos) mousePos = new PVector(e.pageX, e.pageY);
  8.     else {
  9.         mousePos.x = e.pageX;
  10.         mousePos.y = e.pageY;
  11.     }
  12. });


http://jonobr1.com/
Thank you again for being so helpful.

I have input the code but it doesn't seem to work, have I put it in my file correctly?

Copy code
  1.  
    // Global variables
    float radius = 10.0;
    int X, Y;
    int nX, nY;
    int delay = 50;

    // Setup the Processing Canvas
    void setup(){

      // Gauge the proper height

        if( jQuery(document).height() > jQuery(window).height() )
        setupHeight = jQuery(document).height();
        else
        setupHeight = jQuery(window).height();
        jQuery('canvas').width(jQuery(window).width());
        jQuery('canvas').height(setupHeight);
        size(jQuery(window).width(), setupHeight);

      strokeWeight( 10 );
      frameRate( 25 );
      X = width / 2;
      Y = height / 2;
      nX = X;
      nY = Y;
      smooth(); 
    }

    // Main draw loop
    void draw(){
     
      radius = radius + sin( frameCount / 4 );
     
      // Track circle to new destination
      X+=(nX-X)/delay;
      Y+=(nY-Y)/delay;
     
      // Fill canvas grey
      background( 255 );
     
      // Set fill-color to blue
      //fill( 0, 121, 184 );
      noFill();
     
      // Set stroke-color white
      stroke(0);
     
      // Draw circle
      ellipse( X, Y, radius, radius );                 
    }


    // Set circle's next destination
    void mouseMoved(){
      nX = mouseX;
      nY = mouseY; 
    }


    void mouseMoved(float xpos, float ypos) {

        nX = mouseX;
      nY = mouseY; 
    }

    jQuery(document).mousemove(function(e) {
        mouseMoved(e.pageX, e.pageY);
        if(!mousePos) mousePos = new PVector(e.pageX, e.pageY);
        else {
            mousePos.x = e.pageX;
            mousePos.y = e.pageY;
        }
    });