29
java/examples/Basics/Color/Brightness/Brightness.pde
Normal 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;
|
||||
}
|
||||
}
|
||||
51
java/examples/Basics/Color/Brightness/applet/Brightness.java
Normal 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" });
|
||||
}
|
||||
}
|
||||
31
java/examples/Basics/Color/Brightness/applet/Brightness.pde
Normal 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++;
|
||||
}
|
||||
}
|
||||
BIN
java/examples/Basics/Color/Brightness/applet/loading.gif
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
88
java/examples/Basics/Color/ColorWheel/ColorWheel.pde
Normal 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;
|
||||
}
|
||||
}
|
||||
99
java/examples/Basics/Color/ColorWheel/applet/ColorWheel.java
Normal 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" });
|
||||
}
|
||||
}
|
||||
79
java/examples/Basics/Color/ColorWheel/applet/ColorWheel.pde
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BIN
java/examples/Basics/Color/ColorWheel/applet/loading.gif
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
26
java/examples/Basics/Color/Creating/Creating.pde
Normal 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);
|
||||
47
java/examples/Basics/Color/Creating/applet/Creating.java
Normal 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" });
|
||||
}
|
||||
}
|
||||
26
java/examples/Basics/Color/Creating/applet/Creating.pde
Normal 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);
|
||||
BIN
java/examples/Basics/Color/Creating/applet/loading.gif
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
31
java/examples/Basics/Color/Hue/Hue.pde
Normal 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++;
|
||||
}
|
||||
}
|
||||
51
java/examples/Basics/Color/Hue/applet/Hue.java
Normal 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" });
|
||||
}
|
||||
}
|
||||
31
java/examples/Basics/Color/Hue/applet/Hue.pde
Normal 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++;
|
||||
}
|
||||
}
|
||||
BIN
java/examples/Basics/Color/Hue/applet/loading.gif
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
73
java/examples/Basics/Color/LinearGradient/LinearGradient.pde
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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" });
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BIN
java/examples/Basics/Color/LinearGradient/applet/loading.gif
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
58
java/examples/Basics/Color/RadialGradient/RadialGradient.pde
Normal 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);
|
||||
}
|
||||
|
||||
@@ -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" });
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
BIN
java/examples/Basics/Color/RadialGradient/applet/loading.gif
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
46
java/examples/Basics/Color/Reading/Reading.pde
Normal 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);
|
||||
}
|
||||
}
|
||||
63
java/examples/Basics/Color/Reading/applet/Reading.java
Normal 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" });
|
||||
}
|
||||
}
|
||||
42
java/examples/Basics/Color/Reading/applet/Reading.pde
Normal 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;
|
||||
}
|
||||
}
|
||||
|
||||
BIN
java/examples/Basics/Color/Reading/applet/loading.gif
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
42
java/examples/Basics/Color/Relativity/Relativity.pde
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
62
java/examples/Basics/Color/Relativity/applet/Relativity.java
Normal 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" });
|
||||
}
|
||||
}
|
||||
42
java/examples/Basics/Color/Relativity/applet/Relativity.pde
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
BIN
java/examples/Basics/Color/Relativity/applet/loading.gif
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
29
java/examples/Basics/Color/Saturation/Saturation.pde
Normal 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;
|
||||
}
|
||||
}
|
||||
52
java/examples/Basics/Color/Saturation/applet/Saturation.java
Normal 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" });
|
||||
}
|
||||
}
|
||||
32
java/examples/Basics/Color/Saturation/applet/Saturation.pde
Normal 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++;
|
||||
}
|
||||
}
|
||||
BIN
java/examples/Basics/Color/Saturation/applet/loading.gif
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
39
java/examples/Basics/Color/WaveGradient/WaveGradient.pde
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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" });
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
java/examples/Basics/Color/WaveGradient/applet/loading.gif
Normal file
|
After Width: | Height: | Size: 2.2 KiB |