createGraphics() and image()

Hi,

I am slooooowly transitioning from Processing to p5.js and I am trying to re-write some of the sketches I did in Processing on p5.js

When I try to use createGraphics() method in p5.js and display a preloaded image (with image() method) in that offscreen graphic, somehow I don't get anything other than a blank screen.

When I use background() instead of image() method and display that image in the offscreen graphic I see everything, but then, of course, I cannot scale that image.

What am I doing wrong?

                    `var img, pg;
                    var canvasOfset = 10;




                    function preload() {
                      img = loadImage('http://cdni.pageflow.codevise.de/main/video_files/posters/000/000/370/v3/medium/poster-0.JPG');
                    }

                    function setup() {
                      createCanvas(windowWidth - canvasOfset, windowHeight - canvasOfset);
                      pg = createGraphics(width, height);
                    }

                    function draw() {
                      pg.background(img);
                      var c = color(255, 0, 0);
                      image(pg, 0, 0, width, height);
                    }
                    `

this works

                    `var img, pg;
                    var canvasOfset = 10;
                    var fillColor;
                    var drawn = false;



                    function preload() {
                      img = loadImage('http://cdni.pageflow.codevise.de/main/video_files/posters/000/000/370/v3/medium/poster-0.JPG');
                    }

                    function setup() {
                      createCanvas(windowWidth - canvasOfset, windowHeight - canvasOfset);
                      pg = createGraphics(width, height);
                    }

                    function draw() {
                      pg.image(img,0,0,width,height);
                      var c = color(255, 0, 0);
                      image(pg, 0, 0, width, height);
                    }
`

this does not...

Any help regarding this issue would be awesome!!

Thanks a lot.

Omer

Answers

Sign In or Register to comment.