How to replace a Shape with an image ? PShape to PImage

I am trying to exchange all forms for images

What is the correct way to do it?

The game opens and no error appears
The image just does not appear when I press the Y key

hope someone can help me
thank you in advance :slightly_smiling_face:

PFont font;
//PImage amarelo;
//PImage plastico;
//PImage caixa;

int number = 0;

int start = 0;

int aa =0;
PShape aaa;

int bb=0;
PShape bbb;

int cc=0;
PShape ccc;

int dd=0;
PShape ddd;

int ee =0;
PShape eee;

int ff =0;
PShape fff;

int gg =0;
PShape ggg;

int hh=0;
PShape hhh;

int ii=0;
PShape iii;

int jj =0;
PShape jjj;

int kk=0;
PShape kkk;

int ll =0;
PShape lll ;

int mm =0;
PShape mmm ;

int nn =0;
PShape nnn;

int oo =0;
PShape ooo;

int pp =0;
PShape ppp;

int qq=0;
PShape qqq;

int rr=0;
PShape rrr;

int ss =0;
PShape sss;

int tt=0;
PShape ttt;

int uu= 0;
PShape uuu;

int vv =0;
PShape vvv;

int xx =0;
PShape xxx;

int yy=0;
PImage yyy;
//PImage img;

int ww=0;
PShape www;

int zz =0;
PShape zzz;

int st=0;
PShape ste;

float x = new float[18];
float y = new float[18];
float segLength = 50;
float segHeight = 50;
float r;
float g;
float b;
float rect ;

void setup() {

size(1366,768);

strokeWeight(5);
stroke(255, 100);
//caixa = loadImage(β€œcaixa3.png”);

}

void draw() {
background(150);
//image(caixa, 0, 0);

if (start == 0){

fill(0);
rect(0,0,1366,768);

//font = createFont(β€œDialogInput.bold”, 40);
// textFont(font);
textSize(70);
fill(250);
text(β€œPress the mouse to start”, 300, 300);
//textAlign(CENTER, CENTER);

textSize(20);
fill(250);
text(" Drag and click the mouse and press any letter to create:", 420, 500);
fill(250);
text("Use the caps lock to take each letter individually, ", 465, 550);
fill(250);
text(β€œpress S to save and D to delete.”, 550, 600);

}

if (start > 0){

dragSegment(0, mouseX, mouseY);
for(int i=0; i<x.length-1; i++) {
dragSegment(i+1, x[i], y[i]);
}

if(keyPressed) {
if(key==β€˜s’||key== β€˜S’) {
println(β€œSaving…”);
String s = β€œscreen” + nf(number,4) +β€œ.jpg”;
save(s);
number++;
println(β€œDone saving.”);
}
}
}
}

void mouseClicked() {
start =1;
}

void dragSegment(int i, float xin, float yin) {
float dx = xin - x[i];
float dy = yin - y[i];
float angle = atan2(dy, dx);
x[i] = xin - cos(angle) * segLength;
y[i] = yin - sin(angle) * segLength;
segment(x[i], y[i], angle);

x[i] = xin - cos(angle) * segHeight;
y[i] = yin - sin(angle) * segHeight;

}

void segment(float x, float y, float a) {
pushMatrix();
translate(x, y);
rotate(a);

if(keyPressed) {

if (key== β€˜A’||key==β€˜d’||key== β€˜D’) {
aa=0;

}

if (key==β€˜a’) {
aa=1;
}
}

if (aa==1) {

aaa = createShape(ARC,0, y, 80, 80, PI+QUARTER_PI, TWO_PI);
shape(aaa);
}

fill(r,g,0);
if(keyPressed) {

if (key==β€˜Y’||key==β€˜d’||key== β€˜D’) {
yy=0;

}

if (key==β€˜y’) {
yy=1;
}
}

if (yy==1) {
yyy = loadImage(β€œcaixa3.png”);
//shape(yyy);

}

fill(r,0,b);

fill(0,g,b);

if(keyPressed) {

if (key==β€˜K’||key==β€˜d’||key== β€˜D’) {
kk=0;

}

if (key==β€˜k’) {
kk=1;
}
}

if (kk==1) {

kkk = createShape(ELLIPSE,0,50,10,60);
shape(kkk);
}

fill(r,g,0);
if(keyPressed) {

if (key==β€˜K’||key==β€˜d’||key== β€˜D’) {
kk=0;

}

if (key==β€˜k’) {
kk=1;
}
}

if (kk==1) {

kkk = createShape(ELLIPSE,0,10,30,5);
shape(kkk);
}

fill(r,0,b);
if(keyPressed) {

if (key==β€˜Q’||key==β€˜d’||key== β€˜D’) {
qq=0;

}

if (key==β€˜q’) {
qq=1;
}
}

if (qq==1) {

qqq = createShape(RECT,0,0,30, 30);
shape(qqq);
}

fill(0,g,b);
if(keyPressed) {

if (key==β€˜R’||key==β€˜d’||key== β€˜D’) {
rr=0;

}

if (key==β€˜r’) {
rr=1;
}
}

if (rr==1) {

rrr = createShape(RECT,x,0,10, segLength);
shape(rrr);
}

fill(r,g,0);
if(keyPressed) {

if (key==β€˜B’||key==β€˜d’||key== β€˜D’) {
bb=0;

}

if (key==β€˜b’) {
bb=1;
}
}

if (bb==1) {
bbb = createShape(ELLIPSE,0,y,20,60);
shape(bbb);
}

fill(0,g,b);
if(keyPressed) {

if (key==β€˜C’||key==β€˜d’||key== β€˜D’) {
cc=0;

}

if (key==β€˜c’) {
cc=1;
}
}

if (cc==1) {

ccc = createShape(ELLIPSE,0,0,50,50);
shape(ccc);
}

fill(r,0,b);
if(keyPressed) {

if (key==β€˜E’||key==β€˜d’||key== β€˜D’) {
ee=0;

}

if (key==β€˜e’) {
ee=1;
}
}

if (ee==1) {

eee = createShape( TRIANGLE,300, 75, 8, 20, 6, 7);
shape(eee);
}

fill(0,g,b);
if(keyPressed) {

if (key==β€˜F’||key==β€˜d’||key== β€˜D’) {
ff=0;

}

if (key==β€˜f’) {
ff=1;
}
}

if (ff==1) {

fff = createShape( LINE,0, 30, 75, 85);
shape(fff);
}

fill(r,g,0);
if(keyPressed) {

if (key==β€˜G’||key==β€˜d’||key== β€˜D’) {
gg=0;

}

if (key==β€˜g’) {
gg=1;
}
}

if (gg==1) {

ggg = createShape( ELLIPSE,40,40,10,10);
shape(ggg);
}

fill(0,g,b);
if(keyPressed) {

if (key==β€˜H’ ||key==β€˜d’||key== β€˜D’ ){
hh=0;

}

if (key==β€˜h’) {
hh=1;
}
}

if (hh==1) {

hhh = createShape( RECT,X,Y,10,300);
shape(hhh);
}

fill(r,0,b);
if(keyPressed) {

if (key==β€˜I’||key==β€˜d’||key== β€˜D’) {
ii=0;

}

if (key==β€˜i’) {
ii=1;
}
}

if (ii==1) {

iii = createShape( ELLIPSE,0,y,80,40 );
shape(iii);
}

fill(r,g,0);
if(keyPressed) {

if (key==β€˜J’||key==β€˜d’||key== β€˜D’) {
jj=0;

}

if (key==β€˜j’) {
jj=1;
}
}

if (jj==1) {

jjj = createShape(ARC, X, 100, 95, 50, 0, HALF_PI );
shape(jjj);
}
fill(r,0,b);
if(keyPressed) {

if (key==β€˜J’||key==β€˜d’||key== β€˜D’) {
jj=0;

}

if (key==β€˜j’) {
jj=1;
}
}

if (jj==1) {

jjj = createShape(TRIANGLE,30, 70, 80, 12, 16, 13);
shape(jjj);
}

fill(0,g,b);
if(keyPressed) {

if (key==β€˜K’||key==β€˜d’||key== β€˜D’) {
kk=0;

}

if (key==β€˜k’) {
kk=1;
}
}

if (kk==1) {

kkk = createShape(ARC, 50, 55, 50, 50, 0, HALF_PI );
shape(kkk);
}

fill(r,g,0);
if(keyPressed) {

if (key==β€˜L’||key==β€˜d’||key== β€˜D’) {
ll=0;

}

if (key==β€˜l’) {
ll=1;
}
}

if (ll==1) {

lll = createShape(LINE,x,40, 85, 75 );
shape(lll);
}

fill(r,0,b);
if(keyPressed) {

if (key==β€˜M’||key==β€˜d’||key== β€˜D’) {
mm=0;

}

if (key==β€˜m’) {
mm=1;
}
}

if (mm==1) {

mmm = createShape(RECT,69,0,20,40);
shape(mmm);
}

if(keyPressed) {

if (key==β€˜M’||key==β€˜d’||key== β€˜D’) {
mm=0;

}

if (key==β€˜m’) {
mm=1;
}
}

if (mm==1) {

mmm = createShape(RECT,x,10,60,10);
shape(mmm);
}
fill(r,0,b);
if(keyPressed) {

if (key==β€˜N’||key==β€˜d’||key== β€˜D’) {
nn=0;

}

if (key==β€˜n’) {
nn=1;
}
}

if (nn==1) {

nnn= createShape(TRIANGLE,x, 0, 8, 50, 6, 15);
shape(nnn);
}
fill(0,g,b);
if(keyPressed) {

if (key == β€˜O’ ||key==β€˜d’||key== β€˜D’) {
oo=0;

}

if (key==β€˜o’) {
oo=1;
}
}

if (oo==1) {

ooo= createShape(ELLIPSE,0,y,50,10);
shape(ooo);
}
fill(r,g,0);
if(keyPressed) {

if (key==β€˜O’||key==β€˜d’||key== β€˜D’) {
oo=0;

}

if (key==β€˜o’) {
oo=1;
}
}

if (oo==1) {

ooo= createShape(ELLIPSE,0,y,20,20);
shape(ooo);
}

fill(r,0,b);
if(keyPressed) {

if (key==β€˜P’||key==β€˜d’||key== β€˜D’) {
pp=0;

}

if (key==β€˜p’) {
pp=1;
}
}

if (pp==1) {

ppp= createShape(TRIANGLE,0, 500, 4, 0, 6, 30);
shape(ppp);
}

fill(0,g,b);
if(keyPressed) {

if (key==β€˜T’||key==β€˜d’||key== β€˜D’) {
tt=0;

}

if (key==β€˜t’) {
tt=1;
}
}

if (tt==1) {

ttt= createShape (TRIANGLE,30, 75, 58, 20, 86, 75);
shape(ttt);
}

fill(r,0,b);
if(keyPressed) {

if (key==β€˜T’||key==β€˜d’||key== β€˜D’) {
tt=0;

}

if (key==β€˜t’) {
tt=1;
}
}

if (tt==1) {

ttt= createShape (TRIANGLE,75, 16,30, 75, 58, 20 );
shape(ttt);
}

fill(r,g,0);

if(keyPressed) {

if (key==β€˜U’||key==β€˜d’||key== β€˜D’) {
uu=0;

}

if (key==β€˜u’) {
uu=1;
}
}

if (uu==1) {

uuu= createShape ( ARC, 50, 55, 600, 60, HALF_PI, PI);
shape(uuu);
}

fill(0,g,b);
if(keyPressed) {

if (key==β€˜V’||key==β€˜d’||key== β€˜D’) {
vv=0;

}

if (key==β€˜v’) {
vv=1;
}
}

if (vv==1) {

vvv= createShape (RECT,0,0,90,7);
shape(vvv);
}

fill(0,g,b);
if(keyPressed) {

if (key==β€˜X’||key==β€˜d’||key== β€˜D’) {
xx=0;

}

if (key==β€˜x’) {
xx=1;
}
}

if (xx==1) {

xxx= createShape (ELLIPSE,6, 100,100,100);
shape(xxx);
}
fill(r,0,b);
if(keyPressed) {

if (key==β€˜Z’||key==β€˜d’||key== β€˜D’) {
zz=0;

}

if (key==β€˜z’) {
zz=1;
}
}

if (zz==1) {

zzz= createShape (TRIANGLE,0, 10 ,300, 50, 600, 5);
shape(zzz);
}
fill(r,g,0);
if(keyPressed) {

if (key==β€˜W’||key==β€˜d’||key== β€˜D’) {
ww=0;

}

if (key==β€˜w’) {
ww=1;
}
}

if (ww==1) {

www= createShape (RECT,90,50,40,10);
shape(www);
}
fill(r,0,b);
if(keyPressed) {

if (key==β€˜W’||key==β€˜d’||key== β€˜D’) {
ww=0;

}

if (key==β€˜w’) {
ww=1;
}
}

if (ww==1) {

www= createShape (RECT,10,60,10,40);
shape(www);
}

ellipse(0,80, 30,30);
fill(250);
ellipse(80,0,15,15);
line(0, 0, segLength, 0);
line(0, y, segLength, 0);
ellipse(0,80, 10,10);
line(0,0, segHeight, segLength);

popMatrix();
}

void mousePressed(){
r = random(0,255);
g = random (0,255);
b = random(0,255);

}
<

Hello,

Please format your code:
FAQ - Processing Foundation

:)

1 Like