Examples updates for 2.0

This commit is contained in:
Casey Reas
2011-07-17 06:50:01 +00:00
parent d996b52e66
commit 84dd359b1e
33 changed files with 305 additions and 280 deletions
+2 -2
View File
@@ -15,7 +15,7 @@ float hoursRadius;
float clockDiameter;
void setup() {
size(200, 200);
size(640, 360);
stroke(255);
smooth();
@@ -29,7 +29,7 @@ void setup() {
cy = height / 2;
}
void draw2() {
void draw() {
background(0);
// Draw the clock background
@@ -11,11 +11,11 @@ float mx;
float my;
float easing = 0.05;
int radius = 24;
int edge = 56;
int edge = 100;
int inner = edge + radius;
void setup() {
size(200, 200);
size(640, 360);
noStroke();
smooth();
ellipseMode(RADIUS);
+3 -3
View File
@@ -16,14 +16,14 @@ float easing = 0.05;
void setup()
{
size(200, 200);
size(640, 360);
smooth();
noStroke();
}
void draw()
{
background( 51 );
background(51);
targetX = mouseX;
float dx = targetX - x;
@@ -37,5 +37,5 @@ void draw()
y += dy * easing;
}
ellipse(x, y, 33, 33);
ellipse(x, y, 66, 66);
}
@@ -10,7 +10,7 @@
int rectWidth;
void setup() {
size(200, 200);
size(640, 360);
noStroke();
background(0);
rectWidth = width/4;
@@ -9,12 +9,12 @@
* function that is called when a key is released.
*/
int max_height = 20;
int min_height = 10;
int letter_height = max_height; // Height of the letters
int letter_width = 10; // Width of the letter
int maxHeight = 40;
int minHeight = 20;
int letterHeight = maxHeight; // Height of the letters
int letterWidth = 20; // Width of the letter
int x = -letter_width; // X position of the letters
int x = -letterWidth; // X position of the letters
int y = 0; // Y position of the letters
boolean newletter;
@@ -24,7 +24,7 @@ color[] colors = new color[numChars];
void setup()
{
size(200, 200);
size(640, 360);
noStroke();
colorMode(RGB, numChars);
background(numChars/2);
@@ -39,14 +39,14 @@ void draw()
if(newletter == true) {
// Draw the "letter"
int y_pos;
if (letter_height == max_height) {
if (letterHeight == maxHeight) {
y_pos = y;
rect( x, y_pos, letter_width, letter_height );
rect( x, y_pos, letterWidth, letterHeight );
} else {
y_pos = y + min_height;
rect( x, y_pos, letter_width, letter_height );
y_pos = y + minHeight;
rect( x, y_pos, letterWidth, letterHeight );
fill(numChars/2);
rect( x, y_pos-min_height, letter_width, letter_height );
rect( x, y_pos-minHeight, letterWidth, letterHeight );
}
newletter = false;
}
@@ -54,36 +54,36 @@ void draw()
void keyPressed()
{
// if the key is between 'A'(65) and 'z'(122)
// If the key is between 'A'(65) and 'z'(122)
if( key >= 'A' && key <= 'z') {
int keyIndex;
if(key <= 'Z') {
keyIndex = key-'A';
letter_height = max_height;
letterHeight = maxHeight;
fill(colors[key-'A']);
} else {
keyIndex = key-'a';
letter_height = min_height;
letterHeight = minHeight;
fill(colors[key-'a']);
}
} else {
fill(0);
letter_height = 10;
letterHeight = 10;
}
newletter = true;
// Update the "letter" position
x = ( x + letter_width );
x = ( x + letterWidth );
// Wrap horizontally
if (x > width - letter_width) {
if (x > width - letterWidth) {
x = 0;
y+= max_height;
y+= maxHeight;
}
// Wrap vertically
if( y > height - letter_height) {
if( y > height - letterHeight) {
y = 0; // reset y to 0
}
}
@@ -11,16 +11,16 @@ float scale;
void setup()
{
size(200, 200);
size(640, 360);
noStroke();
scale = width/10;
scale = width/20;
}
void draw()
{
for(int i=0; i<scale; i++) {
for(int i = 0; i < scale; i++) {
colorMode(RGB, (i+1) * scale * 10);
fill(millis()%((i+1) * scale * 10) );
fill(millis()%((i+1) * scale * 10));
rect(i*scale, 0, scale, height);
}
}
+13 -31
View File
@@ -5,43 +5,25 @@
* The "mouseX" variable is used to control both the
* size and color of the rectangles.
*/
int gx = 15;
int gy = 35;
float leftColor = 0.0;
float rightColor = 0.0;
void setup() {
size(200, 200);
colorMode(RGB, 1.0);
size(640, 360);
noStroke();
colorMode(RGB, height, height, height);
rectMode(CENTER);
}
void draw() {
background(0.0);
update(mouseX);
fill(0.0, leftColor + 0.4, leftColor + 0.6);
rect(width/4-gx, height/2-gx, gx*2, gx*2);
fill(0.0, rightColor + 0.2, rightColor + 0.4);
rect(width/1.33-gy, height/2-gy, gy*2, gy*2);
float r1 = map(mouseX, 0, width, 0, height);
float r2 = height-r1;
fill(r1);
rect(width/2 + r1/2, height/2, r1, r1);
fill(r2);
rect(width/2 - r2/2, height/2, r2, r2);
}
void update(int x) {
leftColor = -0.002 * x/2 + 0.06;
rightColor = 0.002 * x/2 + 0.06;
gx = x/2;
gy = 100-x/2;
if (gx < 10) {
gx = 10;
} else if (gx > 90) {
gx = 90;
}
if (gy > 90) {
gy = 90;
} else if (gy < 10) {
gy = 10;
}
}
@@ -6,7 +6,7 @@
void setup()
{
size(200, 200);
size(640, 360);
noStroke();
rectMode(CENTER);
}
@@ -6,7 +6,7 @@
float bx;
float by;
int bs = 20;
int bs = 75;
boolean bover = false;
boolean locked = false;
float bdifx = 0.0;
@@ -15,7 +15,7 @@ float bdify = 0.0;
void setup()
{
size(200, 200);
size(640, 360);
bx = width/2.0;
by = height/2.0;
rectMode(RADIUS);
@@ -1,5 +1,5 @@
/**
* Click.
* Mouse Press.
*
* Move the mouse to position the shape.
* Press the mouse button to invert the color.
@@ -7,7 +7,7 @@
void setup() {
size(200, 200);
size(640, 360);
fill(126);
background(102);
}
@@ -13,7 +13,7 @@ int[] bvals;
void setup()
{
size(200, 200);
size(640, 360);
xvals = new int[width];
yvals = new int[width];
bvals = new int[width];
@@ -25,7 +25,7 @@ void draw()
{
background(102);
for(int i=1; i<width; i++) {
for(int i = 1; i < width; i++) {
xvals[i-1] = xvals[i];
yvals[i-1] = yvals[i];
bvals[i-1] = bvals[i];
@@ -6,8 +6,6 @@
* into an array and played back every frame. Between each
* frame, the newest value are added to the end of each array
* and the oldest value is deleted.
*
* Updated 27 February 2010.
*/
int num = 60;
@@ -15,7 +13,7 @@ float mx[] = new float[num];
float my[] = new float[num];
void setup() {
size(200, 200);
size(640, 360);
smooth();
noStroke();
fill(255, 153);
@@ -33,6 +31,6 @@ void draw() {
for (int i = 0; i < num; i++) {
// which+1 is the smallest (the oldest in the array)
int index = (which+1 + i) % num;
ellipse(mx[index], my[index], i/2, i/2);
ellipse(mx[index], my[index], i, i);
}
}