get Color and use it many times
in
Programming Questions
•
1 year ago
Hello,
I am trying to make a drawing tool for pixel images, so I want to have a color palette(Image) so that when you hover on it in a certain position and press the 'c" key it takes the color from that pixel and puts in in a color variable, and then draw a square with the color acquired from that pixel, but have the chance of doing it many times. I haven't gotten it to work totally, at least it runs the application but doesn't pick a color specifically. Any help will be much appreciate it.
Here is the code:
int xPos;
int yPos;
int wRect;
int hRect;
PFont myFontPixelizer;
int fontPosX = 30;
int fontPosY = 30;
color pixelColor;
//color = pixelColor;
PImage myImage;
void setup() {
size(600, 600);
myImage = loadImage("starck-squeezer.jpeg");
//background(240);
frame.setTitle("|| Pixelizer v1.0 ||");
frame.setLocationRelativeTo(null);
smooth();
pixelColor= myImage.get(mouseX, mouseY);
}
void draw() {
//Title---------------------------------->
image(myImage, 30, 70);
myFontPixelizer= loadFont("Atari-Font-Full-Version-48.vlw");
textFont(myFontPixelizer);
text("Pixelizer", 30, 70);
fill(18);
//Define my variables and functions
mousePixel();
//Grid------------------------------------>
line(150, 150, 150, 570);
for ( int i = 150 ; i < 580; i = i+20) {
line(xPos+i, 150, xPos+i, 570);
line(xPos+150, yPos+i, 570, yPos+i);
// pixelColor++;
}
//Get color------------------------------->
if (key == 'c') {
myImage.get(mouseX, mouseY);
}
}
void mousePixel() {
if ( mousePressed) {
fill(pixelColor);
rectMode(CENTER);
rect(mouseX, mouseY, 20, 20);
}
}
1