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.
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!