This commit is contained in:
benfry
2011-01-26 19:22:19 +00:00
parent d3a18c7964
commit eb64b2d4fc
1234 changed files with 96518 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
/**
* Brightness
* by Rusty Robison.
*
* Brightness is the relative lightness or darkness of a color.
* Move the cursor vertically over each bar to alter its brightness.
*
* Updated 28 February 2010.
*/
int barWidth = 5;
int lastBar = -1;
void setup() {
size(200, 200);
colorMode(HSB, 360, 100, height);
noStroke();
background(0);
}
void draw() {
int whichBar = mouseX / barWidth;
if (whichBar != lastBar) {
int barX = whichBar * barWidth;
fill(barX, 100, mouseY);
rect(barX, 0, barWidth, height);
lastBar = whichBar;
}
}

View File

@@ -0,0 +1,51 @@
import processing.core.*;
import java.applet.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.*;
import java.util.zip.*;
import java.util.regex.*;
public class Brightness extends PApplet {
/**
* Brightness
* by Rusty Robison.
*
* Brightness is the relative lightness or darkness of a color.
* Move the cursor vertically over each bar to alter its brightness.
*/
int barWidth = 5;
int[] brightness;
public void setup()
{
size(200, 200);
colorMode(HSB, 360, height, height);
brightness = new int[width/barWidth];
}
public void draw()
{
int j = 0;
for (int i = 0; i <= (width-barWidth); i += barWidth) {
noStroke();
if ((mouseX > i) && (mouseX < i+barWidth)) {
brightness[j] = mouseY;
}
fill(i, height, brightness[j]);
rect(i, 0, barWidth, height);
j++;
}
}
static public void main(String args[]) {
PApplet.main(new String[] { "Brightness" });
}
}

View File

@@ -0,0 +1,31 @@
/**
* Brightness
* by Rusty Robison.
*
* Brightness is the relative lightness or darkness of a color.
* Move the cursor vertically over each bar to alter its brightness.
*/
int barWidth = 5;
int[] brightness;
void setup()
{
size(200, 200);
colorMode(HSB, 360, height, height);
brightness = new int[width/barWidth];
}
void draw()
{
int j = 0;
for (int i = 0; i <= (width-barWidth); i += barWidth) {
noStroke();
if ((mouseX > i) && (mouseX < i+barWidth)) {
brightness[j] = mouseY;
}
fill(i, height, brightness[j]);
rect(i, 0, barWidth, height);
j++;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -0,0 +1,88 @@
/**
* 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

@@ -0,0 +1,99 @@
import processing.core.*;
import java.applet.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.*;
import java.util.zip.*;
import java.util.regex.*;
public class ColorWheel extends PApplet {
/**
* 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.
*/
int segs = 12;
int steps = 6;
float rotAdjust = radians(360.0f/segs/2.0f);
float radius = 95.0f;
float segWidth = radius/steps;
float interval = TWO_PI/segs;
int SHADE = 0;
int TINT = 1;
public void setup(){
size(200, 200);
background(127);
smooth();
ellipseMode(CENTER_RADIUS);
noStroke();
// you can substitue TINT for SHADE argument
createWheel(width/2, height/2, SHADE);
}
public void createWheel(int x, int y, int valueShift){
if (valueShift == SHADE){
for (int j=0; j<steps; j++){
int[]cols = {
color(255-(255/steps)*j, 255-(255/steps)*j, 0),
color(255-(255/steps)*j, (255/1.5f)-((255/1.5f)/steps)*j, 0),
color(255-(255/steps)*j, (255/2)-((255/2)/steps)*j, 0),
color(255-(255/steps)*j, (255/2.5f)-((255/2.5f)/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.5f)-((255/2.5f)/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(x, y, radius, radius, interval*i+rotAdjust, interval*(i+1)+rotAdjust);
}
radius -= segWidth;
}
} else if (valueShift == TINT){
for (int j=0; j<steps; j++){
int[]cols = {
color((255/steps)*j, (255/steps)*j, 0),
color((255/steps)*j, ((255/1.5f)/steps)*j, 0),
color((255/steps)*j, ((255/2)/steps)*j, 0),
color((255/steps)*j, ((255/2.5f)/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.5f)/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(x, y, radius, radius, interval*i+rotAdjust, interval*(i+1)+rotAdjust);
}
radius -= segWidth;
}
}
}
static public void main(String args[]) {
PApplet.main(new String[] { "ColorWheel" });
}
}

View File

@@ -0,0 +1,79 @@
/**
* 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.
*/
int segs = 12;
int steps = 6;
float rotAdjust = radians(360.0/segs/2.0);
float radius = 95.0;
float segWidth = radius/steps;
float interval = TWO_PI/segs;
int SHADE = 0;
int TINT = 1;
void setup(){
size(200, 200);
background(127);
smooth();
ellipseMode(CENTER_RADIUS);
noStroke();
// you can substitue TINT for SHADE argument
createWheel(width/2, height/2, SHADE);
}
void createWheel(int x, int y, int valueShift){
if (valueShift == SHADE){
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(x, y, radius, radius, interval*i+rotAdjust, interval*(i+1)+rotAdjust);
}
radius -= segWidth;
}
} else if (valueShift == TINT){
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(x, y, radius, radius, interval*i+rotAdjust, interval*(i+1)+rotAdjust);
}
radius -= segWidth;
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -0,0 +1,26 @@
/**
* Creating Colors (Homage to Albers).
*
* Creating variables for colors that may be referred to
* in the program by their name, rather than a number.
*/
size(200, 200);
noStroke();
color inside = color(204, 102, 0);
color middle = color(204, 153, 0);
color outside = color(153, 51, 0);
// These statements are equivalent to the statements above.
// Programmers may use the format they prefer.
//color inside = #CC6600;
//color middle = #CC9900;
//color outside = #993300;
fill(outside);
rect(0, 0, 200, 200);
fill(middle);
rect(40, 60, 120, 120);
fill(inside);
rect(60, 90, 80, 80);

View File

@@ -0,0 +1,47 @@
import processing.core.*;
import java.applet.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.*;
import java.util.zip.*;
import java.util.regex.*;
public class Creating extends PApplet {
public void setup() {/**
* Creating Colors (Homage to Albers).
*
* Creating variables for colors that may be referred to
* in the program by their name, rather than a number.
*/
size(200, 200);
noStroke();
int inside = color(204, 102, 0);
int middle = color(204, 153, 0);
int outside = color(153, 51, 0);
// These statements are equivalent to the statements above.
// Programmers may use the format they prefer.
//color inside = #CC6600;
//color middle = #CC9900;
//color outside = #993300;
fill(outside);
rect(0, 0, 200, 200);
fill(middle);
rect(40, 60, 120, 120);
fill(inside);
rect(60, 90, 80, 80);
noLoop();
}
static public void main(String args[]) {
PApplet.main(new String[] { "Creating" });
}
}

View File

@@ -0,0 +1,26 @@
/**
* Creating Colors (Homage to Albers).
*
* Creating variables for colors that may be referred to
* in the program by their name, rather than a number.
*/
size(200, 200);
noStroke();
color inside = color(204, 102, 0);
color middle = color(204, 153, 0);
color outside = color(153, 51, 0);
// These statements are equivalent to the statements above.
// Programmers may use the format they prefer.
//color inside = #CC6600;
//color middle = #CC9900;
//color outside = #993300;
fill(outside);
rect(0, 0, 200, 200);
fill(middle);
rect(40, 60, 120, 120);
fill(inside);
rect(60, 90, 80, 80);

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -0,0 +1,31 @@
/**
* Hue.
*
* Hue is the color reflected from or transmitted through an object
* and is typically referred to as the name of the color (red, blue, yellow, etc.)
* Move the cursor vertically over each bar to alter its hue.
*/
int barWidth = 5;
int[] hue;
void setup()
{
size(200, 200);
colorMode(HSB, 360, height, height);
hue = new int[width/barWidth];
noStroke();
}
void draw()
{
int j = 0;
for (int i=0; i<=(width-barWidth); i+=barWidth) {
if ((mouseX > i) && (mouseX < i+barWidth)) {
hue[j] = mouseY;
}
fill(hue[j], height/1.2, height/1.2);
rect(i, 0, barWidth, height);
j++;
}
}

View File

@@ -0,0 +1,51 @@
import processing.core.*;
import java.applet.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.*;
import java.util.zip.*;
import java.util.regex.*;
public class Hue extends PApplet {
/**
* Hue.
*
* Hue is the color reflected from or transmitted through an object
* and is typically referred to as the name of the color (red, blue, yellow, etc.)
* Move the cursor vertically over each bar to alter its hue.
*/
int barWidth = 5;
int[] hue;
public void setup()
{
size(200, 200);
colorMode(HSB, 360, height, height);
hue = new int[width/barWidth];
noStroke();
}
public void draw()
{
int j = 0;
for (int i=0; i<=(width-barWidth); i+=barWidth) {
if ((mouseX > i) && (mouseX < i+barWidth)) {
hue[j] = mouseY;
}
fill(hue[j], height/1.2f, height/1.2f);
rect(i, 0, barWidth, height);
j++;
}
}
static public void main(String args[]) {
PApplet.main(new String[] { "Hue" });
}
}

View File

@@ -0,0 +1,31 @@
/**
* Hue.
*
* Hue is the color reflected from or transmitted through an object
* and is typically referred to as the name of the color (red, blue, yellow, etc.)
* Move the cursor vertically over each bar to alter its hue.
*/
int barWidth = 5;
int[] hue;
void setup()
{
size(200, 200);
colorMode(HSB, 360, height, height);
hue = new int[width/barWidth];
noStroke();
}
void draw()
{
int j = 0;
for (int i=0; i<=(width-barWidth); i+=barWidth) {
if ((mouseX > i) && (mouseX < i+barWidth)) {
hue[j] = mouseY;
}
fill(hue[j], height/1.2, height/1.2);
rect(i, 0, barWidth, height);
j++;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -0,0 +1,73 @@
/**
* Simple Linear Gradient
* by Ira Greenberg.
*
* Using the convenient red(), green()
* and blue() component functions,
* generate some linear gradients.
*/
// constants
int Y_AXIS = 1;
int X_AXIS = 2;
void setup(){
size(200, 200);
// 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);
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);
}
void setGradient(int x, int y, float w, float h, color c1, color c2, int axis ){
// calculate differences between color components
float deltaR = red(c2)-red(c1);
float deltaG = green(c2)-green(c1);
float deltaB = blue(c2)-blue(c1);
// choose axis
if(axis == Y_AXIS){
/*nested for loops set pixels
in a basic table structure */
// column
for (int i=x; i<=(x+w); i++){
// row
for (int j = y; j<=(y+h); j++){
color c = color(
(red(c1)+(j-y)*(deltaR/h)),
(green(c1)+(j-y)*(deltaG/h)),
(blue(c1)+(j-y)*(deltaB/h))
);
set(i, j, c);
}
}
}
else if(axis == X_AXIS){
// column
for (int i=y; i<=(y+h); i++){
// row
for (int j = x; j<=(x+w); j++){
color c = color(
(red(c1)+(j-x)*(deltaR/h)),
(green(c1)+(j-x)*(deltaG/h)),
(blue(c1)+(j-x)*(deltaB/h))
);
set(j, i, c);
}
}
}
}

View File

@@ -0,0 +1,93 @@
import processing.core.*;
import java.applet.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.*;
import java.util.zip.*;
import java.util.regex.*;
public class LinearGradient extends PApplet {
/**
* Simple Linear Gradient
* by Ira Greenberg.
*
* Using the convenient red(), green()
* and blue() component functions,
* generate some linear gradients.
*/
// constants
int Y_AXIS = 1;
int X_AXIS = 2;
public void setup(){
size(200, 200);
// create some gradients
// background
int b1 = color(190, 190, 190);
int b2 = color(20, 20, 20);
setGradient(0, 0, width, height, b1, b2, Y_AXIS);
//center squares
int c1 = color(255, 120, 0);
int c2 = color(10, 45, 255);
int c3 = color(10, 255, 15);
int c4 = color(125, 2, 140);
int c5 = color(255, 255, 0);
int c6 = color(25, 255, 200);
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);
}
public void setGradient(int x, int y, float w, float h, int c1, int c2, int axis ){
// calculate differences between color components
float deltaR = red(c2)-red(c1);
float deltaG = green(c2)-green(c1);
float deltaB = blue(c2)-blue(c1);
// choose axis
if(axis == Y_AXIS){
/*nested for loops set pixels
in a basic table structure */
// column
for (int i=x; i<=(x+w); i++){
// row
for (int j = y; j<=(y+h); j++){
int c = color(
(red(c1)+(j-y)*(deltaR/h)),
(green(c1)+(j-y)*(deltaG/h)),
(blue(c1)+(j-y)*(deltaB/h))
);
set(i, j, c);
}
}
}
else if(axis == X_AXIS){
// column
for (int i=y; i<=(y+h); i++){
// row
for (int j = x; j<=(x+w); j++){
int c = color(
(red(c1)+(j-x)*(deltaR/h)),
(green(c1)+(j-x)*(deltaG/h)),
(blue(c1)+(j-x)*(deltaB/h))
);
set(j, i, c);
}
}
}
}
static public void main(String args[]) {
PApplet.main(new String[] { "LinearGradient" });
}
}

View File

@@ -0,0 +1,73 @@
/**
* Simple Linear Gradient
* by Ira Greenberg.
*
* Using the convenient red(), green()
* and blue() component functions,
* generate some linear gradients.
*/
// constants
int Y_AXIS = 1;
int X_AXIS = 2;
void setup(){
size(200, 200);
// 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);
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);
}
void setGradient(int x, int y, float w, float h, color c1, color c2, int axis ){
// calculate differences between color components
float deltaR = red(c2)-red(c1);
float deltaG = green(c2)-green(c1);
float deltaB = blue(c2)-blue(c1);
// choose axis
if(axis == Y_AXIS){
/*nested for loops set pixels
in a basic table structure */
// column
for (int i=x; i<=(x+w); i++){
// row
for (int j = y; j<=(y+h); j++){
color c = color(
(red(c1)+(j-y)*(deltaR/h)),
(green(c1)+(j-y)*(deltaG/h)),
(blue(c1)+(j-y)*(deltaB/h))
);
set(i, j, c);
}
}
}
else if(axis == X_AXIS){
// column
for (int i=y; i<=(y+h); i++){
// row
for (int j = x; j<=(x+w); j++){
color c = color(
(red(c1)+(j-x)*(deltaR/h)),
(green(c1)+(j-x)*(deltaG/h)),
(blue(c1)+(j-x)*(deltaB/h))
);
set(j, i, c);
}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -0,0 +1,58 @@
/**
* 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);
}

View File

@@ -0,0 +1,78 @@
import processing.core.*;
import java.applet.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.*;
import java.util.zip.*;
import java.util.regex.*;
public class RadialGradient extends PApplet {
/**
* Simple Radial Gradient
* by Ira Greenberg.
*
* Using the convenient red(), green()
* and blue() component functions,
* generate an array of radial gradients.
*/
public 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(PApplet.parseInt(random(255)), PApplet.parseInt(random(255)), PApplet.parseInt(random(255))),
color(PApplet.parseInt(random(255)), PApplet.parseInt(random(255)), PApplet.parseInt(random(255))));
}
}
}
public void createGradient (float x, float y, float radius, int c1, int 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.0f;
for (int i=0; i< radius; i++){
for (float j=0; j<360; j+=1.0f/gapFiller){
px = x+cos(radians(angle))*i;
py = y+sin(radians(angle))*i;
angle+=1.0f/gapFiller;
int c = color(
(red(c1)+(i)*(deltaR/radius)),
(green(c1)+(i)*(deltaG/radius)),
(blue(c1)+(i)*(deltaB/radius))
);
set(PApplet.parseInt(px), PApplet.parseInt(py), c);
}
}
// adds smooth edge
// hack anti-aliasing
noFill();
strokeWeight(3);
ellipse(x, y, radius*2, radius*2);
}
static public void main(String args[]) {
PApplet.main(new String[] { "RadialGradient" });
}
}

View File

@@ -0,0 +1,58 @@
/**
* 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);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -0,0 +1,43 @@
/**
* Inspired by Ira Greenberg's RadialGradient sketch,
* but uses a different method for the gradients.
*/
int dim = 40;
void setup() {
size(200, 200);
background(0);
smooth();
noStroke();
ellipseMode(RADIUS);
// create a simple table of gradients
int rows = height / dim;
int cols = width / dim;
for (int row = 0; row < rows; row++) {
for (int col = 0; col < cols; col++) {
drawGradient(col*dim + dim/2, row*dim + dim/2);
}
}
}
void drawGradient(float x, float y) {
int radius = dim/2 - 2;
float r1 = random(255);
float g1 = random(255);
float b1 = random(255);
float dr = (random(255) - r1) / radius;
float dg = (random(255) - g1) / radius;
float db = (random(255) - b1) / radius;
for (int r = radius; r > 0; --r) {
fill(r1, g1, b1);
ellipse(x, y, r, r);
r1 += dr;
g1 += dg;
b1 += db;
}
}

View File

@@ -0,0 +1,46 @@
/**
* Reading.
*
* An image is recreated from its individual component colors.
* The many colors of the image are created through modulating the
* red, green, and blue values. This is an exageration of an LCD display.
*/
size(200, 200);
noStroke();
background(0);
// Load an image from the data directory
PImage img = loadImage("cait.jpg");
img.loadPixels();
// figure out how big to make each block based on
// the sketch area and the size of the input image
int eachW = width / img.width;
int eachH = height / img.height;
int each = min(eachW, eachH);
// vertical stripes will be a third as wide
int stripeW = each / 3;
// make sure the block size is a multiple of 3
each = 3 * stripeW;
int left = (width - (img.width * each)) / 2;
int top = (height - (img.height * each)) / 2;
for (int y = 0; y < img.height; y++) {
int y1 = top + y*each;
for (int x = 0; x < img.width; x++) {
int pixel = img.get(x, y);
int x1 = left + x*each;
fill(red(pixel), 0, 0);
rect(x1 + stripeW*0, y1, stripeW, each);
fill(0, green(pixel), 0);
rect(x1 + stripeW*1, y1, stripeW, each);
fill(0, 0, blue(pixel));
rect(x1 + stripeW*2, y1, stripeW, each);
}
}

View File

@@ -0,0 +1,63 @@
import processing.core.*;
import java.applet.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.*;
import java.util.zip.*;
import java.util.regex.*;
public class Reading extends PApplet {
public void setup() {/**
* Reading.
*
* An image is recreated from its individual component colors.
* The many colors of the image are created through modulating the
* red, green, and blue values. This is an exageration of an LCD display.
*/
size(200, 200);
noStroke();
background(0);
// Load an image from the data directory
PImage c;
c = loadImage("cait.jpg");
int xoff = 0;
int yoff = 0;
int p = 2;
int pix = p*3;
for(int i = 0; i < c.width*c.height; i += 1)
{
int here = c.pixels[i];
fill(red(here), 0, 0);
rect(xoff, yoff, p, pix);
fill(0, green(here), 0);
rect(xoff+p, yoff, p, pix);
fill(0, 0, blue(here));
rect(xoff+p*2, yoff, p, pix);
xoff+=pix;
if(xoff >= width-pix) {
xoff = 0;
yoff += pix;
}
}
noLoop();
}
static public void main(String args[]) {
PApplet.main(new String[] { "Reading" });
}
}

View File

@@ -0,0 +1,42 @@
/**
* Reading.
*
* An image is recreated from its individual component colors.
* The many colors of the image are created through modulating the
* red, green, and blue values. This is an exageration of an LCD display.
*/
size(200, 200);
noStroke();
background(0);
// Load an image from the data directory
PImage c;
c = loadImage("cait.jpg");
int xoff = 0;
int yoff = 0;
int p = 2;
int pix = p*3;
for(int i = 0; i < c.width*c.height; i += 1)
{
int here = c.pixels[i];
fill(red(here), 0, 0);
rect(xoff, yoff, p, pix);
fill(0, green(here), 0);
rect(xoff+p, yoff, p, pix);
fill(0, 0, blue(here));
rect(xoff+p*2, yoff, p, pix);
xoff+=pix;
if(xoff >= width-pix) {
xoff = 0;
yoff += pix;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -0,0 +1,42 @@
/**
* Relativity.
*
* Each color is perceived in relation to other colors.
* The top and bottom bars each contain the same component colors,
* but a different display order causes individual colors to appear differently.
*/
color a, b, c, d, e;
void setup() {
size(200, 200);
noStroke();
a = color(165, 167, 20);
b = color(77, 86, 59);
c = color(42, 106, 105);
d = color(165, 89, 20);
e = color(146, 150, 127);
noLoop();
}
void draw() {
drawBand(a, b, c, d, e, 0, width/50);
drawBand(c, a, d, b, e, height/2, width/50);
}
void drawBand(color v, color w, color x, color y, color z, int ypos, int barWidth) {
int num = 5;
color[] colorOrder = { v, w, x, y, z };
for(int i = 0; i < width; i += barWidth*num) {
for(int j = 0; j < num; j++) {
fill(colorOrder[j]);
rect(i+j*barWidth, ypos, barWidth, height/2);
}
}
}

View File

@@ -0,0 +1,62 @@
import processing.core.*;
import java.applet.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.*;
import java.util.zip.*;
import java.util.regex.*;
public class Relativity extends PApplet {
/**
* Relativity.
*
* Each color is perceived in relation to other colors.
* The top and bottom bars each contain the same component colors,
* but a different display order causes individual colors to appear differently.
*/
int a, b, c, d, e;
public void setup() {
size(200, 200);
noStroke();
a = color(165, 167, 20);
b = color(77, 86, 59);
c = color(42, 106, 105);
d = color(165, 89, 20);
e = color(146, 150, 127);
noLoop();
}
public void draw() {
drawBand(a, b, c, d, e, 0, 4);
drawBand(c, a, d, b, e, height/2, 4);
}
public void drawBand(int v, int w, int x, int y, int z, int ypos, int barWidth) {
int num = 5;
int[] colorOrder = { v, w, x, y, z };
for(int i = 0; i < width; i += barWidth*num) {
for(int j = 0; j < num; j++) {
fill(colorOrder[j]);
rect(i+j*barWidth, ypos, barWidth, height/2);
}
}
}
static public void main(String args[]) {
PApplet.main(new String[] { "Relativity" });
}
}

View File

@@ -0,0 +1,42 @@
/**
* Relativity.
*
* Each color is perceived in relation to other colors.
* The top and bottom bars each contain the same component colors,
* but a different display order causes individual colors to appear differently.
*/
color a, b, c, d, e;
void setup() {
size(200, 200);
noStroke();
a = color(165, 167, 20);
b = color(77, 86, 59);
c = color(42, 106, 105);
d = color(165, 89, 20);
e = color(146, 150, 127);
noLoop();
}
void draw() {
drawBand(a, b, c, d, e, 0, 4);
drawBand(c, a, d, b, e, height/2, 4);
}
void drawBand(color v, color w, color x, color y, color z, int ypos, int barWidth) {
int num = 5;
color[] colorOrder = { v, w, x, y, z };
for(int i = 0; i < width; i += barWidth*num) {
for(int j = 0; j < num; j++) {
fill(colorOrder[j]);
rect(i+j*barWidth, ypos, barWidth, height/2);
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -0,0 +1,29 @@
/**
* Saturation.
*
* Saturation is the strength or purity of the color and represents the
* amount of gray in proportion to the hue. A "saturated" color is pure
* and an "unsaturated" color has a large percentage of gray.
* Move the cursor vertically over each bar to alter its saturation.
*/
int barWidth = 5;
int lastBar = -1;
void setup() {
size(200, 200);
colorMode(HSB, width, height, 100);
noStroke();
}
void draw() {
int whichBar = mouseX / barWidth;
if (whichBar != lastBar) {
int barX = whichBar * barWidth;
fill(barX, mouseY, 66);
rect(barX, 0, barWidth, height);
lastBar = whichBar;
}
}

View File

@@ -0,0 +1,52 @@
import processing.core.*;
import java.applet.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.*;
import java.util.zip.*;
import java.util.regex.*;
public class Saturation extends PApplet {
/**
* Saturation.
*
* Saturation is the strength or purity of the color and represents the
* amount of gray in proportion to the hue. A "saturated" color is pure
* and an "unsaturated" color has a large percentage of gray.
* Move the cursor vertically over each bar to alter its saturation.
*/
int barWidth = 5;
int[] saturation;
public void setup()
{
size(200, 200);
colorMode(HSB, 360, height, height);
saturation = new int[width/barWidth];
}
public void draw()
{
int j = 0;
for (int i=0; i<=(width-barWidth); i+=barWidth) {
noStroke();
if ((mouseX > i) && (mouseX < i+barWidth)) {
saturation[j] = mouseY;
}
fill(i, saturation[j], height/1.5f);
rect(i, 0, barWidth, height);
j++;
}
}
static public void main(String args[]) {
PApplet.main(new String[] { "Saturation" });
}
}

View File

@@ -0,0 +1,32 @@
/**
* Saturation.
*
* Saturation is the strength or purity of the color and represents the
* amount of gray in proportion to the hue. A "saturated" color is pure
* and an "unsaturated" color has a large percentage of gray.
* Move the cursor vertically over each bar to alter its saturation.
*/
int barWidth = 5;
int[] saturation;
void setup()
{
size(200, 200);
colorMode(HSB, 360, height, height);
saturation = new int[width/barWidth];
}
void draw()
{
int j = 0;
for (int i=0; i<=(width-barWidth); i+=barWidth) {
noStroke();
if ((mouseX > i) && (mouseX < i+barWidth)) {
saturation[j] = mouseY;
}
fill(i, saturation[j], height/1.5);
rect(i, 0, barWidth, height);
j++;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -0,0 +1,39 @@
/**
* Wave Gradient
* by Ira Greenberg.
*
* Generate a gradient along a sin() wave.
*/
float angle = 0;
float px = 0, py = 0;
float amplitude = 30;
float frequency = 0;
float fillGap = 2.5;
color c;
void setup() {
size(200, 200);
background(200,200,200);
noLoop();
}
void draw() {
for (int i =- 75; i < height+75; i++){
// Reset angle to 0, so waves stack properly
angle = 0;
// Increasing frequency causes more gaps
frequency+=.006;
for (float j=0; j<width+75; j++){
py = i+sin(radians(angle))*amplitude;
angle+=frequency;
c = color(abs(py-i)*255/amplitude, 255-abs(py-i)*255/amplitude, j*(255.0/(width+50)));
// Hack to fill gaps. Raise value of fillGap if you increase frequency
for (int filler = 0; filler<fillGap; filler++){
set(int(j-filler), int(py)-filler, c);
set(int(j), int(py), c);
set(int(j+filler), int(py)+filler, c);
}
}
}
}

View File

@@ -0,0 +1,59 @@
import processing.core.*;
import java.applet.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.*;
import java.util.zip.*;
import java.util.regex.*;
public class WaveGradient extends PApplet {
/**
* Wave Gradient
* by Ira Greenberg.
*
* Generate a gradient along a sin() wave.
*/
float angle = 0;
float px = 0, py = 0;
float amplitude = 30;
float frequency = 0;
float fillGap = 2.5f;
int c;
public void setup() {
size(200, 200);
background(200,200,200);
noLoop();
}
public void draw() {
for (int i =- 75; i < height+75; i++){
// Reset angle to 0, so waves stack properly
angle = 0;
// Increasing frequency causes more gaps
frequency+=.006f;
for (float j=0; j<width+75; j++){
py = i+sin(radians(angle))*amplitude;
angle+=frequency;
c = color(abs(py-i)*255/amplitude, 255-abs(py-i)*255/amplitude, j*(255.0f/(width+50)));
// Hack to fill gaps. Raise value of fillGap if you increase frequency
for (int filler = 0; filler<fillGap; filler++){
set(PApplet.parseInt(j-filler), PApplet.parseInt(py)-filler, c);
set(PApplet.parseInt(j), PApplet.parseInt(py), c);
set(PApplet.parseInt(j+filler), PApplet.parseInt(py)+filler, c);
}
}
}
}
static public void main(String args[]) {
PApplet.main(new String[] { "WaveGradient" });
}
}

View File

@@ -0,0 +1,39 @@
/**
* Wave Gradient
* by Ira Greenberg.
*
* Generate a gradient along a sin() wave.
*/
float angle = 0;
float px = 0, py = 0;
float amplitude = 30;
float frequency = 0;
float fillGap = 2.5;
color c;
void setup() {
size(200, 200);
background(200,200,200);
noLoop();
}
void draw() {
for (int i =- 75; i < height+75; i++){
// Reset angle to 0, so waves stack properly
angle = 0;
// Increasing frequency causes more gaps
frequency+=.006;
for (float j=0; j<width+75; j++){
py = i+sin(radians(angle))*amplitude;
angle+=frequency;
c = color(abs(py-i)*255/amplitude, 255-abs(py-i)*255/amplitude, j*(255.0/(width+50)));
// Hack to fill gaps. Raise value of fillGap if you increase frequency
for (int filler = 0; filler<fillGap; filler++){
set(int(j-filler), int(py)-filler, c);
set(int(j), int(py), c);
set(int(j+filler), int(py)+filler, c);
}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB