Create Red() Green() Blue() Functions

edited October 2015 in Questions about Code

Create draw( ) function, and design following mechanisms along with for loop to read pixels; a)image( ) function to draw

b)Use red( ), green(), and blue( ) functions to show only red, green, or blue channels.

c)Mapping between the pixel position, bar height, bar color and font color: To show an interactive RGB value on a specific pixel based on the position of mouse cursor (mouseX& mouseY), create a bar graph (use rect( ) to create a bar per each color). Useful Processing commands; •text( ), textFont( ) •Color, image( ), fill( ) •updatePixels(); •loadPixels();

d)Based on simple math operators (+, -, *, %), design minimum 4 filters operated through key board interaction.

Capture

Answers

  • edited October 2015

    My Code

    PImage img, imgRed,imgGreen,imgBlue;
    
    
        void setup() {
          frameRate(24);
      size(900, 600);
    background(153);
    line(0, 0, width, height);
      // Images must be in the "data" directory to load correctly
      img = loadImage("yoshiesmall.png");
      noTint();
      imgRed= createImage(img.width, img.height,RGB);
      imgGreen= createImage(img.width, img.height,RGB);
      imgBlue=createImage(img.width, img.height,RGB);
    
    }
    
    void draw() {
      {  
      image(img, 0, 300);
      tint(0,0,255);
      image(img, 0,0, width/2, height/2);
      };
      {
       image(img, 500, 100);
        tint(255, 0, 0);
     image(img,0,0,width/2,height/2);
      };
      {
      image(img, 400, 200);
      tint(0,128,0);
       image(img,0,0,width/2,height/2);
      };
    }
    

    Producing this output:

    Capture2

  • homework?

    please look up how to post code - there is a sticky post on that

    did you solve task a) with that or b) ? Or all?

    DO you have a question?

  • I COULD ONLY SOLVE A AS B DOES NOT WORK FOR ME

  • i need a little help fixing my code so i could get B and C

  • For B:

    I think you are supposed to use a loop to iterate over all pixels of the image and then use the functions red(), blue() and green() to extract the different channels.
    You could have a look at this tutorial, there is an example in the section "Intro To Image Processing" that seems to be pretty close to what you are supposed to do for B.

  • how would i fix my code

  • You haven't solved anything because your tutor wants you to access the pixel array using loadPixels() NOT use tint() which hasn't worked anyway because you can't see the original image.

    I suggest you look at the reference for the Processing commands your tutor expects you to use.

  • lines 27, 32 and 37 are the same. why is that?

    and you don;t use the images in lines 12, 13, 14

    actually, tint() does exactly what is required, although the one in line 31 looks wrong. but i think the task is to write them youself.

Sign In or Register to comment.