color() working outside setup(). yeehaa.

This commit is contained in:
benfry
2004-07-15 14:45:17 +00:00
parent 2904f41f94
commit 8854f05403
3 changed files with 131 additions and 92 deletions
+81 -40
View File
@@ -2261,6 +2261,87 @@ public class PApplet extends Applet
// ------------------------------------------------------------
// color functions, moved here so that they can work without
// the graphics actually being instantiated
public final int color(int gray) {
if (g == null) {
gray &= 0xff; // cut the bounds on this feller
return 0xff000000 | (gray << 16) | (gray << 8) | gray;
}
return g.color(gray);
}
public final int color(float fgray) {
if (g == null) {
int gray = ((int) fgray) & 0xff;
return 0xff000000 | (gray << 16) | (gray << 8) | gray;
}
return g.color(fgray);
}
public final int color(int gray, int alpha) {
if (g == null) {
gray &= 0xff; // cut the bounds on this feller
alpha &= 0xff;
return (alpha << 24) | (gray << 16) | (gray << 8) | gray;
}
return g.color(gray, alpha);
}
public final int color(float fgray, float falpha) {
if (g == null) {
int gray = ((int) fgray) & 0xff;
int alpha = ((int) falpha) & 0xff;
return 0xff000000 | (gray << 16) | (gray << 8) | gray;
}
return g.color(fgray, falpha);
}
public final int color(int x, int y, int z) {
if (g == null) {
return 0xff000000 |
((x & 0xff) << 16) | ((y & 0xff) << 8) | (z & 0xff);
}
return g.color(x, y, z);
}
public final int color(float x, float y, float z) {
if (g == null) {
return 0xff000000 |
(((int)x & 0xff) << 16) | (((int)y & 0xff) << 8) | ((int)z & 0xff);
}
return g.color(x, y, z);
}
public final int color(int x, int y, int z, int a) {
if (g == null) {
return ((a & 0xff) << 24) |
((x & 0xff) << 16) | ((y & 0xff) << 8) | (z & 0xff);
}
return g.color(x, y, z, a);
}
public final int color(float x, float y, float z, float a) {
if (g == null) {
return (((int)a & 0xff) << 24) |
(((int)x & 0xff) << 16) | (((int)y & 0xff) << 8) | ((int)z & 0xff);
}
return g.color(x, y, z, a);
}
// ------------------------------------------------------------
// everything below this line is automatically generated. no touch.
// public functions for processing.core
@@ -3199,46 +3280,6 @@ public class PApplet extends Applet
}
public final int color(int gray) {
return g.color(gray);
}
public final int color(float gray) {
return g.color(gray);
}
public final int color(int gray, int alpha) {
return g.color(gray, alpha);
}
public final int color(float gray, float alpha) {
return g.color(gray, alpha);
}
public final int color(int x, int y, int z) {
return g.color(x, y, z);
}
public final int color(float x, float y, float z) {
return g.color(x, y, z);
}
public final int color(int x, int y, int z, int a) {
return g.color(x, y, z, a);
}
public final int color(float x, float y, float z, float a) {
return g.color(x, y, z, a);
}
public final float alpha(int what) {
return g.alpha(what);
}
+29 -20
View File
@@ -69,11 +69,14 @@ public class PGraphics extends PImage implements PConstants {
// if it's a one-word feller like 'fill' or 'stroke'
// then an underscore is placed in front: _fill
int color_mode;
// color_scale is for *internal* scaling, true if colorMode(1)
// since that's what's easiest for the internal stuff..
boolean color_scale;
boolean color_rgb255;
// color parameters
// internally, colors are 0..1 for the floats
// this makes the lighting computations clearer
int color_mode;
boolean color_scale;
float colorMaxX;
float colorMaxY;
float colorMaxZ;
@@ -113,9 +116,10 @@ public class PGraphics extends PImage implements PConstants {
int calci;
boolean calc_alpha;
// cache for hsb conversion values for get/set pixel
/** The last rgb value converted to hsb */
int cacheHsbKey;
float cacheHsbValue[] = new float[3]; // init to zero
/** Result of the last conversion to hsb */
float cacheHsbValue[] = new float[3]; // inits to zero
// lighting
static final int MAX_LIGHTS = 10;
@@ -5051,6 +5055,12 @@ public class PGraphics extends PImage implements PConstants {
// if color max values are all 1, then no need to scale
color_scale = ((maxA != ONE) || (maxX != maxY) ||
(maxY != maxZ) || (maxZ != maxA));
// if color is rgb/0..255 this will make it easier for the
// red() green() etc functions
color_rgb255 = (color_mode == RGB) &&
(colorMaxA == 255) && (colorMaxX == 255) &&
(colorMaxY == 255) && (colorMaxZ == 255);
}
@@ -5887,57 +5897,57 @@ public class PGraphics extends PImage implements PConstants {
// they can write it themselves (not difficult)
public final int color(int gray) {
if ((color_mode == RGB) && (!color_scale)) {
public final int color(int gray) { // ignore
if (color_rgb255) {
return 0xff000000 | (gray << 16) | (gray << 8) | gray;
}
calc_color(gray);
return calci;
}
public final int color(float gray) {
public final int color(float gray) { // ignore
calc_color(gray);
return calci;
}
public final int color(int gray, int alpha) {
if ((color_mode == RGB) && (!color_scale)) {
public final int color(int gray, int alpha) { // ignore
if (color_rgb255) {
return (gray << 24) | (gray << 16) | (gray << 8) | gray;
}
calc_color(gray, alpha);
return calci;
}
public final int color(float gray, float alpha) {
public final int color(float gray, float alpha) { // ignore
calc_color(gray, alpha);
return calci;
}
public final int color(int x, int y, int z) {
if ((color_mode == RGB) && (!color_scale)) {
public final int color(int x, int y, int z) { // ignore
if (color_rgb255) {
return 0xff000000 | (x << 16) | (y << 8) | z;
}
calc_color(x, y, z);
return calci;
}
public final int color(float x, float y, float z) {
public final int color(float x, float y, float z) { // ignore
calc_color(x, y, z);
return calci;
}
public final int color(int x, int y, int z, int a) {
if ((color_mode == RGB) && (!color_scale)) {
public final int color(int x, int y, int z, int a) { // ignore
if (color_rgb255) {
return (a << 24) | (x << 16) | (y << 8) | z;
}
calc_color(x, y, z, a);
return calci;
}
public final int color(float x, float y, float z, float a) {
public final int color(float x, float y, float z, float a) { // ignore
calc_color(x, y, z, a);
return calci;
}
@@ -5951,20 +5961,19 @@ public class PGraphics extends PImage implements PConstants {
public final float red(int what) {
float c = (what >> 16) & 0xff;
System.out.println((color_mode == RGB) + " " + color_scale);
if ((color_mode == RGB) && (!color_scale)) return c;
if (color_rgb255) return c;
return (c / 255.0f) * colorMaxX;
}
public final float green(int what) {
float c = (what >> 8) & 0xff;
if ((color_mode == RGB) && (!color_scale)) return c;
if (color_rgb255) return c;
return (c / 255.0f) * colorMaxY;
}
public final float blue(int what) {
float c = (what) & 0xff;
if ((color_mode == RGB) && (!color_scale)) return c;
if (color_rgb255) return c;
return (c / 255.0f) * colorMaxZ;
}
+21 -32
View File
@@ -59,26 +59,26 @@ o all triangles must be counter-clockwise (front-facing)
X do applets know when they're stopped? stop? dispose?
X would be good to set a param in p5 so that the thread dies
X if people have other threads they've spawned, impossible to stop
X api to properly sense when applet has focus
X add a 'focused' variable to the applet
X code now in zipdecode, maybe just list this as a standard thing?
X include a lerp()? is there one in flash?
X http://processing.org/discourse/yabb/YaBB.cgi?board=Programs;action=display;num=1083289030
X should it be called lerp or mix?
X acos, asin, log, exp, ceil/floor, pow, mag(x,y,z)
X add color(gray) and color(gray, alpha)
X http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1089898189;start=0
X color issues
X doesn't work when outside a function:
X color bg_color = color(255,0,0);
X colorMode broken for red() green() etc
X http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1068664455
X add color(gray) and color(gray, alpha)
X http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1089898189;start=0
MEGABUCKET (api)
_ passing in args[] from main
_ color issues
_ doesn't work when outside a function:
_ color bg_color = color(255,0,0);
_ colorMode broken for red() green() etc
_ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1068664455
_ light(x, y, z, c1, c2, c3, TYPE)
_ also BLight with same constructor, and on() and off() fxn
_ api to properly sense when applet has focus
_ add a 'focused' variable to the applet
_ code now in zipdecode, maybe just list this as a standard thing?
_ include in the docs: don't override stop()
_ or handle this some more intelligent way, super.stop() is needed.
_ http://processing.org/discourse/yabb/YaBB.cgi?board=Syntax;action=display;num=1083574943
@@ -184,17 +184,17 @@ CORE / PGraphics
b _ lines
b _ z value hack for lines is causing trouble for 2D
b _ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1089737928;start=0
b X rewrite line and stroke code, it's a buggy mess
b X lines become 2 pixels thick after a 3D transform
b X better handling of single-pixel special case
b _ rewrite line and stroke code, it's a buggy mess
b _ lines become 2 pixels thick after a 3D transform
b _ better handling of single-pixel special case
b _ flat_line_retribution is a hack, can go away
b _ mgorbet stroke transparency problem
b _ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1076383048;start=0
b ? make sure line() commands don't try to have a fill
b _ make sure line() commands don't try to have a fill
b _ box is not opaque
b X problem is that lines are drawn second
b X one pixel lines have no z value.. argh
b X bug re: 3d depth sorting on lines
b _ problem is that lines are drawn second
b _ one pixel lines have no z value.. argh
b _ bug re: 3d depth sorting on lines
b _ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1043894019;start=0
b _ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1042004618
b _ translate(58, 48, 0);
@@ -215,21 +215,10 @@ CORE / PGraphics
1 _ alpha of zero still draws boogers on screen
1 _ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1073329613;start=0
1 _ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1080342288;start=0
b _ super nasty lineweight issue:
void setup()
{
size(400, 400);
}
void loop()
{
stroke(#ff0000);
strokeWeight(2);
line(0, 0, 40, 40);
point(100, 100);
rect(200, 200, 100, 100);
}
1 _ color
1 _ rounding errors on color conversion
1 _ colorMode(RGB, 1.0); colorMode(255); println(red(color(0.5,1,1)));
1 _ will return 127, instead of 128.
1 _ ellipse problems
1 _ weird ellipse bug with an alpha line in same image