removing applet folders from android examples.. oops

This commit is contained in:
benfry
2011-04-10 17:59:08 +00:00
parent 63cf7cd4da
commit 5ae4534378
517 changed files with 0 additions and 26075 deletions

View File

@@ -1,56 +0,0 @@
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 Array extends PApplet {
public void setup() {/**
* Array.
*
* An array is a list of data. Each piece of data in an array
* is identified by an index number representing its position in
* the array. Arrays are zero based, which means that the first
* element in the array is [0], the second element is [1], and so on.
* In this example, an array named "coswav" is created and
* filled with the cosine values. This data is displayed three
* separate ways on the screen.
*/
size(200, 200);
float[] coswave = new float[width];
for (int i = 0; i < width; i++) {
float amount = map(i, 0, width, 0, PI);
coswave[i] = abs(cos(amount));
}
for (int i = 0; i < width; i++) {
stroke(coswave[i]*255);
line(i, 0, i, height/3);
}
for (int i = 0; i < width; i++) {
stroke(coswave[i]*255 / 4);
line(i, height/3, i, height/3*2);
}
for (int i = 0; i < width; i++) {
stroke(255 - coswave[i]*255);
line(i, height/3*2, i, height);
}
noLoop();
}
static public void main(String args[]) {
PApplet.main(new String[] { "Array" });
}
}

View File

@@ -1,35 +0,0 @@
/**
* Array.
*
* An array is a list of data. Each piece of data in an array
* is identified by an index number representing its position in
* the array. Arrays are zero based, which means that the first
* element in the array is [0], the second element is [1], and so on.
* In this example, an array named "coswav" is created and
* filled with the cosine values. This data is displayed three
* separate ways on the screen.
*/
size(200, 200);
float[] coswave = new float[width];
for (int i = 0; i < width; i++) {
float amount = map(i, 0, width, 0, PI);
coswave[i] = abs(cos(amount));
}
for (int i = 0; i < width; i++) {
stroke(coswave[i]*255);
line(i, 0, i, height/3);
}
for (int i = 0; i < width; i++) {
stroke(coswave[i]*255 / 4);
line(i, height/3, i, height/3*2);
}
for (int i = 0; i < width; i++) {
stroke(255 - coswave[i]*255);
line(i, height/3*2, i, height);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -1,53 +0,0 @@
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 Array2D extends PApplet {
public void setup() {/**
* Array 2D.
*
* Demonstrates the syntax for creating a two-dimensional (2D) array.
* Values in a 2D array are accessed through two index values.
* 2D arrays are useful for storing images. In this example, each dot
* is colored in relation to its distance from the center of the image.
*/
float[][] distances;
float maxDistance;
size(200, 200);
background(0);
maxDistance = dist(width/2, height/2, width, height);
distances = new float[width][height];
for(int i=0; i<height; i++) {
for(int j=0; j<width; j++) {
float dist = dist(width/2, height/2, j, i);
distances[j][i] = dist/maxDistance * 255;
}
}
for(int i=0; i<height; i+=2) {
for(int j=0; j<width; j+=2) {
stroke(distances[j][i]);
point(j, i);
}
}
noLoop();
}
static public void main(String args[]) {
PApplet.main(new String[] { "Array2D" });
}
}

View File

@@ -1,32 +0,0 @@
/**
* Array 2D.
*
* Demonstrates the syntax for creating a two-dimensional (2D) array.
* Values in a 2D array are accessed through two index values.
* 2D arrays are useful for storing images. In this example, each dot
* is colored in relation to its distance from the center of the image.
*/
float[][] distances;
float maxDistance;
size(200, 200);
background(0);
maxDistance = dist(width/2, height/2, width, height);
distances = new float[width][height];
for(int i=0; i<height; i++) {
for(int j=0; j<width; j++) {
float dist = dist(width/2, height/2, j, i);
distances[j][i] = dist/maxDistance * 255;
}
}
for(int i=0; i<height; i+=2) {
for(int j=0; j<width; j+=2) {
stroke(distances[j][i]);
point(j, i);
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -1,94 +0,0 @@
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 ArrayObjects extends PApplet {
/**
* Array Objects.
*
* Demonstrates the syntax for creating an array of custom objects.
*/
int unit = 40;
int num;
Module[] mods;
public void setup()
{
size(200, 200);
background(176);
noStroke();
num = width/unit * width/unit;
mods = new Module[num];
for (int i=0; i<height/unit; i++) {
for(int j=0; j<height/unit; j++) {
int index = i*height/unit + j;
mods[index] = new Module(j*unit, i*unit, unit/2, unit/2, random(0.05f, 0.8f));
}
}
}
public void draw()
{
for(int i=0; i<num; i++) {
mods[i].update();
mods[i].draw();
}
}
class Module {
float mx, my;
int size = unit;
float x, y = 0;
int xdir = 1;
int ydir = 1;
float speed;
// Contructor (required)
Module(float imx, float imy, float ix, float iy, float ispeed) {
mx = imy;
my = imx;
x = PApplet.parseInt(ix);
y = PApplet.parseInt(iy);
speed = ispeed;
}
// Custom method for updating the variables
public void update() {
x = x + (speed * xdir);
if (x >= size || x <= 0) {
xdir *= -1;
x = x + (1 * xdir);
y = y + (1 * ydir);
}
if (y >= size || y <= 0) {
ydir *= -1;
y = y + (1 * ydir);
}
}
// Custom method for drawing the object
public void draw() {
stroke(second()*4);
point(mx+x-1, my+y-1);
}
}
static public void main(String args[]) {
PApplet.main(new String[] { "ArrayObjects" });
}
}

View File

@@ -1,74 +0,0 @@
/**
* Array Objects.
*
* Demonstrates the syntax for creating an array of custom objects.
*/
int unit = 40;
int num;
Module[] mods;
void setup()
{
size(200, 200);
background(176);
noStroke();
num = width/unit * width/unit;
mods = new Module[num];
for (int i=0; i<height/unit; i++) {
for(int j=0; j<height/unit; j++) {
int index = i*height/unit + j;
mods[index] = new Module(j*unit, i*unit, unit/2, unit/2, random(0.05, 0.8));
}
}
}
void draw()
{
for(int i=0; i<num; i++) {
mods[i].update();
mods[i].draw();
}
}
class Module {
float mx, my;
int size = unit;
float x, y = 0;
int xdir = 1;
int ydir = 1;
float speed;
// Contructor (required)
Module(float imx, float imy, float ix, float iy, float ispeed) {
mx = imy;
my = imx;
x = int(ix);
y = int(iy);
speed = ispeed;
}
// Custom method for updating the variables
void update() {
x = x + (speed * xdir);
if (x >= size || x <= 0) {
xdir *= -1;
x = x + (1 * xdir);
y = y + (1 * ydir);
}
if (y >= size || y <= 0) {
ydir *= -1;
y = y + (1 * ydir);
}
}
// Custom method for drawing the object
void draw() {
stroke(second()*4);
point(mx+x-1, my+y-1);
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -1,51 +0,0 @@
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

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

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -1,99 +0,0 @@
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

@@ -1,79 +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.
*/
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.

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -1,47 +0,0 @@
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

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

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -1,51 +0,0 @@
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

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

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -1,93 +0,0 @@
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

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

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -1,78 +0,0 @@
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

@@ -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);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -1,63 +0,0 @@
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

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

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -1,62 +0,0 @@
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

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

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -1,52 +0,0 @@
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

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

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -1,59 +0,0 @@
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

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

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -1,47 +0,0 @@
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 Conditionals1 extends PApplet {
public void setup() {/**
* Conditionals 1.
*
* Conditions are like questions.
* They allow a program to decide to take one action if
* the answer to a question is true or to do another action
* if the answer to the question is false.
* The questions asked within a program are always logical
* or relational statements. For example, if the variable 'i' is
* equal to zero then draw a line.
*/
size(200, 200);
background(0);
for(int i=10; i<width; i+=10) {
// If 'i' divides by 20 with no remainder draw the first line
// else draw the second line
if(i%20 == 0) {
stroke(153);
line(i, 40, i, height/2);
} else {
stroke(102);
line(i, 20, i, 180);
}
}
noLoop();
}
static public void main(String args[]) {
PApplet.main(new String[] { "Conditionals1" });
}
}

View File

@@ -1,26 +0,0 @@
/**
* Conditionals 1.
*
* Conditions are like questions.
* They allow a program to decide to take one action if
* the answer to a question is true or to do another action
* if the answer to the question is false.
* The questions asked within a program are always logical
* or relational statements. For example, if the variable 'i' is
* equal to zero then draw a line.
*/
size(200, 200);
background(0);
for(int i=10; i<width; i+=10) {
// If 'i' divides by 20 with no remainder draw the first line
// else draw the second line
if(i%20 == 0) {
stroke(153);
line(i, 40, i, height/2);
} else {
stroke(102);
line(i, 20, i, 180);
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -1,47 +0,0 @@
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 Conditionals2 extends PApplet {
public void setup() {/**
* Conditionals 2.
*
* We extend the language of conditionals by adding the
* keyword "else". This allows conditionals to ask
* two or more sequential questions, each with a different
* action.
*/
size(200, 200);
background(0);
for(int i=2; i<width-2; i+=2) {
// If 'i' divides by 20 with no remainder
// draw the first line else draw the second line
if(i%20 == 0) {
stroke(255);
line(i, 40, i, height/2);
} else if (i%10 == 0) {
stroke(153);
line(i, 20, i, 180);
} else {
stroke(102);
line(i, height/2, i, height-40);
}
}
noLoop();
}
static public void main(String args[]) {
PApplet.main(new String[] { "Conditionals2" });
}
}

View File

@@ -1,26 +0,0 @@
/**
* Conditionals 2.
*
* We extend the language of conditionals by adding the
* keyword "else". This allows conditionals to ask
* two or more sequential questions, each with a different
* action.
*/
size(200, 200);
background(0);
for(int i=2; i<width-2; i+=2) {
// If 'i' divides by 20 with no remainder
// draw the first line else draw the second line
if(i%20 == 0) {
stroke(255);
line(i, 40, i, height/2);
} else if (i%10 == 0) {
stroke(153);
line(i, 20, i, 180);
} else {
stroke(102);
line(i, height/2, i, height-40);
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -1,48 +0,0 @@
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 EmbeddedIteration extends PApplet {
public void setup() {/**
* Embedding Iteration.
*
* Embedding "for" structures allows repetition in two dimensions.
*/
float box_size = 11;
float box_space = 12;
int margin = 7;
size(200, 200);
background(0);
noStroke();
// Draw gray boxes
for (int i = margin; i < height-margin; i += box_space){
if(box_size > 0){
for(int j = margin; j < width-margin; j+= box_space){
fill(255-box_size*10);
rect(j, i, box_size, box_size);
}
box_size = box_size - 0.6f;
}
}
noLoop();
}
static public void main(String args[]) {
PApplet.main(new String[] { "EmbeddedIteration" });
}
}

View File

@@ -1,27 +0,0 @@
/**
* Embedding Iteration.
*
* Embedding "for" structures allows repetition in two dimensions.
*/
float box_size = 11;
float box_space = 12;
int margin = 7;
size(200, 200);
background(0);
noStroke();
// Draw gray boxes
for (int i = margin; i < height-margin; i += box_space){
if(box_size > 0){
for(int j = margin; j < width-margin; j+= box_space){
fill(255-box_size*10);
rect(j, i, box_size, box_size);
}
box_size = box_size - 0.6;
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -1,66 +0,0 @@
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 Iteration extends PApplet {
public void setup() {/**
* Iteration.
*
* Iteration with a "for" structure constructs repetitive forms.
*/
int k;
int xpos1 = 100;
int xpos2 = 118;
int count = 0;
int timey = 0;
int num = 12;
size(200, 200);
background(102);
noStroke();
// Draw gray bars
fill(255);
k=60;
for(int i=0; i < num/3; i++) {
rect(25, k, 155, 5);
k+=10;
}
// Black bars
fill(51);
k = 40;
for(int i=0; i < num; i++) {
rect(105, k, 30, 5);
k += 10;
}
k = 15;
for(int i = 0; i < num; i++) {
rect(125, k, 30, 5);
k +=10;
}
// Thin lines
k = 42;
fill(0);
for(int i=0; i < num-1; i++) {
rect(36, k, 20, 1);
k+=10;
}
noLoop();
}
static public void main(String args[]) {
PApplet.main(new String[] { "Iteration" });
}
}

View File

@@ -1,45 +0,0 @@
/**
* Iteration.
*
* Iteration with a "for" structure constructs repetitive forms.
*/
int k;
int xpos1 = 100;
int xpos2 = 118;
int count = 0;
int timey = 0;
int num = 12;
size(200, 200);
background(102);
noStroke();
// Draw gray bars
fill(255);
k=60;
for(int i=0; i < num/3; i++) {
rect(25, k, 155, 5);
k+=10;
}
// Black bars
fill(51);
k = 40;
for(int i=0; i < num; i++) {
rect(105, k, 30, 5);
k += 10;
}
k = 15;
for(int i = 0; i < num; i++) {
rect(125, k, 30, 5);
k +=10;
}
// Thin lines
k = 42;
fill(0);
for(int i=0; i < num-1; i++) {
rect(36, k, 20, 1);
k+=10;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -1,66 +0,0 @@
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 LogicalOperators extends PApplet {
public void setup() {/**
* Logical Operators.
*
* The logical operators for AND (&&) and OR (||) are used to
* combine simple relational statements into more complex expressions.
* The NOT (!) operator is used to negate a boolean statement.
*/
size(200, 200);
background(126);
boolean op = false;
for(int i=5; i<=195; i+=5) {
// Logical AND
stroke(0);
if((i > 35) && (i < 100)) {
line(5, i, 95, i);
op = false;
}
// Logical OR
stroke(76);
if((i <= 35) || (i >= 100)) {
line(105, i, 195, i);
op = true;
}
// Testing if a boolean value is "true"
// The expression "if(op)" is equivalent to "if(op == true)"
if(op) {
stroke(0);
point(width/2, i);
}
// Testing if a boolean value is "false"
// The expression "if(!op)" is equivalent to "if(op == false)"
if(!op) {
stroke(255);
point(width/4, i);
}
}
noLoop();
}
static public void main(String args[]) {
PApplet.main(new String[] { "LogicalOperators" });
}
}

View File

@@ -1,45 +0,0 @@
/**
* Logical Operators.
*
* The logical operators for AND (&&) and OR (||) are used to
* combine simple relational statements into more complex expressions.
* The NOT (!) operator is used to negate a boolean statement.
*/
size(200, 200);
background(126);
boolean op = false;
for(int i=5; i<=195; i+=5) {
// Logical AND
stroke(0);
if((i > 35) && (i < 100)) {
line(5, i, 95, i);
op = false;
}
// Logical OR
stroke(76);
if((i <= 35) || (i >= 100)) {
line(105, i, 195, i);
op = true;
}
// Testing if a boolean value is "true"
// The expression "if(op)" is equivalent to "if(op == true)"
if(op) {
stroke(0);
point(width/2, i);
}
// Testing if a boolean value is "false"
// The expression "if(!op)" is equivalent to "if(op == false)"
if(!op) {
stroke(255);
point(width/4, i);
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -1,101 +0,0 @@
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 CharactersStrings extends PApplet {
/**
* Characters Strings.
*
* Click on the image to give it focus and then type letters to
* shift the location of the image.
* Characters are typographic symbols such as A, d, and %.
* The character datatype, abbreviated as char, stores letters and
* symbols in the Unicode format, a coding system developed to support
* a variety of world languages. Characters are distinguished from other
* symbols by putting them between single quotes ('P').
* A string is a sequence of characters. A string is noted by surrounding
* a group of letters with double quotes ("Processing").
* Chars and strings are most often used with the keyboard methods,
* to display text to the screen, and to load images or files.
*/
PImage frog;
PFont fontA;
int lettersize = 90;
int xoffset;
char letter;
public void setup()
{
size(200, 200);
fontA = loadFont("Eureka90.vlw");
textFont(fontA);
textSize(lettersize);
// The String datatype must be capitalized because it is a complex datatype.
// A String is actually a class with its own methods, some of which are
// featured below.
String name= "rathausFrog";
String extension = ".jpg";
int nameLength = name.length();
println("The length of " + name + " is " + nameLength + ".");
name = name.concat(extension);
nameLength = name.length();
println("The length of " + name + " is " + nameLength + ".");
// The parameter for the loadImage() method must be a string
// This line could also be written "frog = loadImage("rathausFrog.jpg");
frog = loadImage(name);
}
public void draw()
{
background(51); // Set background to dark gray
image(frog, xoffset, 0);
// Draw an X
line(0, 0, width, height);
line(0, height, width, 0);
// Get the width of the letter
int letterWidth = PApplet.parseInt(fontA.width(letter) * lettersize);
// Draw the letter to the center of the screen
text(letter, width/2-letterWidth/2, height/2);
}
public void keyPressed()
{
// The variable "key" always contains the value of the most recent key pressed.
// If the key is an upper or lowercase letter between 'A' and 'z'
// the image is shifted to the corresponding value of that key
if(key >= 'A' && key <= 'z') {
letter = PApplet.parseChar(key);
// Scale the values to numbers between 0 and 100
float scale = 100.0f/57.0f;
int temp = PApplet.parseInt((key - 'A') * scale);
// Set the offset for the image
xoffset = temp;
println(key);
}
}
static public void main(String args[]) {
PApplet.main(new String[] { "CharactersStrings" });
}
}

View File

@@ -1,81 +0,0 @@
/**
* Characters Strings.
*
* Click on the image to give it focus and then type letters to
* shift the location of the image.
* Characters are typographic symbols such as A, d, and %.
* The character datatype, abbreviated as char, stores letters and
* symbols in the Unicode format, a coding system developed to support
* a variety of world languages. Characters are distinguished from other
* symbols by putting them between single quotes ('P').
* A string is a sequence of characters. A string is noted by surrounding
* a group of letters with double quotes ("Processing").
* Chars and strings are most often used with the keyboard methods,
* to display text to the screen, and to load images or files.
*/
PImage frog;
PFont fontA;
int lettersize = 90;
int xoffset;
char letter;
void setup()
{
size(200, 200);
fontA = loadFont("Eureka90.vlw");
textFont(fontA);
textSize(lettersize);
// The String datatype must be capitalized because it is a complex datatype.
// A String is actually a class with its own methods, some of which are
// featured below.
String name= "rathausFrog";
String extension = ".jpg";
int nameLength = name.length();
println("The length of " + name + " is " + nameLength + ".");
name = name.concat(extension);
nameLength = name.length();
println("The length of " + name + " is " + nameLength + ".");
// The parameter for the loadImage() method must be a string
// This line could also be written "frog = loadImage("rathausFrog.jpg");
frog = loadImage(name);
}
void draw()
{
background(51); // Set background to dark gray
image(frog, xoffset, 0);
// Draw an X
line(0, 0, width, height);
line(0, height, width, 0);
// Get the width of the letter
int letterWidth = int(fontA.width(letter) * lettersize);
// Draw the letter to the center of the screen
text(letter, width/2-letterWidth/2, height/2);
}
void keyPressed()
{
// The variable "key" always contains the value of the most recent key pressed.
// If the key is an upper or lowercase letter between 'A' and 'z'
// the image is shifted to the corresponding value of that key
if(key >= 'A' && key <= 'z') {
letter = char(key);
// Scale the values to numbers between 0 and 100
float scale = 100.0/57.0;
int temp = int((key - 'A') * scale);
// Set the offset for the image
xoffset = temp;
println(key);
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -1,49 +0,0 @@
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 DatatypeConversion extends PApplet {
public void setup() {/**
* Datatype Conversion.
*
* It is sometimes beneficial to convert a value from one type of
* data to another. Each of the conversion functions converts its parameter
* to an equivalent representation within its datatype.
* The conversion functions include int(), float(), char(), byte(), and others.
*/
size(200, 200);
background(51);
noStroke();
char c; // Chars are used for storing typographic symbols
float f; // Floats are decimal numbers
int i; // Ints are values between 2,147,483,647 and -2147483648
byte b; // Bytes are values between -128 and 128
c = 'A';
f = PApplet.parseFloat(c); // Sets f = 65.0
i = PApplet.parseInt(f * 1.4f); // Sets i to 91
b = PApplet.parseByte(c / 2); // Sets b to 32
rect(f, 0, 40, 66);
fill(204);
rect(i, 67, 40, 66);
fill(255);
rect(b, 134, 40, 66);
noLoop();
}
static public void main(String args[]) {
PApplet.main(new String[] { "DatatypeConversion" });
}
}

View File

@@ -1,28 +0,0 @@
/**
* Datatype Conversion.
*
* It is sometimes beneficial to convert a value from one type of
* data to another. Each of the conversion functions converts its parameter
* to an equivalent representation within its datatype.
* The conversion functions include int(), float(), char(), byte(), and others.
*/
size(200, 200);
background(51);
noStroke();
char c; // Chars are used for storing typographic symbols
float f; // Floats are decimal numbers
int i; // Ints are values between 2,147,483,647 and -2147483648
byte b; // Bytes are values between -128 and 128
c = 'A';
f = float(c); // Sets f = 65.0
i = int(f * 1.4); // Sets i to 91
b = byte(c / 2); // Sets b to 32
rect(f, 0, 40, 66);
fill(204);
rect(i, 67, 40, 66);
fill(255);
rect(b, 134, 40, 66);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -1,56 +0,0 @@
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 IntegersFloats extends PApplet {
/**
* Integers Floats.
*
* Integers and floats are two different kinds of numerical data.
* An integer (more commonly called an int) is a number without
* a decimal point. A float is a floating-point number, which means
* it is a number that has a decimal place. Floats are used when
* more precision is needed.
*/
int a = 0; // Create a variable "a" of the datatype "int"
float b = 0.0f; // Create a variable "b" of the datatype "float"
public void setup()
{
size(200, 200);
stroke(255);
frameRate(30);
}
public void draw()
{
background(51);
a = a + 1;
b = b + 0.2f;
line(a, 0, a, height/2);
line(b, height/2, b, height);
if(a > width) {
a = 0;
}
if(b > width) {
b = 0;
}
}
static public void main(String args[]) {
PApplet.main(new String[] { "IntegersFloats" });
}
}

View File

@@ -1,36 +0,0 @@
/**
* Integers Floats.
*
* Integers and floats are two different kinds of numerical data.
* An integer (more commonly called an int) is a number without
* a decimal point. A float is a floating-point number, which means
* it is a number that has a decimal place. Floats are used when
* more precision is needed.
*/
int a = 0; // Create a variable "a" of the datatype "int"
float b = 0.0; // Create a variable "b" of the datatype "float"
void setup()
{
size(200, 200);
stroke(255);
frameRate(30);
}
void draw()
{
background(51);
a = a + 1;
b = b + 0.2;
line(a, 0, a, height/2);
line(b, height/2, b, height);
if(a > width) {
a = 0;
}
if(b > width) {
b = 0;
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -1,55 +0,0 @@
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 TrueFalse extends PApplet {
public void setup() {/**
* True/False.
*
* Boolean data is one bit of information. True or false.
* It is common to use Booleans with control statements to
* determine the flow of a program. In this example, when the
* boolean value "x" is true, vertical black lines are drawn and when
* the boolean value "x" is false, horizontal gray lines are drawn.
*/
boolean x = false;
size(200, 200);
background(0);
stroke(0);
for (int i = 1; i < width; i += 2)
{
if (i < width/2) {
x = true;
} else {
x = false;
}
if (x) {
stroke(255);
line(i, 1, i, height-1);
}
if (!x) {
stroke(126);
line(width/2 , i, width-2, i);
}
}
noLoop();
}
static public void main(String args[]) {
PApplet.main(new String[] { "TrueFalse" });
}
}

View File

@@ -1,34 +0,0 @@
/**
* True/False.
*
* Boolean data is one bit of information. True or false.
* It is common to use Booleans with control statements to
* determine the flow of a program. In this example, when the
* boolean value "x" is true, vertical black lines are drawn and when
* the boolean value "x" is false, horizontal gray lines are drawn.
*/
boolean x = false;
size(200, 200);
background(0);
stroke(0);
for (int i = 1; i < width; i += 2)
{
if (i < width/2) {
x = true;
} else {
x = false;
}
if (x) {
stroke(255);
line(i, 1, i, height-1);
}
if (!x) {
stroke(126);
line(width/2 , i, width-2, i);
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -1,81 +0,0 @@
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 VariableScope extends PApplet {
/**
* Variable Scope.
*
* Variables may either have a global or local "scope".
* For example, variables declared within either the
* setup() or loop() functions may be only used in these
* functions. Global variables, variables declared outside
* of setup() and loop(), may be used anywhere within the program.
* If a local variable is declared with the same name as a
* global variable, the program will use the local variable to make
* its calculations within the current scope. Variables may be localized
* within classes, functions, and iterative statements.
*/
int a = 20; // Create a global variable "a"
public void setup()
{
size(200, 200);
background(51);
stroke(255);
noLoop();
}
public void draw()
{
// Draw a line using the global variable "a"
line(a, 0, a, height);
// Create a new variable "a" local to the for() statement
for(int a=50; a<80; a += 2) {
line(a, 0, a, height);
}
// Create a new variable "a" local to the loop() method
int a = 100;
// Draw a line using the new local variable "a"
line(a, 0, a, height);
// Make a call to the custom function drawAnotherLine()
drawAnotherLine();
// Make a call to the custom function setYetAnotherLine()
drawYetAnotherLine();
}
public void drawAnotherLine()
{
// Create a new variable "a" local to this method
int a = 185;
// Draw a line using the local variable "a"
line(a, 0, a, height);
}
public void drawYetAnotherLine()
{
// Because no new local variable "a" is set,
// this lines draws using the original global
// variable "a" which is set to the value 20.
line(a+2, 0, a+2, height);
}
static public void main(String args[]) {
PApplet.main(new String[] { "VariableScope" });
}
}

View File

@@ -1,61 +0,0 @@
/**
* Variable Scope.
*
* Variables may either have a global or local "scope".
* For example, variables declared within either the
* setup() or loop() functions may be only used in these
* functions. Global variables, variables declared outside
* of setup() and loop(), may be used anywhere within the program.
* If a local variable is declared with the same name as a
* global variable, the program will use the local variable to make
* its calculations within the current scope. Variables may be localized
* within classes, functions, and iterative statements.
*/
int a = 20; // Create a global variable "a"
void setup()
{
size(200, 200);
background(51);
stroke(255);
noLoop();
}
void draw()
{
// Draw a line using the global variable "a"
line(a, 0, a, height);
// Create a new variable "a" local to the for() statement
for(int a=50; a<80; a += 2) {
line(a, 0, a, height);
}
// Create a new variable "a" local to the loop() method
int a = 100;
// Draw a line using the new local variable "a"
line(a, 0, a, height);
// Make a call to the custom function drawAnotherLine()
drawAnotherLine();
// Make a call to the custom function setYetAnotherLine()
drawYetAnotherLine();
}
void drawAnotherLine()
{
// Create a new variable "a" local to this method
int a = 185;
// Draw a line using the local variable "a"
line(a, 0, a, height);
}
void drawYetAnotherLine()
{
// Because no new local variable "a" is set,
// this lines draws using the original global
// variable "a" which is set to the value 20.
line(a+2, 0, a+2, height);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -1,44 +0,0 @@
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 Variables extends PApplet {
public void setup() {/**
* Variables.
*
* Variables are used for storing values. In this example, changing
* the values of variables 'a' and 'b' significantly change the composition.
*/
size(200, 200);
background(0);
stroke(153);
int a = 20;
int b = 50;
int c = a*8;
int d = a*9;
int e = b-a;
int f = b*2;
int g = f+e;
line(a, f, b, g);
line(b, e, b, g);
line(b, e, d, c);
line(a, e, d-e, c);
noLoop();
}
static public void main(String args[]) {
PApplet.main(new String[] { "Variables" });
}
}

View File

@@ -1,23 +0,0 @@
/**
* Variables.
*
* Variables are used for storing values. In this example, changing
* the values of variables 'a' and 'b' significantly change the composition.
*/
size(200, 200);
background(0);
stroke(153);
int a = 20;
int b = 50;
int c = a*8;
int d = a*9;
int e = b-a;
int f = b*2;
int g = f+e;
line(a, f, b, g);
line(b, e, b, g);
line(b, e, d, c);
line(a, e, d-e, c);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -1,39 +0,0 @@
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 Bezier extends PApplet {
public void setup() {/**
* Bezier.
*
* The first two parameters for the bezier() function specify the
* first point in the curve and the last two parameters specify
* the last point. The middle parameters set the control points
* that define the shape of the curve.
*/
size(200, 200);
background(0);
stroke(255);
noFill();
smooth();
for(int i = 0; i < 100; i += 20) {
bezier(90-(i/2.0f), 20+i, 210, 10, 220, 150, 120-(i/8.0f), 150+(i/4.0f));
}
noLoop();
}
static public void main(String args[]) {
PApplet.main(new String[] { "Bezier" });
}
}

View File

@@ -1,18 +0,0 @@
/**
* Bezier.
*
* The first two parameters for the bezier() function specify the
* first point in the curve and the last two parameters specify
* the last point. The middle parameters set the control points
* that define the shape of the curve.
*/
size(200, 200);
background(0);
stroke(255);
noFill();
smooth();
for(int i = 0; i < 100; i += 20) {
bezier(90-(i/2.0), 20+i, 210, 10, 220, 150, 120-(i/8.0), 150+(i/4.0));
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -1,123 +0,0 @@
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 BezierEllipse extends PApplet {
/**
* Bezier Ellipse
* By Ira Greenberg
*
* Generates an ellipse using bezier() and
* trig functions. Approximately every 1/2
* second a new ellipse is plotted using
* random values for control/anchor points.
*/
// arrays to hold ellipse coordinate data
float[] px, py, cx, cy, cx2, cy2;
// global variable-points in ellipse
int pts = 4;
int controlPtCol = 0xff222222;
int anchorPtCol = 0xffBBBBBB;
public void setup(){
size(200, 200);
smooth();
setEllipse(pts, 65, 65);
frameRate(1);
}
public void draw(){
background(145);
drawEllipse();
setEllipse(PApplet.parseInt(random(3, 12)), random(-100, 150), random(-100, 150));
}
// draw ellipse with anchor/control points
public void drawEllipse(){
strokeWeight(1.125f);
stroke(255);
noFill();
// create ellipse
for (int i=0; i<pts; i++){
if (i==pts-1) {
bezier(px[i], py[i], cx[i], cy[i], cx2[i], cy2[i], px[0], py[0]);
}
else{
bezier(px[i], py[i], cx[i], cy[i], cx2[i], cy2[i], px[i+1], py[i+1]);
}
}
strokeWeight(.75f);
stroke(0);
rectMode(CENTER);
// control handles and tangent lines
for ( int i=0; i< pts; i++){
if (i==pts-1){ // last loop iteration-close path
line(px[0], py[0], cx2[i], cy2[i]);
}
if (i>0){
line(px[i], py[i], cx2[i-1], cy2[i-1]);
}
line(px[i], py[i], cx[i], cy[i]);
}
for ( int i=0; i< pts; i++){
fill(controlPtCol);
noStroke();
//control handles
ellipse(cx[i], cy[i], 4, 4);
ellipse(cx2[i], cy2[i], 4, 4);
fill(anchorPtCol);
stroke(0);
//anchor points
rect(px[i], py[i], 5, 5);
}
}
// fill up arrays with ellipse coordinate data
public void setEllipse(int points, float radius, float controlRadius){
pts = points;
px = new float[points];
py = new float[points];
cx = new float[points];
cy = new float[points];
cx2 = new float[points];
cy2 = new float[points];
float angle = 360.0f/points;
float controlAngle1 = angle/3.0f;
float controlAngle2 = controlAngle1*2.0f;
for ( int i=0; i<points; i++){
px[i] = width/2+cos(radians(angle))*radius;
py[i] = height/2+sin(radians(angle))*radius;
cx[i] = width/2+cos(radians(angle+controlAngle1))*
controlRadius/cos(radians(controlAngle1));
cy[i] = height/2+sin(radians(angle+controlAngle1))*
controlRadius/cos(radians(controlAngle1));
cx2[i] = width/2+cos(radians(angle+controlAngle2))*
controlRadius/cos(radians(controlAngle1));
cy2[i] = height/2+sin(radians(angle+controlAngle2))*
controlRadius/cos(radians(controlAngle1));
//increment angle so trig functions keep chugging along
angle+=360.0f/points;
}
}
static public void main(String args[]) {
PApplet.main(new String[] { "BezierEllipse" });
}
}

View File

@@ -1,103 +0,0 @@
/**
* Bezier Ellipse
* By Ira Greenberg
*
* Generates an ellipse using bezier() and
* trig functions. Approximately every 1/2
* second a new ellipse is plotted using
* random values for control/anchor points.
*/
// arrays to hold ellipse coordinate data
float[] px, py, cx, cy, cx2, cy2;
// global variable-points in ellipse
int pts = 4;
color controlPtCol = #222222;
color anchorPtCol = #BBBBBB;
void setup(){
size(200, 200);
smooth();
setEllipse(pts, 65, 65);
frameRate(1);
}
void draw(){
background(145);
drawEllipse();
setEllipse(int(random(3, 12)), random(-100, 150), random(-100, 150));
}
// draw ellipse with anchor/control points
void drawEllipse(){
strokeWeight(1.125);
stroke(255);
noFill();
// create ellipse
for (int i=0; i<pts; i++){
if (i==pts-1) {
bezier(px[i], py[i], cx[i], cy[i], cx2[i], cy2[i], px[0], py[0]);
}
else{
bezier(px[i], py[i], cx[i], cy[i], cx2[i], cy2[i], px[i+1], py[i+1]);
}
}
strokeWeight(.75);
stroke(0);
rectMode(CENTER);
// control handles and tangent lines
for ( int i=0; i< pts; i++){
if (i==pts-1){ // last loop iteration-close path
line(px[0], py[0], cx2[i], cy2[i]);
}
if (i>0){
line(px[i], py[i], cx2[i-1], cy2[i-1]);
}
line(px[i], py[i], cx[i], cy[i]);
}
for ( int i=0; i< pts; i++){
fill(controlPtCol);
noStroke();
//control handles
ellipse(cx[i], cy[i], 4, 4);
ellipse(cx2[i], cy2[i], 4, 4);
fill(anchorPtCol);
stroke(0);
//anchor points
rect(px[i], py[i], 5, 5);
}
}
// fill up arrays with ellipse coordinate data
void setEllipse(int points, float radius, float controlRadius){
pts = points;
px = new float[points];
py = new float[points];
cx = new float[points];
cy = new float[points];
cx2 = new float[points];
cy2 = new float[points];
float angle = 360.0/points;
float controlAngle1 = angle/3.0;
float controlAngle2 = controlAngle1*2.0;
for ( int i=0; i<points; i++){
px[i] = width/2+cos(radians(angle))*radius;
py[i] = height/2+sin(radians(angle))*radius;
cx[i] = width/2+cos(radians(angle+controlAngle1))*
controlRadius/cos(radians(controlAngle1));
cy[i] = height/2+sin(radians(angle+controlAngle1))*
controlRadius/cos(radians(controlAngle1));
cx2[i] = width/2+cos(radians(angle+controlAngle2))*
controlRadius/cos(radians(controlAngle1));
cy2[i] = height/2+sin(radians(angle+controlAngle2))*
controlRadius/cos(radians(controlAngle1));
//increment angle so trig functions keep chugging along
angle+=360.0/points;
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -1,44 +0,0 @@
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 PieChart extends PApplet {
public void setup() {/**
* Pie Chart
* By Ira Greenberg
*
* Uses the arc() function to generate a pie chart from the data
* stored in an array.
*/
size(200, 200);
background(100);
smooth();
noStroke();
int diameter = 150;
int[] angs = {30, 10, 45, 35, 60, 38, 75, 67};
float lastAng = 0;
for (int i = 0; i < angs.length; i++){
fill(angs[i] * 3.0f);
arc(width/2, height/2, diameter, diameter, lastAng, lastAng+radians(angs[i]));
lastAng += radians(angs[i]);
}
noLoop();
}
static public void main(String args[]) {
PApplet.main(new String[] { "PieChart" });
}
}

View File

@@ -1,23 +0,0 @@
/**
* Pie Chart
* By Ira Greenberg
*
* Uses the arc() function to generate a pie chart from the data
* stored in an array.
*/
size(200, 200);
background(100);
smooth();
noStroke();
int diameter = 150;
int[] angs = {30, 10, 45, 35, 60, 38, 75, 67};
float lastAng = 0;
for (int i = 0; i < angs.length; i++){
fill(angs[i] * 3.0);
arc(width/2, height/2, diameter, diameter, lastAng, lastAng+radians(angs[i]));
lastAng += radians(angs[i]);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -1,53 +0,0 @@
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 PointsLines extends PApplet {
public void setup() {/**
* Points and Lines.
*
* Constructing a simple dimensional form with lines and rectangles.
* Changing the value of the variable 'd' scales the image.
* The four variables set the positions based on the value of 'd'.
*/
int d = 40;
int p1 = d;
int p2 = p1+d;
int p3 = p2+d;
int p4 = p3+d;
size(200, 200);
background(0);
// Draw gray box
stroke(153);
line(p3, p3, p2, p3);
line(p2, p3, p2, p2);
line(p2, p2, p3, p2);
line(p3, p2, p3, p3);
// Draw white points
stroke(255);
point(p1, p1);
point(p1, p3);
point(p2, p4);
point(p3, p1);
point(p4, p2);
point(p4, p4);
noLoop();
}
static public void main(String args[]) {
PApplet.main(new String[] { "PointsLines" });
}
}

View File

@@ -1,32 +0,0 @@
/**
* Points and Lines.
*
* Constructing a simple dimensional form with lines and rectangles.
* Changing the value of the variable 'd' scales the image.
* The four variables set the positions based on the value of 'd'.
*/
int d = 40;
int p1 = d;
int p2 = p1+d;
int p3 = p2+d;
int p4 = p3+d;
size(200, 200);
background(0);
// Draw gray box
stroke(153);
line(p3, p3, p2, p3);
line(p2, p3, p2, p2);
line(p2, p2, p3, p2);
line(p3, p2, p3, p3);
// Draw white points
stroke(255);
point(p1, p1);
point(p1, p3);
point(p2, p4);
point(p3, p1);
point(p4, p2);
point(p4, p4);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -1,42 +0,0 @@
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 ShapePrimitives extends PApplet {
public void setup() {/**
* Shape Primitives.
*
* The basic shape primitive functions are triangle(),
* rect(), quad(), and ellipse(). Squares are made
* with rect() and circles are made with
* ellipse(). Each of these functions requires a number
* of parameters which determines their position and size.
*/
size(200, 200);
smooth();
background(0);
noStroke();
fill(226);
triangle(10, 10, 10, 200, 45, 200);
rect(45, 45, 35, 35);
quad(105, 10, 120, 10, 120, 200, 80, 200);
ellipse(140, 80, 40, 40);
triangle(160, 10, 195, 200, 160, 200);
noLoop();
}
static public void main(String args[]) {
PApplet.main(new String[] { "ShapePrimitives" });
}
}

View File

@@ -1,21 +0,0 @@
/**
* Shape Primitives.
*
* The basic shape primitive functions are triangle(),
* rect(), quad(), and ellipse(). Squares are made
* with rect() and circles are made with
* ellipse(). Each of these functions requires a number
* of parameters which determines their position and size.
*/
size(200, 200);
smooth();
background(0);
noStroke();
fill(226);
triangle(10, 10, 10, 200, 45, 200);
rect(45, 45, 35, 35);
quad(105, 10, 120, 10, 120, 200, 80, 200);
ellipse(140, 80, 40, 40);
triangle(160, 10, 195, 200, 160, 200);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -1,101 +0,0 @@
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 SimpleCurves extends PApplet {
/**
* Simple Curves.
*
* Simple curves are drawn with simple equations.
* By using numbers with values between 0 and 1 in
* the equations, a series of elegant curves
* are created. The numbers are then scaled to fill the screen.
*/
public void setup() {
size(200, 200);
colorMode(RGB, 100);
background(0);
noFill();
noLoop();
}
public void draw() {
stroke(40);
beginShape();
for(int i=0; i<width; i++) {
vertex(i, singraph((float)i/width)*height);
}
endShape();
stroke(55);
beginShape();
for(int i=0; i<width; i++) {
vertex(i, quad((float)i/width)*height);
}
endShape();
stroke(70);
beginShape();
for(int i=0; i<width; i++) {
vertex(i, quadHump((float)i/width)*height);
}
endShape();
stroke(85);
beginShape();
for(int i=0; i<width; i++) {
vertex(i, hump((float)i/width)*height);
}
endShape();
stroke(100);
beginShape();
for(int i=0; i<width; i++) {
vertex(i, squared((float)i/width)*height);
}
endShape();
}
public float singraph(float sa) {
sa = (sa - 0.5f) * 1.0f; //scale from -1 to 1
sa = sin(sa*PI)/2 + 0.5f;
return sa;
}
public float quad(float sa) {
return sa*sa*sa*sa;
}
public float quadHump(float sa) {
sa = (sa - 0.5f); //scale from -2 to 2
sa = sa*sa*sa*sa * 16;
return sa;
}
public float hump(float sa) {
sa = (sa - 0.5f) * 2; //scale from -2 to 2
sa = sa*sa;
if(sa > 1) { sa = 1; }
return 1-sa;
}
public float squared(float sa) {
sa = sa*sa;
return sa;
}
static public void main(String args[]) {
PApplet.main(new String[] { "SimpleCurves" });
}
}

View File

@@ -1,81 +0,0 @@
/**
* Simple Curves.
*
* Simple curves are drawn with simple equations.
* By using numbers with values between 0 and 1 in
* the equations, a series of elegant curves
* are created. The numbers are then scaled to fill the screen.
*/
void setup() {
size(200, 200);
colorMode(RGB, 100);
background(0);
noFill();
noLoop();
}
void draw() {
stroke(40);
beginShape();
for(int i=0; i<width; i++) {
vertex(i, singraph((float)i/width)*height);
}
endShape();
stroke(55);
beginShape();
for(int i=0; i<width; i++) {
vertex(i, quad((float)i/width)*height);
}
endShape();
stroke(70);
beginShape();
for(int i=0; i<width; i++) {
vertex(i, quadHump((float)i/width)*height);
}
endShape();
stroke(85);
beginShape();
for(int i=0; i<width; i++) {
vertex(i, hump((float)i/width)*height);
}
endShape();
stroke(100);
beginShape();
for(int i=0; i<width; i++) {
vertex(i, squared((float)i/width)*height);
}
endShape();
}
float singraph(float sa) {
sa = (sa - 0.5) * 1.0; //scale from -1 to 1
sa = sin(sa*PI)/2 + 0.5;
return sa;
}
float quad(float sa) {
return sa*sa*sa*sa;
}
float quadHump(float sa) {
sa = (sa - 0.5); //scale from -2 to 2
sa = sa*sa*sa*sa * 16;
return sa;
}
float hump(float sa) {
sa = (sa - 0.5) * 2; //scale from -2 to 2
sa = sa*sa;
if(sa > 1) { sa = 1; }
return 1-sa;
}
float squared(float sa) {
sa = sa*sa;
return sa;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -1,57 +0,0 @@
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 TriangleStrip extends PApplet {
public void setup() {/**
* TRIANGLE_STRIP Mode
* By Ira Greenberg
*
* Generate a closed ring using vertex()
* function and beginShape(TRIANGLE_STRIP)
* mode. outerRad and innerRad variables
* control ring's outer/inner radii respectively.
* Trig functions generate ring.
*/
size(200, 200);
background(204);
smooth();
int x = width/2;
int y = height/2;
int outerRad = 80;
int innerRad = 50;
float px = 0, py = 0, angle = 0;
float pts = 36;
float rot = 360.0f/pts;
beginShape(TRIANGLE_STRIP);
for (int i = 0; i < pts; i++) {
px = x + cos(radians(angle))*outerRad;
py = y + sin(radians(angle))*outerRad;
angle += rot;
vertex(px, py);
px = x + cos(radians(angle))*innerRad;
py = y + sin(radians(angle))*innerRad;
vertex(px, py);
angle += rot;
}
endShape();
noLoop();
}
static public void main(String args[]) {
PApplet.main(new String[] { "TriangleStrip" });
}
}

View File

@@ -1,36 +0,0 @@
/**
* TRIANGLE_STRIP Mode
* By Ira Greenberg
*
* Generate a closed ring using vertex()
* function and beginShape(TRIANGLE_STRIP)
* mode. outerRad and innerRad variables
* control ring's outer/inner radii respectively.
* Trig functions generate ring.
*/
size(200, 200);
background(204);
smooth();
int x = width/2;
int y = height/2;
int outerRad = 80;
int innerRad = 50;
float px = 0, py = 0, angle = 0;
float pts = 36;
float rot = 360.0/pts;
beginShape(TRIANGLE_STRIP);
for (int i = 0; i < pts; i++) {
px = x + cos(radians(angle))*outerRad;
py = y + sin(radians(angle))*outerRad;
angle += rot;
vertex(px, py);
px = x + cos(radians(angle))*innerRad;
py = y + sin(radians(angle))*innerRad;
vertex(px, py);
angle += rot;
}
endShape();

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -1,68 +0,0 @@
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 Vertices extends PApplet {
public void setup() {/**
* Vertices.
*
* The beginShape() function begins recording vertices
* for a shape and endShape() stops recording.
* A vertex is a location in space specified by X, Y,
* and sometimes Z coordinates. After calling the beginShape() function,
* a series of vertex() functions must follow.
* To stop drawing the shape, call the endShape() functions.
*/
size(200, 200);
background(0);
noFill();
stroke(102);
beginShape();
curveVertex(168, 182);
curveVertex(168, 182);
curveVertex(136, 38);
curveVertex(42, 34);
curveVertex(64, 200);
curveVertex(64, 200);
endShape();
stroke(51);
beginShape(LINES);
vertex(60, 40);
vertex(160, 10);
vertex(170, 150);
vertex(60, 150);
endShape();
stroke(126);
beginShape();
vertex(60, 40);
bezierVertex(160, 10, 170, 150, 60, 150);
endShape();
stroke(255);
beginShape(POINTS);
vertex(60, 40);
vertex(160, 10);
vertex(170, 150);
vertex(60, 150);
endShape();
noLoop();
}
static public void main(String args[]) {
PApplet.main(new String[] { "Vertices" });
}
}

View File

@@ -1,47 +0,0 @@
/**
* Vertices.
*
* The beginShape() function begins recording vertices
* for a shape and endShape() stops recording.
* A vertex is a location in space specified by X, Y,
* and sometimes Z coordinates. After calling the beginShape() function,
* a series of vertex() functions must follow.
* To stop drawing the shape, call the endShape() functions.
*/
size(200, 200);
background(0);
noFill();
stroke(102);
beginShape();
curveVertex(168, 182);
curveVertex(168, 182);
curveVertex(136, 38);
curveVertex(42, 34);
curveVertex(64, 200);
curveVertex(64, 200);
endShape();
stroke(51);
beginShape(LINES);
vertex(60, 40);
vertex(160, 10);
vertex(170, 150);
vertex(60, 150);
endShape();
stroke(126);
beginShape();
vertex(60, 40);
bezierVertex(160, 10, 170, 150, 60, 150);
endShape();
stroke(255);
beginShape(POINTS);
vertex(60, 40);
vertex(160, 10);
vertex(170, 150);
vertex(60, 150);
endShape();

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -1,45 +0,0 @@
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 Alphamask extends PApplet {
/**
* Alpha Mask.
*
* Loads a "mask" for an image to specify the transparency
* in different parts of the image. The two images are blended
* together using the mask() method of PImage.
*/
PImage img;
PImage maskImg;
public void setup()
{
size(200,200);
img = loadImage("test.jpg");
maskImg = loadImage("mask.jpg");
img.mask(maskImg);
}
public void draw()
{
background((mouseX+mouseY)/1.5f);
image(img, 50, 50);
image(img, mouseX-50, mouseY-50);
}
static public void main(String args[]) {
PApplet.main(new String[] { "Alphamask" });
}
}

View File

@@ -1,25 +0,0 @@
/**
* Alpha Mask.
*
* Loads a "mask" for an image to specify the transparency
* in different parts of the image. The two images are blended
* together using the mask() method of PImage.
*/
PImage img;
PImage maskImg;
void setup()
{
size(200,200);
img = loadImage("test.jpg");
maskImg = loadImage("mask.jpg");
img.mask(maskImg);
}
void draw()
{
background((mouseX+mouseY)/1.5);
image(img, 50, 50);
image(img, mouseX-50, mouseY-50);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -1,50 +0,0 @@
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 BackgroundImage extends PApplet {
/**
* Background Image.
*
* This example presents the fastest way to load a background image
* into Processing. To load an image as the background, it must be
* the same width and height as the program.
*/
PImage bg;
int a;
public void setup()
{
size(200,200);
frameRate(30);
// The background image must be the same size as the parameters
// into the size() method. In this program, the size of "milan_rubbish.jpg"
// is 200 x 200 pixels.
bg = loadImage("milan_rubbish.jpg");
}
public void draw()
{
background(bg);
a = (a + 1)%(width+32);
stroke(226, 204, 0);
line(0, a, width, a-26);
line(0, a-6, width, a-32);
}
static public void main(String args[]) {
PApplet.main(new String[] { "BackgroundImage" });
}
}

Some files were not shown because too many files have changed in this diff Show More