🔒 Closed Javascript (for loop) changing color from black to yellow

Status
Not open for further replies.

chad0926

Leecher
Hi,

I'm new here and I'm also starting to learn programming from scratch (non-IT grad). Hoping to switch career from teaching to programming.

HELP!

How can I change a 200x200 black image to yellow using Javascript's For Loop? Nalilito kasi ako sa "formula".
Eto ang naisip ko. Black is (0,0,0) while yellow is (255,255,0).

var img = new SimpleImage(200,200);
print(img);

for (var pixel of img.values()){
var newG = 255 - pixel.getGreen();
var newR = 255 - pixel.getRed();
var newB = 0 - pixel.getBlue();
pixel.setGreen(newG);
pixel.setRed(newR);
pixel.setBlue(newB);
}

Thanks for the help!
 
let r = 255;
let g = 255;
let b = 0;

for (let pixel of img.values()){
pixel.setRed(r);
pixel.setGreen(g);
pixel.setBlue(b);
}
 
kita ko na ginamit mo library, try mo to:

let canvas = document.getElementById('myCanvas');

let img = new SimpleImage(200,200);
let r = 255;
let g = 255;
let b = 0;

for (let x = 0; x < 200; x++){
for (let y = 0; y < 200; y++){
img.setRed(x,y,r);
img.setGreen(x,y,g);
img.setBlue(x,y,b);

}
}

img.drawTo(canvas);
 
kita ko na ginamit mo library, try mo to:

let canvas = document.getElementById('myCanvas');

let img = new SimpleImage(200,200);
let r = 255;
let g = 255;
let b = 0;

for (let x = 0; x < 200; x++){
for (let y = 0; y < 200; y++){
img.setRed(x,y,r);
img.setGreen(x,y,g);
img.setBlue(x,y,b);

}
}

img.drawTo(canvas);

Ayaw pa rin e.
Error:
Identifier 'img' has already been declared
 
Ayaw pa rin e.
Error:
Identifier 'img' has already been declared
LAST
delete mo lahat ng code dyan sa box bago i paste.


let img = new SimpleImage(200,200);
let r = 255;
let g = 255;
let b = 0;


for (let pixel of img.values()){
pixel.setRed(r);
pixel.setGreen(g);
pixel.setBlue(b);
}

print(img);
 
LAST
delete mo lahat ng code dyan sa box bago i paste.


let img = new SimpleImage(200,200);
let r = 255;
let g = 255;
let b = 0;


for (let pixel of img.values()){
pixel.setRed(r);
pixel.setGreen(g);
pixel.setBlue(b);
}

print(img);

Sa wakas! Salamat Wolfrain14. Dami ko pa kelangan alamin.
 
Status
Not open for further replies.

About this Thread

  • 9
    Replies
  • 783
    Views
  • 2
    Participants
Last reply from:
chad0926

Trending Topics

Online now

Members online
1,093
Guests online
981
Total visitors
2,074

Forum statistics

Threads
2,273,784
Posts
28,951,584
Members
1,234,954
Latest member
zreckorbion
Back
Top