problems with Pgraphics
in
Programming Questions
•
1 year ago
Hello everybody, i'm trying to work with PGraphics, but something keeps getting wrong. The problem that i can't understand is why processing draws on the screen everything between beginDraw() and endDraw(), but doesn't draw anything when i call the picture back with image(pic, x, y).
It seemed so easy in the beginning but i already wasted 3 nights looking for bugs in my code or common problems in the internet.
Thank you in advance!
It seemed so easy in the beginning but i already wasted 3 nights looking for bugs in my code or common problems in the internet.
Thank you in advance!
- int pxwidth=2;
- PGraphics randompic = createGraphics(100, 100, P2D);
- void setup(){
- size(100,100);
- noStroke();
- background(255);
- }
- void draw(){
- background(255);
- if (keyPressed){
- if(key == 'a' || key == 'A'){
- randompic.beginDraw();
- for (int x=0; x<width/pxwidth; x++){
- for (int y=0; y<height/pxwidth; y++){
- int colore = (int)random(0,20);
- if (colore < 10) {fill(0);} else if (colore >= 10) {fill(255);}
- rect(x*pxwidth, y*pxwidth, pxwidth, pxwidth);
- }
- }
- randompic.endDraw();
- }
- if(key == 's' || key == 'S'){
- image(randompic, 0, 0);
- }
- }
- }
1