Re-adding Topics to SVN

This commit is contained in:
Casey Reas
2011-09-05 23:58:47 +00:00
parent 4fc6dcca86
commit 391c79c2b6
219 changed files with 31093 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
/**
* Animator.
*
* Click and drag to draw and start the program.
*
* A simple animation tool that displays a continuous cycle of
* twenty-four images. Each image is displayed for 30 milliseconds
* to create animation. While each image is displayed, its possible
* to draw directly into it by pressing the mouse and moving the cursor.
*
*/
int currentFrame = 0;
PImage[] frames = new PImage[24];
int lastTime = 0;
void setup()
{
size(640, 200);
strokeWeight(12);
smooth();
background(204);
for (int i = 0; i < frames.length; i++) {
frames[i] = get(); // Create a blank frame
}
}
void draw()
{
int currentTime = millis();
if (currentTime > lastTime+30) {
nextFrame();
lastTime = currentTime;
}
if (mousePressed == true) {
line(pmouseX, pmouseY, mouseX, mouseY);
}
}
void nextFrame()
{
frames[currentFrame] = get(); // Get the display window
currentFrame++; // Increment to next frame
if (currentFrame >= frames.length) {
currentFrame = 0;
}
image(frames[currentFrame], 0, 0);
}

View File

@@ -0,0 +1,17 @@
/**
* Continuous Lines.
*
* Click and drag the mouse to draw a line.
*/
void setup() {
size(640, 200);
background(102);
}
void draw() {
stroke(255);
if(mousePressed) {
line(mouseX, mouseY, pmouseX, pmouseY);
}
}

View File

@@ -0,0 +1,84 @@
/**
* Custom Tool.
*
* Move the cursor across the screen to draw.
* In addition to creating software tools to simulate pens and pencils,
* it is possible to create unique tools to draw with.
*/
int dots = 1000;
float[] dX = new float[dots];
float[] dY = new float[dots];
float l_0 = 0.0;
float h_0 = 0.0;
float legX = 0.0;
float legY = 0.0;
float thighX = 0.0;
float thighY = 0.0;
float l = 60.0; // Length of the 'leg'
float h = 90.0; // Height of the 'leg'
float nmx, nmy = 0.0;
float mx, my = 0.0;
int currentValue = 0;
int valdir = 1;
void setup()
{
size(640, 360);
noStroke();
smooth();
background(102);
}
void draw()
{
// Smooth the mouse
nmx = mouseX;
nmy = mouseY;
if((abs(mx - nmx) > 1.0) || (abs(my - nmy) > 1.0)) {
mx = mx - (mx-nmx)/20.0;
my = my - (my-nmy)/20.0;
// Set the drawing value
currentValue += 1* valdir;
if(currentValue > 255 || currentValue <= 0) {
valdir *= -1;
}
}
iKinematics();
kinematics();
pushMatrix();
translate(width/2, height/2);
stroke(currentValue);
line(thighX, thighY, legX, legY);
popMatrix();
stroke(255);
point(legX + width/2, legY + height/2);
}
void kinematics()
{
thighX = h*cos(h_0);
thighY = h*sin(h_0);
legX = thighX + l*cos(h_0 - l_0);
legY = thighY + l*sin(h_0 - l_0);
}
void iKinematics()
{
float tx = mx - width/2.0;
float ty = my - height/2.0;
float c2 = (tx*tx + ty*ty - h*h - l*l)/(2*h*l); //in degrees
float s2 = sqrt(abs(1 - c2*c2)); // the sign here determines the bend in the joint
l_0 = -atan2(s2, c2);
h_0 = atan2(ty, tx) - atan2(l*s2, h+l*c2);
}

View File

@@ -0,0 +1,34 @@
/**
* Patterns.
*
* Move the cursor over the image to draw with a software tool
* which responds to the speed of the mouse.
*/
void setup()
{
size(640, 360);
background(102);
smooth();
}
void draw()
{
// Call the variableEllipse() method and send it the
// parameters for the current mouse position
// and the previous mouse position
variableEllipse(mouseX, mouseY, pmouseX, pmouseY);
}
// The simple method variableEllipse() was created specifically
// for this program. It calculates the speed of the mouse
// and draws a small ellipse if the mouse is moving slowly
// and draws a large ellipse if the mouse is moving quickly
void variableEllipse(int x, int y, int px, int py)
{
float speed = abs(x-px) + abs(y-py);
stroke(speed);
ellipse(x, y, speed, speed);
}

View File

@@ -0,0 +1,33 @@
/**
* Pulses.
*
* Software drawing instruments can follow a rhythm or abide by rules independent
* of drawn gestures. This is a form of collaborative drawing in which the draftsperson
* controls some aspects of the image and the software controls others.
*/
int angle = 0;
void setup() {
size(640, 360);
background(102);
smooth();
noStroke();
fill(0, 102);
}
void draw() {
// Draw only when mouse is pressed
if (mousePressed == true) {
angle += 10;
float val = cos(radians(angle)) * 6.0;
for (int a = 0; a < 360; a += 75) {
float xoff = cos(radians(a)) * val;
float yoff = sin(radians(a)) * val;
fill(0);
ellipse(mouseX + xoff, mouseY + yoff, val, val);
}
fill(255);
ellipse(mouseX, mouseY, 2, 2);
}
}

View File

@@ -0,0 +1,91 @@
/**
* Scribble Plotter
* by Ira Greenberg.
*
* Using 2-dimensional arrays, record end points
* and replot scribbles between points.
*/
int SCRIBBLE = 0;
int HATCHING = 1;
void setup(){
size(640, 360);
background(0);
// Create arrays to hold x, y coords
float[]x = new float[4];
float[]y = new float[4];
// create a convenient 2-dimensional
// array to hold x, y arrays
float[][]xy = {x, y};
// Record points
// X positions
xy[0][0] = 125;
xy[0][1] = 475;
xy[0][2] = 475;
xy[0][3] = 125;
// Y positions
xy[1][0] = 100;
xy[1][1] = 100;
xy[1][2] = 260;
xy[1][3] = 260;
// Call plotting function
makeRect(xy);
}
void makeRect(float[][]pts){
stroke(255);
smooth();
// Scribble variables, that get passed as arguments to the scribble function
int steps = 100;
float scribVal = 3.0;
for (int i = 0; i < pts[0].length; i++){
// Plots vertices
strokeWeight(5);
point(pts[0][i], pts[1][i]);
// Call scribble function
strokeWeight(.5);
if (i > 0){
scribble(pts[0][i], pts[1][i], pts[0][i-1], pts[1][i-1], steps, scribVal, SCRIBBLE);
}
if (i == pts[0].length-1){
// Show some hatching between last 2 points
scribble(pts[0][i], pts[1][i], pts[0][0], pts[1][0], steps, scribVal*2, HATCHING);
}
}
}
/*
Scribble function plots lines between end points,
determined by steps and scribVal arguments.
two styles are available: SCRIBBLE and HATCHING, which
are interestingly only dependent on parentheses
placement in the line() function calls.
*/
void scribble(float x1, float y1, float x2, float y2, int steps, float scribVal, int style){
float xStep = (x2-x1)/steps;
float yStep = (y2-y1)/steps;
for (int i = 0; i < steps; i++){
if(style == SCRIBBLE){
if (i < steps-1){
line(x1, y1, x1+=xStep+random(-scribVal, scribVal), y1+=yStep+random(-scribVal, scribVal));
}
else {
// extra line needed to attach line back to point- not necessary in HATCHING style
line(x1, y1, x2, y2);
}
}
else if (style == HATCHING){
line(x1, y1, (x1+=xStep)+random(-scribVal, scribVal), (y1+=yStep)+random(-scribVal, scribVal));
}
}
}