Estoy lanzando este código de demostración de conferencias.
package demos;
import processing.core.PApplet;
import processing.core.PImage;
public class MyPApplet extends PApplet{
PImage img;
public void setup() {
//Add setup code for MyPApplet
size(600,600); //set canvas size>>changed to size(700,800)
background(255); //set canvas color
stroke(0); //set pen color
img = loadImage("palmTrees.jpg", "jpg");
img.resize(0, height); //resize loaded image to full height of canvas
image(img, 0, 0); //display image
}
public void draw() {
//Add drawing code for MyPApplet
int[] color = sunColorSec(second()); //calculate color code for sun
fill(color[0],color[1],color[2]); //set sun color
ellipse(width/4,height/5,width/4,height/5); //draw sun
}
/** Return the RGB color of the sun at this number of seconds in the minute */
public int[] sunColorSec(float seconds)
{
int[] rgb = new int[3];
// Scale the brightness of the yellow based on the seconds. 0 seconds
// is black. 30 seconds is bright yellow.
float diffFrom30 = Math.abs(30-seconds);
float ratio = diffFrom30/30;
rgb[0] = (int)(255*ratio);
rgb[1] = (int)(255*ratio);
rgb[2] = 0;
//System.out.println("R" + rgb[0] + " G" + rgb[1] + " B" + rgb[2]);
return rgb;
}
public static void main (String[] args) {
//Add main method for running as application
PApplet.main(new String[] {"--present", "MyPApplet"});
}
}
El problema es que cuando intento cambiar el tamaño de mi lienzo a más de (600,600), la imagen de fondo desaparece. Esto es de lo que estoy hablando: y aquí hay una copia de la imagen en la que estoy trabajando https://www.mediafire.com/?dnpghfefeo7rl5o
Antes:
Después:
No está mostrando la imagen en su draw
método. En cambio, solo lo muestra una vez, en formato setup
. Cuando cambie el tamaño del lienzo, la ventana se borrará y draw
se llamará. Allí deberías pintar la imagen:
public void draw() {
image(img, 0, 0); // <---- Add this here!
//Add drawing code for MyPApplet
...
...
Este artículo se recopila de Internet, indique la fuente cuando se vuelva a imprimir.
En caso de infracción, por favor [email protected] Eliminar
Déjame decir algunas palabras