/    Sign up×
Community /Pin to ProfileBookmark

Shapes disappear and color won’t change after click

Hello, I’m new to coding and am working on my assessment to school and am stuck with loops and an event statement. I only need to fix the lines so they don’t disappear and fix the color when a mouse is pressed. Please please please can you help me out?

“`
var statement = [‘I’, ‘cannot’, ‘code’, ‘but’, ‘I’ , ‘am’, ‘doing’, ‘my’, ‘best’, ‘:)’];
let value = 255;
var index = 0;

function setup() {
createCanvas(600, 600);
frameRate(1);
}
function draw() {
background(0);
stroke(0);

stroke(255);
for (let lineX = 35; lineX <= 600; lineX += 35) {
line(lineX, 0, lineX, height);
}
fill(value);
stroke(1);
strokeWeight(0);
rect(175, 225, 250, 120);

fill(0);
textAlign(CENTER);
textSize(50);
text(statement[index], 300, 300);
index++;

if (mouseIsPressed) {
if (value === 255) {
value = 66;
} else {
value = 255;
}
}

}
if (index > 10) {
index = 0;
}
“`

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@ClockOutMar 28.2021 — It doesn't look like the vertical lines change so the code that draws the lines can be put into the setup function.

The user must hold down the mouse button for the color to change. If you want the background to change for a mouse click then look into using the [mouseClicked function](https://p5js.org/reference/#/p5.Element/mouseClicked).
Copy linkTweet thisAlerts:
@SempervivumMar 29.2021 — @ElizabethZ#1629626 Please use code tags when posting code: `your code here` or triple backtics.

I edited your posting accordingly.
Copy linkTweet thisAlerts:
@VITSUSAMar 30.2021 — @ElizabethZ#1629626 Have you got the solution of this problem which @Sempervivum suggested to you?
×

Success!

Help @ElizabethZ spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...