# Starting Screen - struggling with code

**URL:** <https://discourse.processing.org/t/starting-screen-struggling-with-code/20473>\
**Category:** Libraries\
**Tags:** homework\
**Created:** [May 4, 2020, 5:55pm UTC](https://discourse.processing.org/t/starting-screen-struggling-with-code/20473 "2020-05-04T17:55:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eduwu](https://avatars.discourse-cdn.com/v4/letter/e/cc9497/32.png) [@Eduwu](https://discourse.processing.org/u/Eduwu)\
**Post date:** [May 4, 2020, 5:55pm UTC](https://discourse.processing.org/t/starting-screen-struggling-with-code/20473/1 "2020-05-04T17:55:22Z")

</div>

Hi!! I’m very new at coding and am doing a project that involves de video library, but I encounter a few problems.  
The first one is that I’m trying to do a starting screen for my program but the image I made doesn’t appear when I run the program.  
The second one is that when I’m changing between the first 2 classes/filters, they overlap, but I want it to start from a black background, but if I put it in the code it loops and doesn’t do the effect I want.  
Here is my code.

```auto
import processing.video.*;
filtro[] ellipses;
pt[] puntos;
filtro5 filt;
pixeles r;
Capture cam;
float c;

int click,stage;
PImage starpro;
void setup(){
 
 size(640,480); 
 stage=1;
  cam= new Capture(this,640,480);
  cam.start();
  puntos=new pt[100];
  starpro=loadImage("starpro.jpg");
  
starpro.resize(width,height);
  for(int i =0; i<puntos.length;i++){
    
    puntos[i]=new pt();
  }
  ellipses = new filtro [500];
  for(int i = 0; i<ellipses.length;i++){
    
  ellipses[i]=new filtro();
  }
  filt=new filtro5();
  background(starpro);
  r= new pixeles();
  
}

void draw(){
  if(stage==1){
    
    if(mousePressed==true){
     stage=2; 
    }
  }
  if(stage==2){
    
  }
  cam.read();
  if(click==1){
   
  for(int i = 0;i<ellipses.length;i++){
  
   ellipses[i].display(); 
   ellipses[i].move();
  }
  }
  else if(click==2){

for(int i = 0;i<puntos.length;i++){

    
  puntos[i].disp();
}
  }
else if(click==3){
    
  r.pix();
  }
  else if(click==4){
   filt.filtro(); 
  }
else{
background(0);  
  
}
 
    
  

}
void keyPressed(){ 
  
if(key=='g'){
fill(255);
  save("foto.jpg");
  textSize(70);
  text("SAVED", width/2,height/4);

}
}
void mousePressed(){
  click++;
  if(click==5){
  click=0;
  }
}
  class filtro{
  float x,y,vx,vy;
  
  filtro(){
   x= width/2;
   y=height/2;
   float a= random(TWO_PI);
   float speed=random(1,2);
   vx = cos(a)*speed;
   vy = sin(a)*speed;
  }
    void display(){
      
     noStroke();
     color c= cam.get(int(x),int(y));
     fill(c,25);
   
     triangle(5+x, 25+y, 18+x, 5+y, 26+x, 25+y);
  
    }
    void move(){
     x=x+vx;
     y=y+vy;
     if(y<0){
       y=height;
      
    }
    if(y > height){
    y=0;
}
if(x<0){
  x=width;
}
if(x>width){
  x=0;
    }
    }
}
class pt{
  float pointillize=10;
  pt(){
   
  }
  
void disp(){

   int x = int(random(cam.width));
  int y = int(random(cam.height));
  
    int loc = x + y*cam.width;
    loadPixels();
  float r = red(cam.pixels[loc]);
  float g = green(cam.pixels[loc]);
  float b = blue(cam.pixels[loc]);
  noStroke();
  

  fill(r,g,b,100);
  ellipse(x,y,pointillize,pointillize); 
  
  }
    
  }
  class pixeles{
  int pixelSize=10;
float angle;
  pixeles(){

    
  }
  void pix(){
    noStroke();
     pixelSize=int(map(mouseX, width, 0, 1, 80));
  for (int x=0; x<width; x+=pixelSize) {
    for (int y=0; y<height; y+=pixelSize) {
      color c=cam.get(x, y);
      fill(c);
      rect(x, y, pixelSize, pixelSize);
    }
  }
}
  }
class filtro5{

  int cellsize = 10; 
int cols, rows; 
  filtro5(){
    
    cols = width/cellsize;             
  rows = height/cellsize;           
    
  }

void filtro(){
   for (int i = 0; i < cols; i++ ) {
    for (int j = 0; j < rows; j++ ) {
      int x = i*cellsize + cellsize/2; 
      int y = j*cellsize + cellsize/2; 
      int loc = x + y*width;           
      color c = cam.pixels[loc];       
      float yy = map(brightness(cam.pixels[loc]), 50, 255, 0, mouseX);
      pushMatrix();
      translate(x+yy, y+yy); 
      fill(c);
      noStroke();
      rectMode(CENTER);
      rect(0, 0, cellsize, cellsize);
      popMatrix();
    }
  }
}
  
}

```

Thanks!

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 4, 2020, 7:19pm UTC](https://discourse.processing.org/t/starting-screen-struggling-with-code/20473/2 "2020-05-04T19:19:03Z")

</div>

> [@Eduwu](#):
>
> if(stage==1){  
> // image = ?  
> if(mousePressed==true){  
> stage=2;  
> }  
> }
> 
> if(stage==2){  
> …

you don’t call image() in stage 1

Chrisir

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [May 5, 2020, 2:21am UTC](https://discourse.processing.org/t/starting-screen-struggling-with-code/20473/3 "2020-05-05T02:21:16Z")

</div>

Hello,

It took a few seconds for cam to load in setup on my PC.

I moved some code up so background would display _before_ cam started up; this worked here and I had a background while waiting… its a long few seconds but enough to display background image. If setup was faster you could also have added a delay().  
You did not need a background in stage 1 because it kept the background from setup() until it was changed; you may still want to load one in stage 1 to indicate when starting draw().  
You did not define a new background for stage 2.

```auto
void setup() 
  {
  size(640, 480); 
  starpro = loadImage("starpro.jpg");
  starpro.resize(width, height);
  background(starpro);

  stage=1;
  cam = new Capture(this, 640, 480, 30);
  cam.start();
  }

void draw() 
  {  
  if (stage==1) 
    {
    //background(255);
    if (mousePressed==true) 
      {
      stage=2;
      }
    }
  
  if (stage==2) 
    {
    background(0);
    }
  } 

```

`:)`
