JFreechart LookUpPaintScale color gradient - gradient

How do you add a color gradient (3 colors: red, yellow, Green) to a LookUpPaintScale in JFreechart?
Thanks

I tried initializing it with the new GradientPaint, but this only take 2 colors.
You could try LinearGradientPaint.

you can try something like this
....
XYPlot plot = new XYPlot(data1, xAxis, yAxis, null);
LookupPaintScale ps = new LookupPaintScale(0,101,Color.lightGray);
ps.add(0, Color.green);
ps.add(10, Color.yellow);
ps.add(20, Color.red);
renderer1.setBlockHeight(0.95f);
renderer1.setBlockWidth(0.95f);
renderer1.setPaintScale(ps);
plot.setRenderer(renderer1);
....

Related

Converting colorspaces in Objective-C

How can I convert from device colour space to calibrated RGB space.Please try to add changes to the following code:
NSColor *MyColorAtScreenCoordinate(CGDirectDisplayID displayID, NSInteger x, NSInteger y) {
CGImageRef image = CGDisplayCreateImageForRect(displayID, CGRectMake(x, y, 1, 1));
NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithCGImage:image];
CGImageRelease(image);
NSColor *color = [bitmap colorAtX:0 y:0];
[bitmap release];
return color;
}
I got the code from this post.
I found an answer for swift here ,I am pretty new to swift and even the docs didnt help
Update
I managed to come with the code:
//'color' is the color from the function
//bitmapRep points to a NSBitmapImageRep
CGFloat* components = malloc(color.numberOfComponents *sizeof(CGFloat));
[color getComponents:components];
NSColor* correctedcolor = [NSColor colorWithColorSpace[self.bitmapRep colorspace]
components:components count:colorbmp.numberOfComponents];
free(components);
[correctedcolor colorUsingColorSpace:[NSColorSpace sRGBColorSpace]];
return correctedcolor
Even with trying this piece of code I was not getting the correct pixel color, I tried using a colorpicker from Appstore which resulted in showing a value different than which was read from using my app.
Example when picking a pure Red color:
Commercial Colorpicker: 0xFF0000
MY Color Picker: 0xFF0404
How can I get the correct calibrated value of the selected pixel?

How to get the color of a pixel in an image in C++ (sfml)

I am working on a simple racing game where you drive a car on a track.
The track is grey and the background green, and any time the color i get on a given point (the front of the car) is not grey, the car should stop because it went out of the track.
However the track is NOT drawn with sfml, rather a downloaded image i made.
So, is there any method for getting the color of a pixel on an IMAGE, as long as the rgb values match?
Here is the pseudo code to do this:
while game is running
get color (car x value, car y value)
if color is not grey
car stops
Thank you!
You can get the sf::Color of a pixel in an sf::Image by using the appropriate method: sf::Image::getPixel. It takes X and Y coordinates.
Example:
sf::Image track;
if (!track.loadFromFile("track.jpg"))
{
// oops, loading failed, handle it
}
sf::Color color = track.getPixel(0, 0); // gets the color of the upper left corner pixel
You'll want to use sf::Image's getPixel(int x, int y) funciton. Your pseudo code would look something like this:
sf::Image track;
sf::Color grey_color; // You'll need to define what the grey color is.
// Take sf::Color(100, 100, 100) as an example.
if (!track.loadFromFile("track.jpg")) {
std::cout << "Uhoh" << std::endl;
}
while (gameIsRunning) {
sf::Color color_at_car = track.getPixel(car.getx(), car.gety());
if (color_at_car != grey_color) {
car.stop();
}
}
Hope this helps!

Schindler's List Photo Filter C++

I'm trying to figure out how to make a Schindlers List (Movie) style photo filter for a .bmp file. For those who havent seen it, I want to be able to make everything grayscale except for red.
This is for a class and I am only allowed to use the following libraries : iostream, fstream, cstdlib, string, cstring.
The teacher was nice enough to give us the majority of the code, I just need to modify the pixels accordingly.
My grayscale algorithm isnt perfect. I got it by using fotor's grayscale filter and comparing the before and after RGB values. When I run this function the entire image ends up grayscale even though the picture has colors in the range I declared.
If someone could help me make this work thatd be great!
void process( int& red, int& green, int& blue ) //schindler's list filter
{
if( red < 143 && red > 80 &&
green < 64 && green > 24 &&
blue < 70 && blue >> 30 )//my red range
{
red = red;
blue = blue;
green = green;
}
else //if the pixel isnt red the program will go ahead and make it grayscale
{
red = ((red + green) / 2)*1.01;
green = red;
blue = red;
}
}
blue >> 30
Silly typo: you meant blue > 30.
blue >> 30 is basically always zero, which converts to false which leaves your "leave the colours as they are" block unreachable.
If someone could help me make this work thatd be great!
We're not really here for that. Next time please do some debugging.
Remove conditions, output the values of expressions and variables, until you find the one that isn't what you expect. Make a testcase. Abstract away your specific use case (i.e. the name of a film is not relevant to the problem).
BTW, as a matter of style, red = red etc is utterly pointless!
As a commentator said, in a classic RGB colorspace, a greyscale value is computed with the formula
grey = .2126*red + .7152*green + .0722*blue;
Also, if you just make a brutal transition between the colors you want to preserve and the grey areas, it might look like the colored zones have been painted over the picture.
I would rather apply a smoothing based on the color you want to make stand out.
// this is the center of the intervals you defined for your color
#define TARGET_R 111
#define TARGET_G 44
#define TARGET_B 50
// color distance to consider to mix grey and pure color
#define RADIUS 20 // R, G or B component
int dr = red - TARGET_R;
int dg = green - TARGET_G;
int db = blue - TARGET_B;
int dist = sqrt(dr*dr+dg*dg+db*db); // distance from target color
int grey = .2126*red+.7152*green+.0722*blue; // grey color
float color; // fraction of pure color
if (dist > RADIUS) // pure grey beyond radius
color = 0;
else if (dist > RADIUS/2) // slope from 0 # radius to 1 # radius/2
color = (RADIUS-dist)*2.0/RADIUS;
else // pure color between 0 and radius/2;
color = 1;
grey *= (1-color); // grey part
red = red * color + grey;
green = green * color + grey;
blue = blue * color + grey;
Another approach you could take is to convert the RGB color to HSV (Hue Saturation Value) color space, and than bring the saturation down only if the hue is not in a specific range. For example:
if( 30 < h && h < 330 ) s = 0
http://en.wikipedia.org/wiki/HSL_and_HSV

Gtkmm getting label color

I do not have a code error, I have just looked everywhere and cannot figure out how to do this. I want to get the color of a Gtk::widget, the Gtk::label. I can override the color of a label like this: l.override_color( c, l.get_state_flags() ); , but I have no idea how to get that color back from the label, thanks!
This is a way to set and get the color of a label:
// Set Color
Gtk::Label label("some label");
label.override_color (Gdk::RGBA("red"), Gtk::STATE_FLAG_NORMAL);
// Get Color
Glib::RefPtr<Gtk::StyleContext> stylecontext = label.get_style_context();
Gdk::RGBA color = stylecontext->get_color(Gtk::STATE_FLAG_NORMAL);
std::cout << color.to_string(); // Display color as "rgb(x, x, x)"

cocos2d remove tint

I'm trying to implement a highlight animation to my sprites. The sprite should highlight to a given color and gradually reverse back to its original colors, with the following code:
- (void)highlight {
CCTintTo *tintAction = [CCTintTo actionWithDuration:0.1 red:255 green:255 blue:255];
CCTintTo *tintBackAction = [tintAction reverse];
CCSequence *sequence = [CCSequence actions: tintAction, tintBackAction, nil];
[self runAction:sequence];
}
Now this function raises an exception as CCTintTo doesn't seem to implement 'reverse', which makes sense. Is there any other way to implement removal of an added tint over an interval, using a CCAction?
CCSprite's default color is ccWhite, {255, 255, 255}, so if you
want to make sprite lighter, you'll have to subclass CCSprite/write shader to use additive coloring.
Just tint it back:
CCColor3B oldColor = sprite.color;
CCTintTo *tintTo = [CCTintTo actionWithDuration:t red:r green:g blue:b];
CCTintTo *tintBack = [CCTintTo actionWithDuration:t red:oldColor.r green:oldColor.g blue:oldColor.b];
[sprite runAction:[CCSequence actions: tintTo, tintBack, nil]];
You can store previous color before start tint, then just create CCTintTo with initial RGB values.
For Cocos2dx (C++)
ccColor3B oldColor = sprite->getColor();
CCTintTo* action = CCTintTo::create(0.5f, 127, 255, 127);
CCTintTo* actionReverse = CCTintTo::create(0.5f, oldColor.r, oldColor.g, oldColor.b);;
sprite->runAction(CCSequence::create(action, actionReverse, NULL));
Works fine Kreiri, thanks! I already gave a plus to you:).