fixes to lerpColor

This commit is contained in:
benfry
2006-11-09 13:53:06 +00:00
parent 91bcf775d3
commit 7f62636a9b
5 changed files with 71 additions and 22 deletions
+10 -5
View File
@@ -6830,11 +6830,6 @@ public class PApplet extends Applet
}
static public int lerpColor(int c1, int c2, float amt) {
return PGraphics.lerpColor(c1, c2, amt);
}
public void blend(int sx1, int sy1, int sx2, int sy2,
int dx1, int dy1, int dx2, int dy2, int mode) {
if (recorder != null) recorder.blend(sx1, sy1, sx2, sy2, dx1, dy1, dx2, dy2, mode);
@@ -7864,6 +7859,16 @@ public class PApplet extends Applet
}
public int lerpColor(int c1, int c2, float amt) {
return g.lerpColor(c1, c2, amt);
}
static public int lerpColor(int c1, int c2, float amt, int mode) {
return PGraphics.lerpColor(c1, c2, amt, mode);
}
public void beginRaw(PGraphics raw) {
if (recorder != null) recorder.beginRaw(raw);
g.beginRaw(raw);
+60
View File
@@ -3982,6 +3982,66 @@ public abstract class PGraphics extends PImage implements PConstants {
}
public int lerpColor(int c1, int c2, float amt) {
return lerpColor(c1, c2, amt, colorMode);
}
static float[] lerpColorHSB1;
static float[] lerpColorHSB2;
static public int lerpColor(int c1, int c2, float amt, int mode) {
if (mode == RGB) {
float a1 = ((c1 >> 24) & 0xff);
float r1 = (c1 >> 16) & 0xff;
float g1 = (c1 >> 8) & 0xff;
float b1 = c1 & 0xff;
float a2 = (c2 >> 24) & 0xff;
float r2 = (c2 >> 16) & 0xff;
float g2 = (c2 >> 8) & 0xff;
float b2 = c2 & 0xff;
return (((int) (a1 + (a2-a1)*amt) << 24) |
((int) (r1 + (r2-r1)*amt) << 16) |
((int) (g1 + (g2-g1)*amt) << 8) |
((int) (b1 + (b2-b1)*amt)));
} else if (mode == HSB) {
if (lerpColorHSB1 == null) {
lerpColorHSB1 = new float[3];
lerpColorHSB2 = new float[3];
}
float a1 = (c1 >> 24) & 0xff;
float a2 = (c2 >> 24) & 0xff;
int alfa = ((int) (a1 + (a2-a1)*amt)) << 24;
Color.RGBtoHSB((c1 >> 16) & 0xff, (c1 >> 8) & 0xff, c1 & 0xff,
lerpColorHSB1);
Color.RGBtoHSB((c2 >> 16) & 0xff, (c2 >> 8) & 0xff, c2 & 0xff,
lerpColorHSB2);
// roll around when 0.9 to 0.1
// more than 0.5 away means that it should roll in the other direction
float h1 = lerpColorHSB1[0];
float h2 = lerpColorHSB2[0];
if (Math.abs(h1 - h2) > 0.5f) {
if (h1 > h2) {
// i.e. h1 is 0.7, h2 is 0.1
h2 += 1;
} else {
// i.e. h1 is 0.1, h2 is 0.7
h1 += 1;
}
}
float ho = (PApplet.lerp(lerpColorHSB1[0], lerpColorHSB2[0], amt)) % 1.0f;
float so = PApplet.lerp(lerpColorHSB1[1], lerpColorHSB2[1], amt);
float bo = PApplet.lerp(lerpColorHSB1[2], lerpColorHSB2[2], amt);
return alfa | (Color.HSBtoRGB(ho, so, bo) & 0xFFFFFF);
}
return 0;
}
//////////////////////////////////////////////////////////////
-16
View File
@@ -1100,22 +1100,6 @@ public class PImage implements PConstants, Cloneable {
}
static public int lerpColor(int c1, int c2, float amt) {
float a1 = ((c1 >> 24) & 0xff);
float r1 = (c1 >> 16) & 0xff;
float g1 = (c1 >> 8) & 0xff;
float b1 = c1 & 0xff;
float a2 = (c2 >> 24) & 0xff;
float r2 = (c2 >> 16) & 0xff;
float g2 = (c2 >> 8) & 0xff;
float b2 = c2 & 0xff;
return (((int) (a1 + (a2-a1)*amt) << 24) |
((int) (r1 + (r2-r1)*amt) << 16) |
((int) (g1 + (g2-g1)*amt) << 8) |
((int) (b1 + (b2-b1)*amt)));
}
/**
* Copies and blends 1 pixel with MODE to pixel in this image.
* Removing this function, the blend() command above can be used instead.
-1
View File
@@ -18,7 +18,6 @@ g2.setPaint(gradient);
//g2.draw(gp);
g2.fill(gp);
_ make lerpColor honor the current color mode
_ though that's awkward b/c colors always RGB
_ lerpColor(c1, c2, amt, RGB/HSB/???)
+1
View File
@@ -1,6 +1,7 @@
0122 pde
_ slow save/new because of large sketchbook
_ this is a total cluster, the rebuild is being called incessantly
_ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=SoftwareBugs;action=display;num=1162801212
_ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=SoftwareBugs;action=display;num=1141126582