# Don\`t work void mousePressed

**URL:** <https://discourse.processing.org/t/don-t-work-void-mousepressed/26280>\
**Category:** Coding Questions\
**Created:** [December 15, 2020, 8:52pm UTC](https://discourse.processing.org/t/don-t-work-void-mousepressed/26280 "2020-12-15T20:52:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pundy](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/pundy/32/11447_2.png) [@pundy](https://discourse.processing.org/u/pundy)\
**Post date:** [December 15, 2020, 8:52pm UTC](https://discourse.processing.org/t/don-t-work-void-mousepressed/26280/1 "2020-12-15T20:52:40Z")

</div>

int K = 2;  
int L1 = 1;  
int P1 = 0;  
int L2 = 3;  
int P2 = 4;  
color k1,k2,l1,l2,p1,p2,l3,l4,p3,p4,len,len2,ban,ban2;  
void setup(){  
size(500,500);  
background(145, 209, 189);  
k1=color(255,70,64);  
k2=color(194,53,48);  
l1=color(255,65,59);  
l2=color(255,55,50);  
p1=color(200,45,50);  
p2=color(200,30,30);  
l3=color(245,55,49);  
l4=color(245,45,40);  
p3=color(190,35,40);  
p4=color(190,20,20);  
len=color(227,189,52);  
len2=color(217,179,62);  
ban=color(237,199,62);  
noLoop();  
}

void draw(){

setGradient(150,190,350,150, k1, k2, K); // кришка quad(250,150,350,190,250,230,150,190);  
setGradient(150,190,250,230, l1, l2, L1); //ліва кришка  
setGradient(250,230,350,190, p1, p2, P1); //права кришка  
setGradient(160,215,250,272, l3, l4, L2); //ліва стінка  
setGradient(250,251,340,190, p3, p4, P2); //права стінка  
//лента

noStroke();  
fill(len);  
quad(190,173,210,165,310,206,290,214); //зліва-направо кришка  
quad(293,165,313,173,210,214,190,206); //справа-наліво кришка  
quad(190,205,210,213,210,234,190,226); //ліва кришка  
quad(290,212,310,205,310,226,290,234); //права кришка  
fill(len2);  
quad(195,227,215,235,215,317,195,310); //ліва стінка  
quad(285,235,305,227,305,310,285,318); //права стінка  
//бантик  
fill(ban);  
noStroke();  
//права завитуха  
int x=250;  
float y=0;  
int r=20;  
int z=205;  
float df= 2_PI/18;  
for (float f=df; f\<2_PI; f += df)  
{  
x = x+3;  
y = z - sin(f) \* r;  
ellipse( x, y, 20, 20);  
z=z+2;  
}  
//ліва завитуха  
int x1=250;  
int z1=205;  
float y1;  
float df1= 2_PI/18;  
for (float f1=df1; f1\<2_PI; f1 += df1)  
{  
x1 = x1-3;  
y1 = z1 - sin(f1) \* r;  
ellipse( x1, y1, 20, 20);  
z1=z1+2;  
}  
stroke(len2);  
circle(230,190,40); //ліва частина  
circle(270,190,40); //права частина  
circle(250,190,30); //цент банта  
//після натискання  
}  
void mousePressed() {  
background(145, 209, 189);  
fill(22, 135, 31);  
triangle(250,10,300,60,200,60);  
triangle(250,30,320,100,180,100);  
triangle(250,50,340,140,160,140);  
}

//кришка  
void setGradient(int x, int y,float w, float h, color z1, color z2, int ax ) {

noFill();

if (ax == K) {  
float k3=map(x, y, h, 0, 0.4);  
float k31=k3;  
for (int i = x; i \<= w; i++) {  
float inter = map(i, x, w, 0, 1);  
color k = lerpColor(z1, z2, inter);  
stroke(k);  
line(i, y-k31, i, y+k31);  
if (i \<= w-100) {  
k31=k31+k3;}  
else {  
k31=k31-k3;}  
}  
}  
else if (ax==L1) {  
float k3=map(x, y, h, 0, 0.4);  
float k31=k3;  
for (int i = x; i \<= w; i++) {  
float inter = map(i, x, w, 0, 1);  
color k = lerpColor(z1, z2, inter);  
stroke(k);  
line(i, y-k31,i,y-k31+20);  
k31=k31+k3;  
}  
}  
else if (ax==P1) {  
float k3=map(x, y, h, 0, 0.8);  
float k31=k3;  
for (int i = x; i \<= w; i++) {  
float inter = map(i, x, w, 0, 1);  
color k = lerpColor(z1, z2, inter);  
stroke(k);  
line(i, y-k31,i,y-k31+20);  
k31=k31-k3;  
}  
}  
else if (ax==L2) {  
float k3=map(x, y, h, 0, 0.4);  
float k31=k3;  
for (int i = x; i \<= w; i++) {  
float inter = map(i, x, w, 0, 1);  
color k = lerpColor(z1, z2, inter);  
stroke(k);  
line(i, y-k31,i,y-k31+80);  
k31=k31+k3;  
}  
}  
else if (ax==P2) {  
float k3=map(x, h, y, 0, 0.4);  
float k31=k3;  
for (int i = x; i \<= w; i++) {  
float inter = map(i, x, w, 0, 1);  
color k = lerpColor(z1, z2, inter);  
stroke(k);  
line(i, y-k31,i,y-k31+80);  
k31=k31+k3;  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [December 15, 2020, 8:59pm UTC](https://discourse.processing.org/t/don-t-work-void-mousepressed/26280/2 "2020-12-15T20:59:52Z")

</div>

Hi,

Welcome to the forum! 😉

First of all, you can format your code by using the `</>` button in the message editor. (Also remember to press `Ctrl+T` in the Processing IDE for auto formating 👍 )

When you ask a question on the forum, you should elaborate a little more. Because giving only the question in the title is not a good practice and without saying hi everyone!

Also giving a full code without explanations of what it’s doing is a little bit rude, so be gentle with people trying to help you 😍

You can read the guidelines here : [https://discourse.processing.org/faq](https://discourse.processing.org/faq)

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [December 15, 2020, 9:20pm UTC](https://discourse.processing.org/t/don-t-work-void-mousepressed/26280/3 "2020-12-15T21:20:45Z")

</div>

Мені сподобався малюнок. Щоб намалювати трикутники, ви можете повністю видалити функцію “void mousePress ()” і замінити її цим кодом, розмістивши її внизу функції draw ().

```auto
if (mousePressed) {
    fill(22, 135, 31);
    triangle(250, 10, 300, 60, 200, 60);
    triangle(250, 30, 320, 100, 180, 100);
    triangle(250, 50, 340, 140, 160, 140);
  }

```
