Changes to color examples

This commit is contained in:
Casey Reas
2011-07-17 04:50:51 +00:00
parent 7860e7115c
commit 4140646f18
5 changed files with 42 additions and 166 deletions

View File

@@ -8,12 +8,12 @@
* Updated 28 February 2010.
*/
int barWidth = 5;
int barWidth = 20;
int lastBar = -1;
void setup() {
size(200, 200);
colorMode(HSB, 360, 100, height);
size(640, 360);
colorMode(HSB, width, 100, width);
noStroke();
background(0);
}

View File

@@ -1,88 +0,0 @@
/**
* Subtractive Color Wheel
* by Ira Greenberg.
*
* The primaries are red, yellow, and blue. The secondaries are green,
* purple, and orange. The tertiaries are yellow-orange, red-orange,
* red-purple, blue-purple, blue-green, and yellow-green.
*
* Create a shade or tint of the subtractive color wheel using
* SHADE or TINT parameters.
*
* Updated 26 February 2010.
*/
int segs = 12;
int steps = 6;
float rotAdjust = TWO_PI / segs / 2;
float radius;
float segWidth;
float interval = TWO_PI / segs;
void setup() {
size(200, 200);
background(127);
smooth();
ellipseMode(RADIUS);
noStroke();
// make the diameter 90% of the sketch area
radius = min(width, height) * 0.45;
segWidth = radius / steps;
// swap which line is commented out to draw the other version
//drawTintWheel();
drawShadeWheel();
}
void drawShadeWheel() {
for (int j = 0; j < steps; j++) {
color[] cols = {
color(255-(255/steps)*j, 255-(255/steps)*j, 0),
color(255-(255/steps)*j, (255/1.5)-((255/1.5)/steps)*j, 0),
color(255-(255/steps)*j, (255/2)-((255/2)/steps)*j, 0),
color(255-(255/steps)*j, (255/2.5)-((255/2.5)/steps)*j, 0),
color(255-(255/steps)*j, 0, 0),
color(255-(255/steps)*j, 0, (255/2)-((255/2)/steps)*j),
color(255-(255/steps)*j, 0, 255-(255/steps)*j),
color((255/2)-((255/2)/steps)*j, 0, 255-(255/steps)*j),
color(0, 0, 255-(255/steps)*j),
color(0, 255-(255/steps)*j, (255/2.5)-((255/2.5)/steps)*j),
color(0, 255-(255/steps)*j, 0),
color((255/2)-((255/2)/steps)*j, 255-(255/steps)*j, 0)
};
for (int i = 0; i < segs; i++) {
fill(cols[i]);
arc(width/2, height/2, radius, radius,
interval*i+rotAdjust, interval*(i+1)+rotAdjust);
}
radius -= segWidth;
}
}
void drawTintWheel() {
for (int j = 0; j < steps; j++) {
color[] cols = {
color((255/steps)*j, (255/steps)*j, 0),
color((255/steps)*j, ((255/1.5)/steps)*j, 0),
color((255/steps)*j, ((255/2)/steps)*j, 0),
color((255/steps)*j, ((255/2.5)/steps)*j, 0),
color((255/steps)*j, 0, 0),
color((255/steps)*j, 0, ((255/2)/steps)*j),
color((255/steps)*j, 0, (255/steps)*j),
color(((255/2)/steps)*j, 0, (255/steps)*j),
color(0, 0, (255/steps)*j),
color(0, (255/steps)*j, ((255/2.5)/steps)*j),
color(0, (255/steps)*j, 0),
color(((255/2)/steps)*j, (255/steps)*j, 0)
};
for (int i = 0; i < segs; i++) {
fill(cols[i]);
arc(width/2, height/2, radius, radius,
interval*i+rotAdjust, interval*(i+1)+rotAdjust);
}
radius -= segWidth;
}
}

View File

@@ -1,12 +1,13 @@
/**
* Creating Colors (Homage to Albers).
* Color Variables (Homage to Albers).
*
* Creating variables for colors that may be referred to
* in the program by their name, rather than a number.
* This example creates variables for colors that may be referred to
* in the program by a name, rather than a number.
*/
size(200, 200);
size(640, 360);
noStroke();
background(51, 0, 0);
color inside = color(204, 102, 0);
color middle = color(204, 153, 0);
@@ -18,9 +19,22 @@ color outside = color(153, 51, 0);
//color middle = #CC9900;
//color outside = #993300;
pushMatrix();
translate(80, 80);
fill(outside);
rect(0, 0, 200, 200);
fill(middle);
rect(40, 60, 120, 120);
fill(inside);
rect(60, 90, 80, 80);
popMatrix();
pushMatrix();
translate(360, 80);
fill(inside);
rect(0, 0, 200, 200);
fill(outside);
rect(40, 60, 120, 120);
fill(middle);
rect(60, 90, 80, 80);
popMatrix();

View File

@@ -10,26 +10,34 @@
// constants
int Y_AXIS = 1;
int X_AXIS = 2;
color b1, b2, c1, c2, c3, c4, c5, c6;
void setup(){
size(200, 200);
size(640, 360);
// create some gradients
// background
color b1 = color(190, 190, 190);
color b2 = color(20, 20, 20);
setGradient(0, 0, width, height, b1, b2, Y_AXIS);
//center squares
color c1 = color(255, 120, 0);
color c2 = color(10, 45, 255);
color c3 = color(10, 255, 15);
color c4 = color(125, 2, 140);
color c5 = color(255, 255, 0);
color c6 = color(25, 255, 200);
b1 = color(190, 190, 190);
b2 = color(20, 20, 20);
c1 = color(255, 120, 0);
c2 = color(10, 45, 255);
c3 = color(10, 255, 15);
c4 = color(125, 2, 140);
c5 = color(255, 255, 0);
c6 = color(25, 255, 200);
noLoop();
}
void draw() {
// background
setGradient(0, 0, width, height, b1, b2, Y_AXIS);
//center squares
setGradient(25, 25, 75, 75, c1, c2, Y_AXIS);
setGradient(100, 25, 75, 75, c3, c4, X_AXIS);
setGradient(25, 100, 75, 75, c2, c5, X_AXIS);
setGradient(100, 100, 75, 75, c4, c6, Y_AXIS);
setGradient(100, 100, 75, 75, c4, c6, Y_AXIS);
}
void setGradient(int x, int y, float w, float h, color c1, color c2, int axis ){

View File

@@ -1,58 +0,0 @@
/**
* Simple Radial Gradient
* by Ira Greenberg.
*
* Using the convenient red(), green()
* and blue() component functions,
* generate an array of radial gradients.
*/
void setup(){
size(200, 200);
background(0);
smooth();
// create a simple table of gradients
int columns = 4;
int radius = (width/columns)/2;
// create some gradients
for (int i=radius; i< width; i+=radius*2){
for (int j =radius; j< height; j+=radius*2){
createGradient(i, j, radius,
color(int(random(255)), int(random(255)), int(random(255))),
color(int(random(255)), int(random(255)), int(random(255))));
}
}
}
void createGradient (float x, float y, float radius, color c1, color c2){
float px = 0, py = 0, angle = 0;
// calculate differences between color components
float deltaR = red(c2)-red(c1);
float deltaG = green(c2)-green(c1);
float deltaB = blue(c2)-blue(c1);
// hack to ensure there are no holes in gradient
// needs to be increased, as radius increases
float gapFiller = 8.0;
for (int i=0; i< radius; i++){
for (float j=0; j<360; j+=1.0/gapFiller){
px = x+cos(radians(angle))*i;
py = y+sin(radians(angle))*i;
angle+=1.0/gapFiller;
color c = color(
(red(c1)+(i)*(deltaR/radius)),
(green(c1)+(i)*(deltaG/radius)),
(blue(c1)+(i)*(deltaB/radius))
);
set(int(px), int(py), c);
}
}
// adds smooth edge
// hack anti-aliasing
noFill();
strokeWeight(3);
ellipse(x, y, radius*2, radius*2);
}