@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* Clock.
|
||||
*
|
||||
* The current time can be read with the second(), minute(),
|
||||
* and hour() functions. In this example, sin() and cos() values
|
||||
* are used to set the position of the hands.
|
||||
*
|
||||
* Updated 27 February 2010 to handle size() changes.
|
||||
*/
|
||||
|
||||
int cx, cy;
|
||||
float secondsRadius;
|
||||
float minutesRadius;
|
||||
float hoursRadius;
|
||||
float clockDiameter;
|
||||
|
||||
void setup() {
|
||||
size(200, 200);
|
||||
stroke(255);
|
||||
smooth();
|
||||
|
||||
int radius = min(width, height) / 2;
|
||||
secondsRadius = radius * 0.72;
|
||||
minutesRadius = radius * 0.60;
|
||||
hoursRadius = radius * 0.50;
|
||||
clockDiameter = radius * 1.8;
|
||||
|
||||
cx = width / 2;
|
||||
cy = height / 2;
|
||||
}
|
||||
|
||||
void draw2() {
|
||||
background(0);
|
||||
|
||||
// Draw the clock background
|
||||
fill(80);
|
||||
noStroke();
|
||||
ellipse(cx, cy, clockDiameter, clockDiameter);
|
||||
|
||||
// Angles for sin() and cos() start at 3 o'clock;
|
||||
// subtract HALF_PI to make them start at the top
|
||||
float s = map(second(), 0, 60, 0, TWO_PI) - HALF_PI;
|
||||
float m = map(minute() + norm(second(), 0, 60), 0, 60, 0, TWO_PI) - HALF_PI;
|
||||
float h = map(hour() + norm(minute(), 0, 60), 0, 24, 0, TWO_PI * 2) - HALF_PI;
|
||||
|
||||
// Draw the hands of the clock
|
||||
stroke(255);
|
||||
strokeWeight(1);
|
||||
line(cx, cy, cx + cos(s) * secondsRadius, cy + sin(s) * secondsRadius);
|
||||
strokeWeight(2);
|
||||
line(cx, cy, cx + cos(m) * minutesRadius, cy + sin(m) * minutesRadius);
|
||||
strokeWeight(4);
|
||||
line(cx, cy, cx + cos(h) * hoursRadius, cy + sin(h) * hoursRadius);
|
||||
|
||||
// Draw the minute ticks
|
||||
strokeWeight(2);
|
||||
beginShape(POINTS);
|
||||
for (int a = 0; a < 360; a+=6) {
|
||||
float x = cx + cos(radians(a)) * secondsRadius;
|
||||
float y = cy + sin(radians(a)) * secondsRadius;
|
||||
vertex(x, y);
|
||||
}
|
||||
endShape();
|
||||
}
|
||||
@@ -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 Clock extends PApplet {
|
||||
|
||||
/**
|
||||
* Clock.
|
||||
*
|
||||
* The current time can be read with the second(), minute(),
|
||||
* and hour() functions. In this example, sin() and cos() values
|
||||
* are used to set the position of the hands.
|
||||
*/
|
||||
|
||||
public void setup() {
|
||||
size(200, 200);
|
||||
stroke(255);
|
||||
smooth();
|
||||
}
|
||||
public void draw() {
|
||||
background(0);
|
||||
fill(80);
|
||||
noStroke();
|
||||
// Angles for sin() and cos() start at 3 o'clock;
|
||||
// subtract HALF_PI to make them start at the top
|
||||
ellipse(100, 100, 160, 160);
|
||||
float s = map(second(), 0, 60, 0, TWO_PI) - HALF_PI;
|
||||
float m = map(minute() + norm(second(), 0, 60), 0, 60, 0, TWO_PI) - HALF_PI;
|
||||
float h = map(hour() + norm(minute(), 0, 60), 0, 24, 0, TWO_PI * 2) - HALF_PI;
|
||||
stroke(255);
|
||||
strokeWeight(1);
|
||||
line(100, 100, cos(s) * 72 + 100, sin(s) * 72 + 100);
|
||||
strokeWeight(2);
|
||||
line(100, 100, cos(m) * 60 + 100, sin(m) * 60 + 100);
|
||||
strokeWeight(4);
|
||||
line(100, 100, cos(h) * 50 + 100, sin(h) * 50 + 100);
|
||||
|
||||
// Draw the minute ticks
|
||||
strokeWeight(2);
|
||||
for (int a = 0; a < 360; a+=6) {
|
||||
float x = 100 + ( cos(radians(a)) * 72 );
|
||||
float y = 100 + ( sin(radians(a)) * 72 );
|
||||
point(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "Clock" });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Clock.
|
||||
*
|
||||
* The current time can be read with the second(), minute(),
|
||||
* and hour() functions. In this example, sin() and cos() values
|
||||
* are used to set the position of the hands.
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
size(200, 200);
|
||||
stroke(255);
|
||||
smooth();
|
||||
}
|
||||
void draw() {
|
||||
background(0);
|
||||
fill(80);
|
||||
noStroke();
|
||||
// Angles for sin() and cos() start at 3 o'clock;
|
||||
// subtract HALF_PI to make them start at the top
|
||||
ellipse(100, 100, 160, 160);
|
||||
float s = map(second(), 0, 60, 0, TWO_PI) - HALF_PI;
|
||||
float m = map(minute() + norm(second(), 0, 60), 0, 60, 0, TWO_PI) - HALF_PI;
|
||||
float h = map(hour() + norm(minute(), 0, 60), 0, 24, 0, TWO_PI * 2) - HALF_PI;
|
||||
stroke(255);
|
||||
strokeWeight(1);
|
||||
line(100, 100, cos(s) * 72 + 100, sin(s) * 72 + 100);
|
||||
strokeWeight(2);
|
||||
line(100, 100, cos(m) * 60 + 100, sin(m) * 60 + 100);
|
||||
strokeWeight(4);
|
||||
line(100, 100, cos(h) * 50 + 100, sin(h) * 50 + 100);
|
||||
|
||||
// Draw the minute ticks
|
||||
strokeWeight(2);
|
||||
for (int a = 0; a < 360; a+=6) {
|
||||
float x = 100 + ( cos(radians(a)) * 72 );
|
||||
float y = 100 + ( sin(radians(a)) * 72 );
|
||||
point(x, y);
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 2.2 KiB |
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Constrain.
|
||||
*
|
||||
* Move the mouse across the screen to move the circle.
|
||||
* The program constrains the circle to its box.
|
||||
*
|
||||
* Updated 27 February 2010 to handle changes in size().
|
||||
*/
|
||||
|
||||
float mx;
|
||||
float my;
|
||||
float easing = 0.05;
|
||||
int radius = 24;
|
||||
int edge = 56;
|
||||
int inner = edge + radius;
|
||||
|
||||
void setup() {
|
||||
size(200, 200);
|
||||
noStroke();
|
||||
smooth();
|
||||
ellipseMode(RADIUS);
|
||||
rectMode(CORNERS);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(51);
|
||||
|
||||
if (abs(mouseX - mx) > 0.1) {
|
||||
mx = mx + (mouseX - mx) * easing;
|
||||
}
|
||||
if (abs(mouseY - my) > 0.1) {
|
||||
my = my + (mouseY- my) * easing;
|
||||
}
|
||||
|
||||
mx = constrain(mx, inner, width - inner);
|
||||
my = constrain(my, inner, height - inner);
|
||||
fill(76);
|
||||
rect(edge, edge, width-edge, height-edge);
|
||||
fill(255);
|
||||
ellipse(mx, my, radius, radius);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
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 Constrain extends PApplet {
|
||||
|
||||
/**
|
||||
* Constrain.
|
||||
*
|
||||
* Move the mouse across the screen to move the circle.
|
||||
* The program constrains the circle to its box.
|
||||
*/
|
||||
|
||||
float mx;
|
||||
float my;
|
||||
float easing = 0.05f;
|
||||
float esize = 25.0f;
|
||||
int box = 30;
|
||||
|
||||
public void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
noStroke();
|
||||
smooth();
|
||||
ellipseMode(CENTER_RADIUS);
|
||||
}
|
||||
|
||||
public void draw()
|
||||
{
|
||||
background(51);
|
||||
|
||||
if(abs(mouseX - mx) > 0.1f) {
|
||||
mx = mx + (mouseX - mx) * easing;
|
||||
}
|
||||
if(abs(mouseY - my) > 0.1f) {
|
||||
my = my + (mouseY- my) * easing;
|
||||
}
|
||||
|
||||
float distance = esize * 2;
|
||||
mx = constrain(mx, box+distance, width-box-distance);
|
||||
my = constrain(my, box+distance, height-box-distance);
|
||||
fill(76);
|
||||
rect(box+esize, box+esize, box*3, box*3);
|
||||
fill(255);
|
||||
ellipse(mx, my, esize, esize);
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "Constrain" });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Constrain.
|
||||
*
|
||||
* Move the mouse across the screen to move the circle.
|
||||
* The program constrains the circle to its box.
|
||||
*/
|
||||
|
||||
float mx;
|
||||
float my;
|
||||
float easing = 0.05;
|
||||
float esize = 25.0;
|
||||
int box = 30;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
noStroke();
|
||||
smooth();
|
||||
ellipseMode(CENTER_RADIUS);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(51);
|
||||
|
||||
if(abs(mouseX - mx) > 0.1) {
|
||||
mx = mx + (mouseX - mx) * easing;
|
||||
}
|
||||
if(abs(mouseY - my) > 0.1) {
|
||||
my = my + (mouseY- my) * easing;
|
||||
}
|
||||
|
||||
float distance = esize * 2;
|
||||
mx = constrain(mx, box+distance, width-box-distance);
|
||||
my = constrain(my, box+distance, height-box-distance);
|
||||
fill(76);
|
||||
rect(box+esize, box+esize, box*3, box*3);
|
||||
fill(255);
|
||||
ellipse(mx, my, esize, esize);
|
||||
}
|
||||
|
After Width: | Height: | Size: 2.2 KiB |
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Easing.
|
||||
*
|
||||
* Move the mouse across the screen and the symbol will follow.
|
||||
* Between drawing each frame of the animation, the program
|
||||
* calculates the difference between the position of the
|
||||
* symbol and the cursor. If the distance is larger than
|
||||
* 1 pixel, the symbol moves part of the distance (0.05) from its
|
||||
* current position toward the cursor.
|
||||
*/
|
||||
|
||||
float x;
|
||||
float y;
|
||||
float targetX, targetY;
|
||||
float easing = 0.05;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
smooth();
|
||||
noStroke();
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background( 51 );
|
||||
|
||||
targetX = mouseX;
|
||||
float dx = targetX - x;
|
||||
if(abs(dx) > 1) {
|
||||
x += dx * easing;
|
||||
}
|
||||
|
||||
targetY = mouseY;
|
||||
float dy = targetY - y;
|
||||
if(abs(dy) > 1) {
|
||||
y += dy * easing;
|
||||
}
|
||||
|
||||
ellipse(x, y, 33, 33);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
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 Easing extends PApplet {
|
||||
|
||||
/**
|
||||
* Easing.
|
||||
*
|
||||
* Move the mouse across the screen and the symbol will follow.
|
||||
* Between drawing each frame of the animation, the program
|
||||
* calculates the difference between the position of the
|
||||
* symbol and the cursor. If the distance is larger than
|
||||
* 1 pixel, the symbol moves part of the distance (0.05) from its
|
||||
* current position toward the cursor.
|
||||
*/
|
||||
|
||||
float x;
|
||||
float y;
|
||||
float targetX, targetY;
|
||||
float easing = 0.05f;
|
||||
|
||||
public void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
smooth();
|
||||
noStroke();
|
||||
}
|
||||
|
||||
public void draw()
|
||||
{
|
||||
background( 51 );
|
||||
|
||||
targetX = mouseX;
|
||||
float dx = mouseX - x;
|
||||
if(abs(dx) > 1) {
|
||||
x += dx * easing;
|
||||
}
|
||||
|
||||
targetY = mouseY;
|
||||
float dy = mouseY - y;
|
||||
if(abs(dy) > 1) {
|
||||
y += dy * easing;
|
||||
}
|
||||
|
||||
ellipse(x, y, 33, 33);
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "Easing" });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Easing.
|
||||
*
|
||||
* Move the mouse across the screen and the symbol will follow.
|
||||
* Between drawing each frame of the animation, the program
|
||||
* calculates the difference between the position of the
|
||||
* symbol and the cursor. If the distance is larger than
|
||||
* 1 pixel, the symbol moves part of the distance (0.05) from its
|
||||
* current position toward the cursor.
|
||||
*/
|
||||
|
||||
float x;
|
||||
float y;
|
||||
float targetX, targetY;
|
||||
float easing = 0.05;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
smooth();
|
||||
noStroke();
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background( 51 );
|
||||
|
||||
targetX = mouseX;
|
||||
float dx = mouseX - x;
|
||||
if(abs(dx) > 1) {
|
||||
x += dx * easing;
|
||||
}
|
||||
|
||||
targetY = mouseY;
|
||||
float dy = mouseY - y;
|
||||
if(abs(dy) > 1) {
|
||||
y += dy * easing;
|
||||
}
|
||||
|
||||
ellipse(x, y, 33, 33);
|
||||
}
|
||||
|
After Width: | Height: | Size: 2.2 KiB |
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Keyboard.
|
||||
*
|
||||
* Click on the image to give it focus and press the letter keys
|
||||
* to create forms in time and space. Each key has a unique identifying
|
||||
* number called its ASCII value. These numbers can be used to position
|
||||
* shapes in space.
|
||||
*/
|
||||
|
||||
int rectWidth;
|
||||
|
||||
void setup() {
|
||||
size(200, 200);
|
||||
noStroke();
|
||||
background(0);
|
||||
rectWidth = width/4;
|
||||
}
|
||||
|
||||
void draw() {
|
||||
// keep draw() here to continue looping while waiting for keys
|
||||
}
|
||||
|
||||
void keyPressed() {
|
||||
int keyIndex = -1;
|
||||
if (key >= 'A' && key <= 'Z') {
|
||||
keyIndex = key - 'A';
|
||||
} else if (key >= 'a' && key <= 'z') {
|
||||
keyIndex = key - 'a';
|
||||
}
|
||||
if (keyIndex == -1) {
|
||||
// If it's not a letter key, clear the screen
|
||||
background(0);
|
||||
} else {
|
||||
// It's a letter key, fill a rectangle
|
||||
fill(millis() % 255);
|
||||
float x = map(keyIndex, 0, 25, 0, width - rectWidth);
|
||||
rect(x, 0, rectWidth, height);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
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 Keyboard extends PApplet {
|
||||
|
||||
/**
|
||||
* Keyboard.
|
||||
*
|
||||
* Click on the image to give it focus and press the letter keys
|
||||
* to create forms in time and space. Each key has a unique identifying
|
||||
* number called it's ASCII value. These numbers can be used to position
|
||||
* shapes in space.
|
||||
*/
|
||||
|
||||
int numChars = 26;
|
||||
int[] colors = new int[numChars];
|
||||
int keyIndex;
|
||||
float keyScale;
|
||||
int rectWidth;
|
||||
|
||||
|
||||
public void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
noStroke();
|
||||
background(0);
|
||||
keyScale = 200/numChars-1.0f;
|
||||
rectWidth = width/4;
|
||||
}
|
||||
|
||||
public void draw()
|
||||
{
|
||||
if(keyPressed) {
|
||||
if(key >= 'A' && key <= 'z') {
|
||||
if(key <= 'Z') {
|
||||
keyIndex = key-'A';
|
||||
} else {
|
||||
keyIndex = key-'a';
|
||||
}
|
||||
fill(millis()%255);
|
||||
float beginRect = rectWidth/2 + keyIndex*keyScale-rectWidth/2;
|
||||
rect(beginRect, 0.0f, rectWidth, height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "Keyboard" });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Keyboard.
|
||||
*
|
||||
* Click on the image to give it focus and press the letter keys
|
||||
* to create forms in time and space. Each key has a unique identifying
|
||||
* number called it's ASCII value. These numbers can be used to position
|
||||
* shapes in space.
|
||||
*/
|
||||
|
||||
int numChars = 26;
|
||||
color[] colors = new color[numChars];
|
||||
int keyIndex;
|
||||
float keyScale;
|
||||
int rectWidth;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
noStroke();
|
||||
background(0);
|
||||
keyScale = 200/numChars-1.0;
|
||||
rectWidth = width/4;
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
if(keyPressed) {
|
||||
if(key >= 'A' && key <= 'z') {
|
||||
if(key <= 'Z') {
|
||||
keyIndex = key-'A';
|
||||
} else {
|
||||
keyIndex = key-'a';
|
||||
}
|
||||
fill(millis()%255);
|
||||
float beginRect = rectWidth/2 + keyIndex*keyScale-rectWidth/2;
|
||||
rect(beginRect, 0.0, rectWidth, height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 2.2 KiB |
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* Keyboard Functions.
|
||||
* Modified from code by Martin.
|
||||
* Original 'Color Typewriter' concept by John Maeda.
|
||||
*
|
||||
* Click on the window to give it focus and press the letter keys to type colors.
|
||||
* The keyboard function keyPressed() is called whenever
|
||||
* a key is pressed. keyReleased() is another keyboard
|
||||
* 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 x = -letter_width; // X position of the letters
|
||||
int y = 0; // Y position of the letters
|
||||
|
||||
boolean newletter;
|
||||
|
||||
int numChars = 26; // There are 26 characters in the alphabet
|
||||
color[] colors = new color[numChars];
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
noStroke();
|
||||
colorMode(RGB, numChars);
|
||||
background(numChars/2);
|
||||
// Set a gray value for each key
|
||||
for(int i=0; i<numChars; i++) {
|
||||
colors[i] = color(i, i, i);
|
||||
}
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
if(newletter == true) {
|
||||
// Draw the "letter"
|
||||
int y_pos;
|
||||
if (letter_height == max_height) {
|
||||
y_pos = y;
|
||||
rect( x, y_pos, letter_width, letter_height );
|
||||
} else {
|
||||
y_pos = y + min_height;
|
||||
rect( x, y_pos, letter_width, letter_height );
|
||||
fill(numChars/2);
|
||||
rect( x, y_pos-min_height, letter_width, letter_height );
|
||||
}
|
||||
newletter = false;
|
||||
}
|
||||
}
|
||||
|
||||
void keyPressed()
|
||||
{
|
||||
// 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;
|
||||
fill(colors[key-'A']);
|
||||
} else {
|
||||
keyIndex = key-'a';
|
||||
letter_height = min_height;
|
||||
fill(colors[key-'a']);
|
||||
}
|
||||
} else {
|
||||
fill(0);
|
||||
letter_height = 10;
|
||||
}
|
||||
|
||||
newletter = true;
|
||||
|
||||
// Update the "letter" position
|
||||
x = ( x + letter_width );
|
||||
|
||||
// Wrap horizontally
|
||||
if (x > width - letter_width) {
|
||||
x = 0;
|
||||
y+= max_height;
|
||||
}
|
||||
|
||||
// Wrap vertically
|
||||
if( y > height - letter_height) {
|
||||
y = 0; // reset y to 0
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
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 KeyboardFunctions extends PApplet {
|
||||
|
||||
/**
|
||||
* Keyboard Functions.
|
||||
* Modified from code by Martin.
|
||||
* Original 'Color Typewriter' concept by John Maeda.
|
||||
*
|
||||
* Click on the window to give it focus and press the letter keys to type colors.
|
||||
* The keyboard function keyPressed() is called whenever
|
||||
* a key is pressed. keyReleased() is another keyboard
|
||||
* 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 x = -letter_width; // X position of the letters
|
||||
int y = 0; // Y position of the letters
|
||||
|
||||
boolean newletter;
|
||||
|
||||
int numChars = 26; // There are 26 characters in the alphabet
|
||||
int[] colors = new int[numChars];
|
||||
|
||||
public void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
noStroke();
|
||||
colorMode(RGB, numChars);
|
||||
background(numChars/2);
|
||||
// Set a gray value for each key
|
||||
for(int i=0; i<numChars; i++) {
|
||||
colors[i] = color(i, i, i);
|
||||
}
|
||||
}
|
||||
|
||||
public void draw()
|
||||
{
|
||||
if(newletter == true) {
|
||||
// Draw the "letter"
|
||||
int y_pos;
|
||||
if (letter_height == max_height) {
|
||||
y_pos = y;
|
||||
rect( x, y_pos, letter_width, letter_height );
|
||||
} else {
|
||||
y_pos = y + min_height;
|
||||
rect( x, y_pos, letter_width, letter_height );
|
||||
fill(numChars/2);
|
||||
rect( x, y_pos-min_height, letter_width, letter_height );
|
||||
}
|
||||
newletter = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void keyPressed()
|
||||
{
|
||||
// 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;
|
||||
fill(colors[key-'A']);
|
||||
} else {
|
||||
keyIndex = key-'a';
|
||||
letter_height = min_height;
|
||||
fill(colors[key-'a']);
|
||||
}
|
||||
} else {
|
||||
fill(0);
|
||||
letter_height = 10;
|
||||
}
|
||||
|
||||
newletter = true;
|
||||
|
||||
// Update the "letter" position
|
||||
x = ( x + letter_width );
|
||||
|
||||
// Wrap horizontally
|
||||
if (x > width - letter_width) {
|
||||
x = 0;
|
||||
y+= max_height;
|
||||
}
|
||||
|
||||
// Wrap vertically
|
||||
if( y > height - letter_height) {
|
||||
y = 0; // reset y to 0
|
||||
}
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "KeyboardFunctions" });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* Keyboard Functions.
|
||||
* Modified from code by Martin.
|
||||
* Original 'Color Typewriter' concept by John Maeda.
|
||||
*
|
||||
* Click on the window to give it focus and press the letter keys to type colors.
|
||||
* The keyboard function keyPressed() is called whenever
|
||||
* a key is pressed. keyReleased() is another keyboard
|
||||
* 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 x = -letter_width; // X position of the letters
|
||||
int y = 0; // Y position of the letters
|
||||
|
||||
boolean newletter;
|
||||
|
||||
int numChars = 26; // There are 26 characters in the alphabet
|
||||
color[] colors = new color[numChars];
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
noStroke();
|
||||
colorMode(RGB, numChars);
|
||||
background(numChars/2);
|
||||
// Set a gray value for each key
|
||||
for(int i=0; i<numChars; i++) {
|
||||
colors[i] = color(i, i, i);
|
||||
}
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
if(newletter == true) {
|
||||
// Draw the "letter"
|
||||
int y_pos;
|
||||
if (letter_height == max_height) {
|
||||
y_pos = y;
|
||||
rect( x, y_pos, letter_width, letter_height );
|
||||
} else {
|
||||
y_pos = y + min_height;
|
||||
rect( x, y_pos, letter_width, letter_height );
|
||||
fill(numChars/2);
|
||||
rect( x, y_pos-min_height, letter_width, letter_height );
|
||||
}
|
||||
newletter = false;
|
||||
}
|
||||
}
|
||||
|
||||
void keyPressed()
|
||||
{
|
||||
// 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;
|
||||
fill(colors[key-'A']);
|
||||
} else {
|
||||
keyIndex = key-'a';
|
||||
letter_height = min_height;
|
||||
fill(colors[key-'a']);
|
||||
}
|
||||
} else {
|
||||
fill(0);
|
||||
letter_height = 10;
|
||||
}
|
||||
|
||||
newletter = true;
|
||||
|
||||
// Update the "letter" position
|
||||
x = ( x + letter_width );
|
||||
|
||||
// Wrap horizontally
|
||||
if (x > width - letter_width) {
|
||||
x = 0;
|
||||
y+= max_height;
|
||||
}
|
||||
|
||||
// Wrap vertically
|
||||
if( y > height - letter_height) {
|
||||
y = 0; // reset y to 0
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 2.2 KiB |
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Milliseconds.
|
||||
*
|
||||
* A millisecond is 1/1000 of a second.
|
||||
* Processing keeps track of the number of milliseconds a program has run.
|
||||
* By modifying this number with the modulo(%) operator,
|
||||
* different patterns in time are created.
|
||||
*/
|
||||
|
||||
float scale;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
noStroke();
|
||||
scale = width/10;
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
for(int i=0; i<scale; i++) {
|
||||
colorMode(RGB, (i+1) * scale * 10);
|
||||
fill(millis()%((i+1) * scale * 10) );
|
||||
rect(i*scale, 0, scale, height);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
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 Milliseconds extends PApplet {
|
||||
|
||||
/**
|
||||
* Milliseconds.
|
||||
*
|
||||
* A millisecond is 1/1000 of a second.
|
||||
* Processing keeps track of the number of milliseconds a program has run.
|
||||
* By modifying this number with the modulo(%) operator,
|
||||
* different patterns in time are created.
|
||||
*/
|
||||
|
||||
float scale;
|
||||
|
||||
public void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
noStroke();
|
||||
scale = width/10;
|
||||
}
|
||||
|
||||
public void draw()
|
||||
{
|
||||
for(int i=0; i<scale; i++) {
|
||||
colorMode(RGB, (i+1) * scale * 10);
|
||||
fill(millis()%((i+1) * scale * 10) );
|
||||
rect(i*scale, 0, scale, height);
|
||||
}
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "Milliseconds" });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Milliseconds.
|
||||
*
|
||||
* A millisecond is 1/1000 of a second.
|
||||
* Processing keeps track of the number of milliseconds a program has run.
|
||||
* By modifying this number with the modulo(%) operator,
|
||||
* different patterns in time are created.
|
||||
*/
|
||||
|
||||
float scale;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
noStroke();
|
||||
scale = width/10;
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
for(int i=0; i<scale; i++) {
|
||||
colorMode(RGB, (i+1) * scale * 10);
|
||||
fill(millis()%((i+1) * scale * 10) );
|
||||
rect(i*scale, 0, scale, height);
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 2.2 KiB |
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Mouse 1D.
|
||||
*
|
||||
* Move the mouse left and right to shift the balance.
|
||||
* 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);
|
||||
noStroke();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
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 Mouse1D extends PApplet {
|
||||
|
||||
/**
|
||||
* Mouse 1D.
|
||||
*
|
||||
* Move the mouse left and right to shift the balance.
|
||||
* The "mouseX" variable is used to control both the
|
||||
* size and color of the rectangles.
|
||||
*/
|
||||
|
||||
int gx = 15;
|
||||
int gy = 35;
|
||||
float leftColor = 0.0f;
|
||||
float rightColor = 0.0f;
|
||||
|
||||
public void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
colorMode(RGB, 1.0f);
|
||||
noStroke();
|
||||
}
|
||||
|
||||
public void draw()
|
||||
{
|
||||
background(0.0f);
|
||||
update(mouseX);
|
||||
fill(0.0f, leftColor + 0.4f, leftColor + 0.6f);
|
||||
rect(width/4-gx, width/2-gx, gx*2, gx*2);
|
||||
fill(0.0f, rightColor + 0.2f, rightColor + 0.4f);
|
||||
rect(width/1.33f-gy, width/2-gy, gy*2, gy*2);
|
||||
}
|
||||
|
||||
public void update(int x)
|
||||
{
|
||||
leftColor = -0.002f * x/2 + 0.06f;
|
||||
rightColor = 0.002f * x/2 + 0.06f;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "Mouse1D" });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* Mouse 1D.
|
||||
*
|
||||
* Move the mouse left and right to shift the balance.
|
||||
* 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);
|
||||
noStroke();
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(0.0);
|
||||
update(mouseX);
|
||||
fill(0.0, leftColor + 0.4, leftColor + 0.6);
|
||||
rect(width/4-gx, width/2-gx, gx*2, gx*2);
|
||||
fill(0.0, rightColor + 0.2, rightColor + 0.4);
|
||||
rect(width/1.33-gy, width/2-gy, gy*2, gy*2);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 2.2 KiB |
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Mouse 2D.
|
||||
*
|
||||
* Moving the mouse changes the position and size of each box.
|
||||
*/
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
noStroke();
|
||||
rectMode(CENTER);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(51);
|
||||
fill(255, 204);
|
||||
rect(mouseX, height/2, mouseY/2+10, mouseY/2+10);
|
||||
fill(255, 204);
|
||||
int inverseX = width-mouseX;
|
||||
int inverseY = height-mouseY;
|
||||
rect(inverseX, height/2, (inverseY/2)+10, (inverseY/2)+10);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
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 Mouse2D extends PApplet {
|
||||
|
||||
/**
|
||||
* Mouse 2D.
|
||||
*
|
||||
* Moving the mouse changes the position and size of each box.
|
||||
*/
|
||||
|
||||
public void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
noStroke();
|
||||
colorMode(RGB, 255, 255, 255, 100);
|
||||
rectMode(CENTER);
|
||||
}
|
||||
|
||||
public void draw()
|
||||
{
|
||||
background(51);
|
||||
fill(255, 80);
|
||||
rect(mouseX, height/2, mouseY/2+10, mouseY/2+10);
|
||||
fill(255, 80);
|
||||
int inverseX = width-mouseX;
|
||||
int inverseY = height-mouseY;
|
||||
rect(inverseX, height/2, (inverseY/2)+10, (inverseY/2)+10);
|
||||
}
|
||||
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "Mouse2D" });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Mouse 2D.
|
||||
*
|
||||
* Moving the mouse changes the position and size of each box.
|
||||
*/
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
noStroke();
|
||||
colorMode(RGB, 255, 255, 255, 100);
|
||||
rectMode(CENTER);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(51);
|
||||
fill(255, 80);
|
||||
rect(mouseX, height/2, mouseY/2+10, mouseY/2+10);
|
||||
fill(255, 80);
|
||||
int inverseX = width-mouseX;
|
||||
int inverseY = height-mouseY;
|
||||
rect(inverseX, height/2, (inverseY/2)+10, (inverseY/2)+10);
|
||||
}
|
||||
|
||||
|
After Width: | Height: | Size: 2.2 KiB |
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* Mouse Functions.
|
||||
*
|
||||
* Click on the box and drag it across the screen.
|
||||
*/
|
||||
|
||||
float bx;
|
||||
float by;
|
||||
int bs = 20;
|
||||
boolean bover = false;
|
||||
boolean locked = false;
|
||||
float bdifx = 0.0;
|
||||
float bdify = 0.0;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
bx = width/2.0;
|
||||
by = height/2.0;
|
||||
rectMode(RADIUS);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(0);
|
||||
|
||||
// Test if the cursor is over the box
|
||||
if (mouseX > bx-bs && mouseX < bx+bs &&
|
||||
mouseY > by-bs && mouseY < by+bs) {
|
||||
bover = true;
|
||||
if(!locked) {
|
||||
stroke(255);
|
||||
fill(153);
|
||||
}
|
||||
} else {
|
||||
stroke(153);
|
||||
fill(153);
|
||||
bover = false;
|
||||
}
|
||||
|
||||
// Draw the box
|
||||
rect(bx, by, bs, bs);
|
||||
}
|
||||
|
||||
void mousePressed() {
|
||||
if(bover) {
|
||||
locked = true;
|
||||
fill(255, 255, 255);
|
||||
} else {
|
||||
locked = false;
|
||||
}
|
||||
bdifx = mouseX-bx;
|
||||
bdify = mouseY-by;
|
||||
|
||||
}
|
||||
|
||||
void mouseDragged() {
|
||||
if(locked) {
|
||||
bx = mouseX-bdifx;
|
||||
by = mouseY-bdify;
|
||||
}
|
||||
}
|
||||
|
||||
void mouseReleased() {
|
||||
locked = false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
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 MouseFunctions extends PApplet {
|
||||
|
||||
/**
|
||||
* Mouse Functions.
|
||||
*
|
||||
* Click on the box and drag it across the screen.
|
||||
*/
|
||||
|
||||
float bx;
|
||||
float by;
|
||||
int bs = 20;
|
||||
boolean bover = false;
|
||||
boolean locked = false;
|
||||
float bdifx = 0.0f;
|
||||
float bdify = 0.0f;
|
||||
|
||||
|
||||
public void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
bx = width/2.0f;
|
||||
by = height/2.0f;
|
||||
rectMode(CENTER_RADIUS);
|
||||
}
|
||||
|
||||
public void draw()
|
||||
{
|
||||
background(0);
|
||||
|
||||
// Test if the cursor is over the box
|
||||
if (mouseX > bx-bs && mouseX < bx+bs &&
|
||||
mouseY > by-bs && mouseY < by+bs) {
|
||||
bover = true;
|
||||
if(!locked) {
|
||||
stroke(255);
|
||||
fill(153);
|
||||
}
|
||||
} else {
|
||||
stroke(153);
|
||||
fill(153);
|
||||
bover = false;
|
||||
}
|
||||
|
||||
// Draw the box
|
||||
rect(bx, by, bs, bs);
|
||||
}
|
||||
|
||||
public void mousePressed() {
|
||||
if(bover) {
|
||||
locked = true;
|
||||
fill(255, 255, 255);
|
||||
} else {
|
||||
locked = false;
|
||||
}
|
||||
bdifx = mouseX-bx;
|
||||
bdify = mouseY-by;
|
||||
|
||||
}
|
||||
|
||||
public void mouseDragged() {
|
||||
if(locked) {
|
||||
bx = mouseX-bdifx;
|
||||
by = mouseY-bdify;
|
||||
}
|
||||
}
|
||||
|
||||
public void mouseReleased() {
|
||||
locked = false;
|
||||
}
|
||||
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "MouseFunctions" });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* Mouse Functions.
|
||||
*
|
||||
* Click on the box and drag it across the screen.
|
||||
*/
|
||||
|
||||
float bx;
|
||||
float by;
|
||||
int bs = 20;
|
||||
boolean bover = false;
|
||||
boolean locked = false;
|
||||
float bdifx = 0.0;
|
||||
float bdify = 0.0;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
bx = width/2.0;
|
||||
by = height/2.0;
|
||||
rectMode(CENTER_RADIUS);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(0);
|
||||
|
||||
// Test if the cursor is over the box
|
||||
if (mouseX > bx-bs && mouseX < bx+bs &&
|
||||
mouseY > by-bs && mouseY < by+bs) {
|
||||
bover = true;
|
||||
if(!locked) {
|
||||
stroke(255);
|
||||
fill(153);
|
||||
}
|
||||
} else {
|
||||
stroke(153);
|
||||
fill(153);
|
||||
bover = false;
|
||||
}
|
||||
|
||||
// Draw the box
|
||||
rect(bx, by, bs, bs);
|
||||
}
|
||||
|
||||
void mousePressed() {
|
||||
if(bover) {
|
||||
locked = true;
|
||||
fill(255, 255, 255);
|
||||
} else {
|
||||
locked = false;
|
||||
}
|
||||
bdifx = mouseX-bx;
|
||||
bdify = mouseY-by;
|
||||
|
||||
}
|
||||
|
||||
void mouseDragged() {
|
||||
if(locked) {
|
||||
bx = mouseX-bdifx;
|
||||
by = mouseY-bdify;
|
||||
}
|
||||
}
|
||||
|
||||
void mouseReleased() {
|
||||
locked = false;
|
||||
}
|
||||
|
||||
|
After Width: | Height: | Size: 2.2 KiB |
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Click.
|
||||
*
|
||||
* Move the mouse to position the shape.
|
||||
* Press the mouse button to invert the color.
|
||||
*/
|
||||
|
||||
|
||||
void setup() {
|
||||
size(200, 200);
|
||||
fill(126);
|
||||
background(102);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
if(mousePressed) {
|
||||
stroke(255);
|
||||
} else {
|
||||
stroke(0);
|
||||
}
|
||||
line(mouseX-66, mouseY, mouseX+66, mouseY);
|
||||
line(mouseX, mouseY-66, mouseX, mouseY+66);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
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 MousePress extends PApplet {
|
||||
|
||||
/**
|
||||
* Click.
|
||||
*
|
||||
* Move the mouse to position the shape.
|
||||
* Press the mouse button to invert the color.
|
||||
*/
|
||||
|
||||
|
||||
public void setup() {
|
||||
size(200, 200);
|
||||
fill(126);
|
||||
background(102);
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
if(mousePressed) {
|
||||
stroke(255);
|
||||
} else {
|
||||
stroke(0);
|
||||
}
|
||||
line(mouseX-66, mouseY, mouseX+66, mouseY);
|
||||
line(mouseX, mouseY-66, mouseX, mouseY+66);
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "MousePress" });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Click.
|
||||
*
|
||||
* Move the mouse to position the shape.
|
||||
* Press the mouse button to invert the color.
|
||||
*/
|
||||
|
||||
|
||||
void setup() {
|
||||
size(200, 200);
|
||||
fill(126);
|
||||
background(102);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
if(mousePressed) {
|
||||
stroke(255);
|
||||
} else {
|
||||
stroke(0);
|
||||
}
|
||||
line(mouseX-66, mouseY, mouseX+66, mouseY);
|
||||
line(mouseX, mouseY-66, mouseX, mouseY+66);
|
||||
}
|
||||
|
After Width: | Height: | Size: 2.2 KiB |
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* Mouse Signals.
|
||||
*
|
||||
* Move and click the mouse to generate signals.
|
||||
* The top row is the signal from "mouseX",
|
||||
* the middle row is the signal from "mouseY",
|
||||
* and the bottom row is the signal from "mousePressed".
|
||||
*/
|
||||
|
||||
int[] xvals;
|
||||
int[] yvals;
|
||||
int[] bvals;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
xvals = new int[width];
|
||||
yvals = new int[width];
|
||||
bvals = new int[width];
|
||||
}
|
||||
|
||||
int arrayindex = 0;
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(102);
|
||||
|
||||
for(int i=1; i<width; i++) {
|
||||
xvals[i-1] = xvals[i];
|
||||
yvals[i-1] = yvals[i];
|
||||
bvals[i-1] = bvals[i];
|
||||
}
|
||||
// Add the new values to the end of the array
|
||||
xvals[width-1] = mouseX;
|
||||
yvals[width-1] = mouseY;
|
||||
if(mousePressed) {
|
||||
bvals[width-1] = 0;
|
||||
} else {
|
||||
bvals[width-1] = 255;
|
||||
}
|
||||
|
||||
fill(255);
|
||||
noStroke();
|
||||
rect(0, height/3, width, height/3+1);
|
||||
|
||||
for(int i=1; i<width; i++) {
|
||||
stroke(255);
|
||||
point(i, xvals[i]/3);
|
||||
stroke(0);
|
||||
point(i, height/3+yvals[i]/3);
|
||||
stroke(255);
|
||||
line(i, 2*height/3+bvals[i]/3, i, (2*height/3+bvals[i-1]/3));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
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 MouseSignals extends PApplet {
|
||||
|
||||
/**
|
||||
* Mouse Signals.
|
||||
*
|
||||
* Move and click the mouse to generate signals.
|
||||
* The top row is the signal from "mouseX",
|
||||
* the middle row is the signal from "mouseY",
|
||||
* and the bottom row is the signal from "mousePressed".
|
||||
*/
|
||||
|
||||
int[] xvals;
|
||||
int[] yvals;
|
||||
int[] bvals;
|
||||
|
||||
public void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
xvals = new int[width];
|
||||
yvals = new int[width];
|
||||
bvals = new int[width];
|
||||
}
|
||||
|
||||
int arrayindex = 0;
|
||||
|
||||
public void draw()
|
||||
{
|
||||
background(102);
|
||||
|
||||
for(int i=1; i<width; i++) {
|
||||
xvals[i-1] = xvals[i];
|
||||
yvals[i-1] = yvals[i];
|
||||
bvals[i-1] = bvals[i];
|
||||
}
|
||||
// Add the new values to the end of the array
|
||||
xvals[width-1] = mouseX;
|
||||
yvals[width-1] = mouseY;
|
||||
if(mousePressed) {
|
||||
bvals[width-1] = 0;
|
||||
} else {
|
||||
bvals[width-1] = 255;
|
||||
}
|
||||
|
||||
fill(255);
|
||||
noStroke();
|
||||
rect(0, height/3, width, height/3+1);
|
||||
|
||||
for(int i=1; i<width; i++) {
|
||||
stroke(255);
|
||||
point(i, xvals[i]/3);
|
||||
stroke(0);
|
||||
point(i, height/3+yvals[i]/3);
|
||||
stroke(255);
|
||||
line(i, 2*height/3+bvals[i]/3, i, (2*height/3+bvals[i-1]/3));
|
||||
}
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "MouseSignals" });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* Mouse Signals.
|
||||
*
|
||||
* Move and click the mouse to generate signals.
|
||||
* The top row is the signal from "mouseX",
|
||||
* the middle row is the signal from "mouseY",
|
||||
* and the bottom row is the signal from "mousePressed".
|
||||
*/
|
||||
|
||||
int[] xvals;
|
||||
int[] yvals;
|
||||
int[] bvals;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
xvals = new int[width];
|
||||
yvals = new int[width];
|
||||
bvals = new int[width];
|
||||
}
|
||||
|
||||
int arrayindex = 0;
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(102);
|
||||
|
||||
for(int i=1; i<width; i++) {
|
||||
xvals[i-1] = xvals[i];
|
||||
yvals[i-1] = yvals[i];
|
||||
bvals[i-1] = bvals[i];
|
||||
}
|
||||
// Add the new values to the end of the array
|
||||
xvals[width-1] = mouseX;
|
||||
yvals[width-1] = mouseY;
|
||||
if(mousePressed) {
|
||||
bvals[width-1] = 0;
|
||||
} else {
|
||||
bvals[width-1] = 255;
|
||||
}
|
||||
|
||||
fill(255);
|
||||
noStroke();
|
||||
rect(0, height/3, width, height/3+1);
|
||||
|
||||
for(int i=1; i<width; i++) {
|
||||
stroke(255);
|
||||
point(i, xvals[i]/3);
|
||||
stroke(0);
|
||||
point(i, height/3+yvals[i]/3);
|
||||
stroke(255);
|
||||
line(i, 2*height/3+bvals[i]/3, i, (2*height/3+bvals[i-1]/3));
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 2.2 KiB |
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Storing Input.
|
||||
*
|
||||
* Move the mouse across the screen to change the position
|
||||
* of the circles. The positions of the mouse are recorded
|
||||
* 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;
|
||||
float mx[] = new float[num];
|
||||
float my[] = new float[num];
|
||||
|
||||
void setup() {
|
||||
size(200, 200);
|
||||
smooth();
|
||||
noStroke();
|
||||
fill(255, 153);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(51);
|
||||
|
||||
// Cycle through the array, using a different entry on each frame.
|
||||
// Using modulo (%) like this is faster than moving all the values over.
|
||||
int which = frameCount % num;
|
||||
mx[which] = mouseX;
|
||||
my[which] = mouseY;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
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 StoringInput extends PApplet {
|
||||
|
||||
/**
|
||||
* Storing Input.
|
||||
*
|
||||
* Move the mouse across the screen to change the position
|
||||
* of the circles. The positions of the mouse are recorded
|
||||
* 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.
|
||||
*/
|
||||
|
||||
int num = 60;
|
||||
float mx[] = new float[num];
|
||||
float my[] = new float[num];
|
||||
|
||||
public void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
smooth();
|
||||
noStroke();
|
||||
fill(255, 153);
|
||||
}
|
||||
|
||||
public void draw()
|
||||
{
|
||||
background(51);
|
||||
|
||||
// Reads throught the entire array
|
||||
// and shifts the values to the left
|
||||
for(int i=1; i<num; i++) {
|
||||
mx[i-1] = mx[i];
|
||||
my[i-1] = my[i];
|
||||
}
|
||||
// Add the new values to the end of the array
|
||||
mx[num-1] = mouseX;
|
||||
my[num-1] = mouseY;
|
||||
|
||||
for(int i=0; i<num; i++) {
|
||||
ellipse(mx[i], my[i], i/2, i/2);
|
||||
}
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "StoringInput" });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Storing Input.
|
||||
*
|
||||
* Move the mouse across the screen to change the position
|
||||
* of the circles. The positions of the mouse are recorded
|
||||
* 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.
|
||||
*/
|
||||
|
||||
int num = 60;
|
||||
float mx[] = new float[num];
|
||||
float my[] = new float[num];
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
smooth();
|
||||
noStroke();
|
||||
fill(255, 153);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(51);
|
||||
|
||||
// Reads throught the entire array
|
||||
// and shifts the values to the left
|
||||
for(int i=1; i<num; i++) {
|
||||
mx[i-1] = mx[i];
|
||||
my[i-1] = my[i];
|
||||
}
|
||||
// Add the new values to the end of the array
|
||||
mx[num-1] = mouseX;
|
||||
my[num-1] = mouseY;
|
||||
|
||||
for(int i=0; i<num; i++) {
|
||||
ellipse(mx[i], my[i], i/2, i/2);
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 2.2 KiB |