mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
Examples updates to 640 x 360 pixels
This commit is contained in:
@@ -6,13 +6,18 @@
|
||||
* the last point. The middle parameters set the control points
|
||||
* that define the shape of the curve.
|
||||
*/
|
||||
|
||||
size(640, 360);
|
||||
background(0);
|
||||
stroke(255);
|
||||
noFill();
|
||||
smooth();
|
||||
|
||||
for(int i = 0; i < 200; i += 20) {
|
||||
bezier(180-(i/2.0), 40+i, 410, 20, 440, 300, 240-(i/16.0), 300+(i/8.0));
|
||||
void setup() {
|
||||
size(640, 360);
|
||||
stroke(255);
|
||||
noFill();
|
||||
smooth();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
for (int i = 0; i < 200; i += 20) {
|
||||
bezier(mouseX-(i/2.0), 40+i, 410, 20, 440, 300, 240-(i/16.0), 300+(i/8.0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,11 +13,6 @@ int x;
|
||||
int y;
|
||||
float outerRad;
|
||||
float innerRad;
|
||||
float px = 0;
|
||||
float py = 0;
|
||||
float angle = 0;
|
||||
float pts = 36;
|
||||
float rot = 360.0/pts;
|
||||
|
||||
void setup() {
|
||||
size(640, 360);
|
||||
@@ -30,10 +25,16 @@ void setup() {
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(204);
|
||||
|
||||
int pts = int(map(mouseX, 0, width, 6, 60));
|
||||
float rot = 180.0/pts;
|
||||
float angle = 0;
|
||||
|
||||
beginShape(TRIANGLE_STRIP);
|
||||
for (int i = 0; i < pts; i++) {
|
||||
px = x + cos(radians(angle)) * outerRad;
|
||||
py = y + sin(radians(angle)) * outerRad;
|
||||
for (int i = 0; i <= pts; i++) {
|
||||
float px = x + cos(radians(angle)) * outerRad;
|
||||
float py = y + sin(radians(angle)) * outerRad;
|
||||
angle += rot;
|
||||
vertex(px, py);
|
||||
px = x + cos(radians(angle)) * innerRad;
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
*
|
||||
* 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;
|
||||
|
||||
@@ -30,7 +30,7 @@ void setup()
|
||||
background(numChars/2);
|
||||
// Set a gray value for each key
|
||||
for(int i=0; i<numChars; i++) {
|
||||
colors[i] = color(i, i, i);
|
||||
colors[i] = color(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,12 +6,11 @@
|
||||
|
||||
float bx;
|
||||
float by;
|
||||
int bs = 75;
|
||||
boolean bover = false;
|
||||
int boxSize = 75;
|
||||
boolean overBox = false;
|
||||
boolean locked = false;
|
||||
float bdifx = 0.0;
|
||||
float bdify = 0.0;
|
||||
|
||||
float xOffset = 0.0;
|
||||
float yOffset = 0.0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
@@ -26,9 +25,9 @@ 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 (mouseX > bx-boxSize && mouseX < bx+boxSize &&
|
||||
mouseY > by-boxSize && mouseY < by+boxSize) {
|
||||
overBox = true;
|
||||
if(!locked) {
|
||||
stroke(255);
|
||||
fill(153);
|
||||
@@ -36,29 +35,29 @@ void draw()
|
||||
} else {
|
||||
stroke(153);
|
||||
fill(153);
|
||||
bover = false;
|
||||
overBox = false;
|
||||
}
|
||||
|
||||
// Draw the box
|
||||
rect(bx, by, bs, bs);
|
||||
rect(bx, by, boxSize, boxSize);
|
||||
}
|
||||
|
||||
void mousePressed() {
|
||||
if(bover) {
|
||||
if(overBox) {
|
||||
locked = true;
|
||||
fill(255, 255, 255);
|
||||
} else {
|
||||
locked = false;
|
||||
}
|
||||
bdifx = mouseX-bx;
|
||||
bdify = mouseY-by;
|
||||
xOffset = mouseX-bx;
|
||||
yOffset = mouseY-by;
|
||||
|
||||
}
|
||||
|
||||
void mouseDragged() {
|
||||
if(locked) {
|
||||
bx = mouseX-bdifx;
|
||||
by = mouseY-bdify;
|
||||
bx = mouseX-xOffset;
|
||||
by = mouseY-yOffset;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ void setup() {
|
||||
}
|
||||
|
||||
void draw() {
|
||||
if(mousePressed) {
|
||||
if (mousePressed) {
|
||||
stroke(255);
|
||||
} else {
|
||||
stroke(0);
|
||||
|
||||
@@ -6,18 +6,16 @@
|
||||
* to the cursor.
|
||||
*/
|
||||
|
||||
Eye e1, e2, e3, e4, e5;
|
||||
Eye e1, e2, e3;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
size(640, 360);
|
||||
smooth();
|
||||
noStroke();
|
||||
e1 = new Eye( 50, 16, 80);
|
||||
e2 = new Eye( 64, 85, 40);
|
||||
e3 = new Eye( 90, 200, 120);
|
||||
e4 = new Eye(150, 44, 40);
|
||||
e5 = new Eye(175, 120, 80);
|
||||
e1 = new Eye( 190, 16, 120);
|
||||
e2 = new Eye( 164, 185, 80);
|
||||
e3 = new Eye( 390, 200, 220);
|
||||
}
|
||||
|
||||
void draw()
|
||||
@@ -27,35 +25,31 @@ void draw()
|
||||
e1.update(mouseX, mouseY);
|
||||
e2.update(mouseX, mouseY);
|
||||
e3.update(mouseX, mouseY);
|
||||
e4.update(mouseX, mouseY);
|
||||
e5.update(mouseX, mouseY);
|
||||
|
||||
e1.display();
|
||||
e2.display();
|
||||
e3.display();
|
||||
e4.display();
|
||||
e5.display();
|
||||
}
|
||||
|
||||
class Eye
|
||||
{
|
||||
int ex, ey;
|
||||
int x, y;
|
||||
int size;
|
||||
float angle = 0.0;
|
||||
|
||||
Eye(int x, int y, int s) {
|
||||
ex = x;
|
||||
ey = y;
|
||||
size = s;
|
||||
Eye(int tx, int ty, int ts) {
|
||||
x = tx;
|
||||
y = ty;
|
||||
size = ts;
|
||||
}
|
||||
|
||||
void update(int mx, int my) {
|
||||
angle = atan2(my-ey, mx-ex);
|
||||
angle = atan2(my-y, mx-x);
|
||||
}
|
||||
|
||||
void display() {
|
||||
pushMatrix();
|
||||
translate(ex, ey);
|
||||
translate(x, y);
|
||||
fill(255);
|
||||
ellipse(0, 0, size, size);
|
||||
rotate(angle);
|
||||
|
||||
@@ -5,18 +5,21 @@
|
||||
* speed and direction of the moving shapes.
|
||||
*/
|
||||
|
||||
float xpos1;
|
||||
float xpos2;
|
||||
float xpos3;
|
||||
float xpos4;
|
||||
int thin = 8;
|
||||
int thick = 36;
|
||||
float xpos1 = 134.0;
|
||||
float xpos2 = 44.0;
|
||||
float xpos3 = 58.0;
|
||||
float xpos4 = 120.0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
size(640, 360);
|
||||
noStroke();
|
||||
frameRate(60);
|
||||
xpos1 = width/2;
|
||||
xpos2 = width/2;
|
||||
xpos3 = width/2;
|
||||
xpos4 = width/2;
|
||||
}
|
||||
|
||||
void draw()
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
float max_distance;
|
||||
|
||||
void setup() {
|
||||
size(200, 200);
|
||||
size(640, 360);
|
||||
smooth();
|
||||
noStroke();
|
||||
max_distance = dist(0, 0, width, height);
|
||||
@@ -17,7 +17,7 @@ void setup() {
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(51);
|
||||
background(0);
|
||||
|
||||
for(int i = 0; i <= width; i += 20) {
|
||||
for(int j = 0; j <= height; j += 20) {
|
||||
|
||||
@@ -6,15 +6,21 @@
|
||||
* to create an irregular sawtooth line.
|
||||
*/
|
||||
|
||||
size(200, 200);
|
||||
background(0);
|
||||
int totalPts = 300;
|
||||
float steps = totalPts + 1;
|
||||
stroke(255);
|
||||
float rand = 0;
|
||||
|
||||
void setup() {
|
||||
size(640, 360);
|
||||
stroke(255);
|
||||
frameRate(1);
|
||||
}
|
||||
|
||||
for (int i = 1; i < steps; i++){
|
||||
point( (width/steps) * i, (height/2) + random(-rand, rand) );
|
||||
rand += random(-5, 5);
|
||||
void draw() {
|
||||
background(0);
|
||||
float rand = 0;
|
||||
for (int i = 1; i < steps; i++) {
|
||||
point( (width/steps) * i, (height/2) + random(-rand, rand) );
|
||||
rand += random(-5, 5);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,7 @@
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
size(200,200);
|
||||
frameRate(30);
|
||||
size(640, 360);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
|
||||
@@ -11,7 +11,7 @@ boolean direction;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
size(640, 360);
|
||||
colorMode(RGB, width);
|
||||
a = 0;
|
||||
b = width;
|
||||
|
||||
@@ -8,9 +8,8 @@ float xoff = 0.0;
|
||||
float xincrement = 0.01;
|
||||
|
||||
void setup() {
|
||||
size(200,200);
|
||||
size(640, 360);
|
||||
background(0);
|
||||
frameRate(30);
|
||||
smooth();
|
||||
noStroke();
|
||||
}
|
||||
@@ -31,7 +30,7 @@ void draw()
|
||||
|
||||
// Draw the ellipse at the value produced by perlin noise
|
||||
fill(200);
|
||||
ellipse(n,height/2,16,16);
|
||||
ellipse(n,height/2, 64, 64);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,19 +8,16 @@
|
||||
float increment = 0.02;
|
||||
|
||||
void setup() {
|
||||
size(200,200);
|
||||
noLoop();
|
||||
size(640, 360);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
|
||||
// Optional: adjust noise detail here
|
||||
// noiseDetail(8,0.65f);
|
||||
|
||||
loadPixels();
|
||||
|
||||
float xoff = 0.0; // Start xoff at 0
|
||||
float detail = map(mouseX, 0, width, 0.1, 0.6);
|
||||
noiseDetail(8, detail);
|
||||
|
||||
// For every x,y coordinate in a 2D space, calculate a noise value and produce a brightness value
|
||||
for (int x = 0; x < width; x++) {
|
||||
@@ -30,7 +27,7 @@ void draw() {
|
||||
yoff += increment; // Increment yoff
|
||||
|
||||
// Calculate noise and scale by 255
|
||||
float bright = noise(xoff,yoff)*255;
|
||||
float bright = noise(xoff, yoff) * 255;
|
||||
|
||||
// Try using this line instead
|
||||
//float bright = random(0,255);
|
||||
|
||||
@@ -12,12 +12,11 @@ float zoff = 0.0;
|
||||
float zincrement = 0.02;
|
||||
|
||||
void setup() {
|
||||
size(200,200);
|
||||
size(640, 360);
|
||||
frameRate(30);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
|
||||
// Optional: adjust noise detail here
|
||||
// noiseDetail(8,0.65f);
|
||||
|
||||
@@ -12,8 +12,7 @@ float yoff = 0.0f; // 2nd dimension of perlin noise
|
||||
float[] yvalues; // Using an array to store height values for the wave (not entirely necessary)
|
||||
|
||||
void setup() {
|
||||
size(200,200);
|
||||
frameRate(30);
|
||||
size(640, 360);
|
||||
colorMode(RGB,255,255,255,100);
|
||||
smooth();
|
||||
w = width+16;
|
||||
@@ -24,7 +23,6 @@ void draw() {
|
||||
background(0);
|
||||
calcWave();
|
||||
renderWave();
|
||||
|
||||
}
|
||||
|
||||
void calcWave() {
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
// Logical OR: ||
|
||||
// Assignment: = += -= *= /= %=
|
||||
|
||||
size(200, 200);
|
||||
size(640, 360);
|
||||
background(51);
|
||||
noFill();
|
||||
stroke(51);
|
||||
@@ -32,25 +32,25 @@ stroke(204);
|
||||
for(int i=0; i< width-20; i+= 4) {
|
||||
// The 30 is added to 70 and then evaluated
|
||||
// if it is greater than the current value of "i"
|
||||
// For clarity, write as "if(i > (30 + 70)) {"
|
||||
if(i > 30 + 70) {
|
||||
// For clarity, write as "if (i > (30 + 70)) {"
|
||||
if (i > 30 + 70) {
|
||||
line(i, 0, i, 50);
|
||||
}
|
||||
}
|
||||
|
||||
stroke(255);
|
||||
// The 2 is multiplied by the 8 and the result is added to the 5
|
||||
// The 2 is multiplied by the 8 and the result is added to the 4
|
||||
// For clarity, write as "rect(5 + (2 * 8), 0, 90, 20);"
|
||||
rect(4 + 2 * 8, 52, 90, 48);
|
||||
rect((4 + 2) * 8, 100, 90, 49);
|
||||
rect(4 + 2 * 8, 52, 290, 48);
|
||||
rect((4 + 2) * 8, 100, 290, 49);
|
||||
|
||||
stroke(153);
|
||||
for(int i=0; i< width; i+= 2) {
|
||||
for (int i = 0; i < width; i+= 2) {
|
||||
// The relational statements are evaluated
|
||||
// first, and then the logical AND statements and
|
||||
// finally the logical OR. For clarity, write as:
|
||||
// "if(((i > 10) && (i < 50)) || ((i > 80) && (i < 160))) {"
|
||||
if(i > 20 && i < 50 || i > 100 && i < width-20) {
|
||||
// "if(((i > 20) && (i < 50)) || ((i > 100) && (i < width-20))) {"
|
||||
if (i > 20 && i < 50 || i > 100 && i < width-20) {
|
||||
line(i, 151, i, height-1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,19 +15,20 @@ float theta_vel;
|
||||
float theta_acc;
|
||||
|
||||
void setup() {
|
||||
size(200, 200);
|
||||
frameRate(30);
|
||||
size(640, 360);
|
||||
smooth();
|
||||
|
||||
// Initialize all values
|
||||
r = 50;
|
||||
r = height * 0.45;
|
||||
theta = 0;
|
||||
theta_vel = 0;
|
||||
theta_acc = 0.0001;
|
||||
}
|
||||
|
||||
void draw() {
|
||||
|
||||
background(0);
|
||||
|
||||
// Translate the origin point to the center of the screen
|
||||
translate(width/2, height/2);
|
||||
|
||||
@@ -39,7 +40,7 @@ void draw() {
|
||||
ellipseMode(CENTER);
|
||||
noStroke();
|
||||
fill(200);
|
||||
ellipse(x, y, 16, 16);
|
||||
ellipse(x, y, 32, 32);
|
||||
|
||||
// Apply acceleration and velocity to angle (r remains static in this example)
|
||||
theta_vel += theta_acc;
|
||||
|
||||
@@ -4,16 +4,21 @@
|
||||
* Random numbers create the basis of this image.
|
||||
* Each time the program is loaded the result is different.
|
||||
*/
|
||||
|
||||
size(200, 200);
|
||||
smooth();
|
||||
background(0);
|
||||
strokeWeight(10);
|
||||
|
||||
for(int i = 0; i < width; i++) {
|
||||
float r = random(255);
|
||||
float x = random(0, width);
|
||||
stroke(r, 100);
|
||||
line(i, 0, x, height);
|
||||
void setup() {
|
||||
size(640, 360);
|
||||
smooth();
|
||||
background(0);
|
||||
strokeWeight(20);
|
||||
frameRate(2);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
for (int i = 0; i < width; i++) {
|
||||
float r = random(255);
|
||||
float x = random(0, width);
|
||||
stroke(r, 100);
|
||||
line(i, 0, x, height);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,16 +4,12 @@
|
||||
* Smoothly scaling size with the sin() function.
|
||||
*/
|
||||
|
||||
float spin = 0.0;
|
||||
float diameter = 84.0;
|
||||
float angle;
|
||||
|
||||
float angle_rot;
|
||||
int rad_points = 90;
|
||||
float angle = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
size(640, 360);
|
||||
noStroke();
|
||||
smooth();
|
||||
}
|
||||
@@ -22,25 +18,24 @@ void draw()
|
||||
{
|
||||
background(153);
|
||||
|
||||
translate(130, 65);
|
||||
translate(width * 0.3, height * 0.5);
|
||||
|
||||
fill(255);
|
||||
ellipse(0, 0, 16, 16);
|
||||
|
||||
angle_rot = 0;
|
||||
float angleOffset = 0;
|
||||
fill(51);
|
||||
|
||||
for(int i=0; i<5; i++) {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
pushMatrix();
|
||||
rotate(angle_rot + -45);
|
||||
rotate(angleOffset + -45);
|
||||
ellipse(-116, 0, diameter, diameter);
|
||||
popMatrix();
|
||||
angle_rot += PI*2/5;
|
||||
angleOffset += TWO_PI/5;
|
||||
}
|
||||
|
||||
diameter = 34 * sin(angle) + 168;
|
||||
|
||||
angle += 0.02;
|
||||
if (angle > TWO_PI) { angle = 0; }
|
||||
}
|
||||
|
||||
|
||||
@@ -1,59 +1,50 @@
|
||||
/**
|
||||
* Sine Cosine.
|
||||
* Sanglene Cosanglene.
|
||||
*
|
||||
* Linear movement with sin() and cos().
|
||||
* Numbers between 0 and PI*2 (TWO_PI which is roughly 6.28)
|
||||
* are put into these functions and numbers between -1 and 1 are
|
||||
* returned. These values are then scaled to produce larger movements.
|
||||
* Langlenear movement wangleth sanglen() and cos().
|
||||
* Numbers between 0 and PI*2 (TWO_PI whanglech angles roughly 6.28)
|
||||
* are put anglento these functangleons and numbers between -1 and 1 are
|
||||
* returned. These values are then scalaraled to produce larger movements.
|
||||
*/
|
||||
|
||||
int i = 45;
|
||||
int j = 225;
|
||||
float pos1 = 0;
|
||||
float pos2 = 0;
|
||||
float pos3 = 0;
|
||||
float pos4 = 0;
|
||||
int sc = 40;
|
||||
float x1, x2, y1, y2;
|
||||
float angle1, angle2;
|
||||
float scalar = 70;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
size(640, 360);
|
||||
noStroke();
|
||||
smooth();
|
||||
rectMode(CENTER);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(0);
|
||||
|
||||
float ang1 = radians(angle1);
|
||||
float ang2 = radians(angle2);
|
||||
|
||||
x1 = width/2 + (scalar * cos(ang1));
|
||||
x2 = width/2 + (scalar * cos(ang2));
|
||||
|
||||
y1 = height/2 + (scalar * sin(ang1));
|
||||
y2 = height/2 + (scalar * sin(ang2));
|
||||
|
||||
fill(51);
|
||||
rect(60, 60, 80, 80);
|
||||
rect(width*0.5, height*0.5, 140, 140);
|
||||
|
||||
fill(255);
|
||||
ellipse(pos1, 36, 32, 32);
|
||||
|
||||
ellipse(x1, height*0.5 - 120, scalar, scalar);
|
||||
ellipse(x2, height*0.5 + 120, scalar, scalar);
|
||||
|
||||
fill(153);
|
||||
ellipse(36, pos2, 32, 32);
|
||||
ellipse(width*0.5 - 120, y1, scalar, scalar);
|
||||
ellipse(width*0.5 + 120, y2, scalar, scalar);
|
||||
|
||||
fill(255);
|
||||
ellipse(pos3, 164, 32, 32);
|
||||
|
||||
fill(153);
|
||||
ellipse(164, pos4, 32, 32);
|
||||
|
||||
i += 3;
|
||||
j -= 3;
|
||||
|
||||
if(i > 405) {
|
||||
i = 45;
|
||||
j = 225;
|
||||
}
|
||||
|
||||
float ang1 = radians(i); // convert degrees to radians
|
||||
float ang2 = radians(j); // convert degrees to radians
|
||||
pos1 = width/2 + (sc * cos(ang1));
|
||||
pos2 = width/2 + (sc * sin(ang1));
|
||||
pos3 = width/2 + (sc * cos(ang2));
|
||||
pos4 = width/2 + (sc * sin(ang2));
|
||||
angle1 += 2;
|
||||
angle2 += 3;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* Render a simple sine wave.
|
||||
*/
|
||||
|
||||
int xspacing = 8; // How far apart should each horizontal location be spaced
|
||||
int xspacing = 16; // How far apart should each horizontal location be spaced
|
||||
int w; // Width of entire wave
|
||||
|
||||
float theta = 0.0; // Start angle at 0
|
||||
@@ -15,9 +15,7 @@ float dx; // Value for incrementing X, a function of period and xspacing
|
||||
float[] yvalues; // Using an array to store height values for the wave
|
||||
|
||||
void setup() {
|
||||
size(200,200);
|
||||
frameRate(30);
|
||||
colorMode(RGB,255,255,255,100);
|
||||
size(640, 360);
|
||||
smooth();
|
||||
w = width+16;
|
||||
dx = (TWO_PI / period) * xspacing;
|
||||
@@ -28,7 +26,6 @@ void draw() {
|
||||
background(0);
|
||||
calcWave();
|
||||
renderWave();
|
||||
|
||||
}
|
||||
|
||||
void calcWave() {
|
||||
@@ -44,12 +41,11 @@ void calcWave() {
|
||||
}
|
||||
|
||||
void renderWave() {
|
||||
noStroke();
|
||||
fill(255);
|
||||
// A simple way to draw the wave with an ellipse at each location
|
||||
for (int x = 0; x < yvalues.length; x++) {
|
||||
noStroke();
|
||||
fill(255,50);
|
||||
ellipseMode(CENTER);
|
||||
ellipse(x*xspacing,width/2+yvalues[x],16,16);
|
||||
ellipse(x*xspacing, height/2+yvalues[x], 16, 16);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,10 +10,10 @@ EggRing er1, er2;
|
||||
|
||||
|
||||
void setup() {
|
||||
size(200, 200);
|
||||
size(640, 360);
|
||||
smooth();
|
||||
er1 = new EggRing(66, 132, 0.1, 66);
|
||||
er2 = new EggRing(132, 180, 0.05, 132);
|
||||
er1 = new EggRing(width*0.45, height*0.5, 0.1, 120);
|
||||
er2 = new EggRing(width*0.65, height*0.8, 0.05, 180);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ class Egg {
|
||||
float scalar; // Height of the egg
|
||||
|
||||
// Constructor
|
||||
Egg(int xpos, int ypos, float t, float s) {
|
||||
Egg(float xpos, float ypos, float t, float s) {
|
||||
x = xpos;
|
||||
y = ypos;
|
||||
tilt = t;
|
||||
@@ -33,4 +33,4 @@ class Egg {
|
||||
endShape();
|
||||
popMatrix();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ class EggRing {
|
||||
Egg ovoid;
|
||||
Ring circle = new Ring();
|
||||
|
||||
EggRing(int x, int y, float t, float sp) {
|
||||
EggRing(float x, float y, float t, float sp) {
|
||||
ovoid = new Egg(x, y, t, sp);
|
||||
circle.start(x, y - sp/2);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
class Ring {
|
||||
|
||||
float x, y; // X-coordinate, y-coordinate
|
||||
float diameter; // Diameter of the ring
|
||||
boolean on = false; // Turns the display on and off
|
||||
|
||||
void start(float xpos, float ypos) {
|
||||
x = xpos;
|
||||
y = ypos;
|
||||
on = true;
|
||||
diameter = 1;
|
||||
}
|
||||
|
||||
void grow() {
|
||||
if (on == true) {
|
||||
diameter += 0.5;
|
||||
@@ -16,6 +19,7 @@ class Ring {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void display() {
|
||||
if (on == true) {
|
||||
noFill();
|
||||
|
||||
@@ -12,10 +12,10 @@ SpinArm arm;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
size(640, 360);
|
||||
smooth();
|
||||
arm = new SpinArm(width/2, height/2, 0.01);
|
||||
spots = new SpinSpots(width/2, height/2, -0.02, 33.0);
|
||||
spots = new SpinSpots(width/2, height/2, -0.02, 90.0);
|
||||
}
|
||||
|
||||
void draw()
|
||||
@@ -53,7 +53,7 @@ class SpinArm extends Spin
|
||||
translate(x, y);
|
||||
angle += speed;
|
||||
rotate(angle);
|
||||
line(0, 0, 66, 0);
|
||||
line(0, 0, 165, 0);
|
||||
popMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,16 +8,17 @@
|
||||
*/
|
||||
|
||||
Spot sp1, sp2;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
size(640, 360);
|
||||
background(204);
|
||||
smooth();
|
||||
noLoop();
|
||||
// Run the constructor without parameters
|
||||
sp1 = new Spot();
|
||||
// Run the constructor with three parameters
|
||||
sp2 = new Spot(122, 100, 40);
|
||||
sp2 = new Spot(width*0.5, height*0.5, 120);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
@@ -27,13 +28,15 @@ void draw() {
|
||||
|
||||
class Spot {
|
||||
float x, y, radius;
|
||||
|
||||
// First version of the Spot constructor;
|
||||
// the fields are assigned default values
|
||||
Spot() {
|
||||
x = 66;
|
||||
y = 100;
|
||||
radius = 16;
|
||||
radius = 40;
|
||||
x = width*0.25;
|
||||
y = height*0.5;
|
||||
}
|
||||
|
||||
// Second version of the Spot constructor;
|
||||
// the fields are assigned with parameters
|
||||
Spot(float xpos, float ypos, float r) {
|
||||
@@ -44,4 +47,5 @@ class Spot {
|
||||
void display() {
|
||||
ellipse(x, y, radius*2, radius*2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,13 +10,13 @@ MRect r1, r2, r3, r4;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
size(640, 360);
|
||||
fill(255, 204);
|
||||
noStroke();
|
||||
r1 = new MRect(1, 134.0, 0.532, 0.083*height, 10.0, 60.0);
|
||||
r2 = new MRect(2, 44.0, 0.166, 0.332*height, 5.0, 50.0);
|
||||
r3 = new MRect(2, 58.0, 0.332, 0.4482*height, 10.0, 35.0);
|
||||
r4 = new MRect(1, 120.0, 0.0498, 0.913*height, 15.0, 60.0);
|
||||
r1 = new MRect(1, 134.0, 0.532, 0.1*height, 10.0, 60.0);
|
||||
r2 = new MRect(2, 44.0, 0.166, 0.3*height, 5.0, 50.0);
|
||||
r3 = new MRect(2, 58.0, 0.332, 0.4*height, 10.0, 35.0);
|
||||
r4 = new MRect(1, 120.0, 0.0498, 0.9*height, 15.0, 60.0);
|
||||
}
|
||||
|
||||
void draw()
|
||||
|
||||
@@ -11,8 +11,9 @@
|
||||
PGraphics pg;
|
||||
|
||||
void setup() {
|
||||
size(200, 200);
|
||||
pg = createGraphics(80, 80, P2D);
|
||||
size(640, 360);
|
||||
smooth();
|
||||
pg = createGraphics(400, 200, P2D);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
@@ -23,11 +24,12 @@ void draw() {
|
||||
ellipse(mouseX, mouseY, 60, 60);
|
||||
|
||||
pg.beginDraw();
|
||||
pg.background(102);
|
||||
pg.smooth();
|
||||
pg.background(51);
|
||||
pg.noFill();
|
||||
pg.stroke(255);
|
||||
pg.ellipse(mouseX-60, mouseY-60, 60, 60);
|
||||
pg.ellipse(mouseX-120, mouseY-60, 60, 60);
|
||||
pg.endDraw();
|
||||
|
||||
image(pg, 60, 60);
|
||||
image(pg, 120, 60);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
size(640, 360);
|
||||
background(51);
|
||||
noStroke();
|
||||
smooth();
|
||||
@@ -17,12 +17,12 @@ void setup()
|
||||
|
||||
void draw()
|
||||
{
|
||||
drawTarget(68, 34, 200, 10);
|
||||
drawTarget(152, 16, 100, 3);
|
||||
drawTarget(100, 144, 80, 5);
|
||||
drawTarget(width*0.25, height*0.4, 200, 4);
|
||||
drawTarget(width*0.5, height*0.5, 300, 10);
|
||||
drawTarget(width*0.75, height*0.3, 120, 6);
|
||||
}
|
||||
|
||||
void drawTarget(int xloc, int yloc, int size, int num)
|
||||
void drawTarget(float xloc, float yloc, int size, int num)
|
||||
{
|
||||
float grayvalues = 255/num;
|
||||
float steps = size/num;
|
||||
|
||||
@@ -7,24 +7,24 @@
|
||||
* click the mouse to execute loop(), which will
|
||||
* cause the draw() the execute continuously.
|
||||
*/
|
||||
|
||||
// The statements in the setup() function
|
||||
// execute once when the program begins
|
||||
void setup()
|
||||
{
|
||||
size(200, 200); // Size should be the first statement
|
||||
stroke(255); // Set stroke color to white
|
||||
noLoop();
|
||||
}
|
||||
|
||||
float y = 100;
|
||||
|
||||
// The statements in the setup() function
|
||||
// run once when the program begins
|
||||
void setup() {
|
||||
size(640, 360); // Size should be the first statement
|
||||
stroke(255); // Set stroke color to white
|
||||
noLoop();
|
||||
|
||||
y = height * 0.5;
|
||||
}
|
||||
|
||||
// The statements in draw() are run until the
|
||||
// program is stopped. Each statement is run in
|
||||
// sequence and after the last line is read, the first
|
||||
// line is run again.
|
||||
void draw()
|
||||
{
|
||||
void draw() {
|
||||
background(0); // Set the background to black
|
||||
line(0, y, width, y);
|
||||
|
||||
@@ -34,7 +34,6 @@ void draw()
|
||||
}
|
||||
}
|
||||
|
||||
void mousePressed()
|
||||
{
|
||||
void mousePressed() {
|
||||
loop();
|
||||
}
|
||||
|
||||
@@ -2,22 +2,23 @@
|
||||
* No Loop.
|
||||
*
|
||||
* The noLoop() function causes draw() to only
|
||||
* execute once. Without calling noLoop(), draw()
|
||||
* executed continually.
|
||||
* execute once. Without calling noLoop(), the
|
||||
* code inside draw() is run continually.
|
||||
*/
|
||||
|
||||
float y;
|
||||
|
||||
// The statements in the setup() function
|
||||
// execute once when the program begins
|
||||
void setup()
|
||||
{
|
||||
size(200, 200); // Size should be the first statement
|
||||
size(640, 360); // Size should be the first statement
|
||||
stroke(255); // Set line drawing color to white
|
||||
frameRate(30);
|
||||
noLoop();
|
||||
|
||||
y = height * 0.5;
|
||||
}
|
||||
|
||||
float y = 100;
|
||||
|
||||
// The statements in draw() are executed until the
|
||||
// program is stopped. Each statement is executed in
|
||||
// sequence and after the last line is read, the first
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
size(640, 360);
|
||||
noStroke();
|
||||
smooth();
|
||||
noLoop();
|
||||
@@ -16,14 +16,14 @@ void setup()
|
||||
|
||||
void draw()
|
||||
{
|
||||
drawCircle(126, 170, 6);
|
||||
drawCircle(width/2, 280, 6);
|
||||
}
|
||||
|
||||
void drawCircle(int x, int radius, int level)
|
||||
{
|
||||
float tt = 126 * level/4.0;
|
||||
fill(tt);
|
||||
ellipse(x, 100, radius*2, radius*2);
|
||||
ellipse(x, height/2, radius*2, radius*2);
|
||||
if(level > 1) {
|
||||
level = level - 1;
|
||||
drawCircle(x - radius/2, radius/2, level);
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
size(640, 360);
|
||||
noStroke();
|
||||
smooth();
|
||||
drawCircle(100, 100, 80, 8);
|
||||
drawCircle(width*0.5, height*0.5, 160, 8);
|
||||
}
|
||||
|
||||
void drawCircle(float x, float y, int radius, int level)
|
||||
|
||||
@@ -6,31 +6,29 @@
|
||||
* the mouse is clicked.
|
||||
*/
|
||||
|
||||
float y;
|
||||
|
||||
// The statements in the setup() function
|
||||
// execute once when the program begins
|
||||
void setup()
|
||||
{
|
||||
size(200, 200); // Size should be the first statement
|
||||
void setup() {
|
||||
size(640, 360); // Size should be the first statement
|
||||
stroke(255); // Set line drawing color to white
|
||||
noLoop();
|
||||
y = height * 0.5;
|
||||
}
|
||||
|
||||
float y = 100;
|
||||
|
||||
// The statements in draw() are executed until the
|
||||
// program is stopped. Each statement is executed in
|
||||
// sequence and after the last line is read, the first
|
||||
// line is executed again.
|
||||
void draw()
|
||||
{
|
||||
void draw() {
|
||||
background(0); // Set the background to black
|
||||
y = y - 1;
|
||||
y = y - 4;
|
||||
if (y < 0) { y = height; }
|
||||
line(0, y, width, y);
|
||||
}
|
||||
|
||||
void mousePressed()
|
||||
{
|
||||
void mousePressed() {
|
||||
redraw();
|
||||
}
|
||||
|
||||
|
||||
@@ -5,16 +5,15 @@
|
||||
* to write programs that change with time.
|
||||
*/
|
||||
|
||||
float y = 100;
|
||||
|
||||
// The statements in the setup() function
|
||||
// execute once when the program begins
|
||||
void setup() {
|
||||
size(200, 200); // Size must be the first statement
|
||||
size(640, 360); // Size must be the first statement
|
||||
stroke(255); // Set line drawing color to white
|
||||
frameRate(30);
|
||||
}
|
||||
|
||||
float y = 100;
|
||||
|
||||
// The statements in draw() are executed until the
|
||||
// program is stopped. Each statement is executed in
|
||||
// sequence and after the last line is read, the first
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
// how large to make the window.
|
||||
// Each function statement has zero or more parameters.
|
||||
// Parameters are data passed into the function
|
||||
// and used as values for specifying what the computer will do.
|
||||
size(200, 200);
|
||||
// and are used as values for telling the computer what to do.
|
||||
size(640, 360);
|
||||
|
||||
// The background function is a statement that tells the computer
|
||||
// which color to make the background of the window
|
||||
background(102);
|
||||
// which color (or gray value) to make the background of the display window
|
||||
background(204, 153, 0);
|
||||
|
||||
@@ -4,13 +4,19 @@
|
||||
* The 'width' and 'height' variables contain the width and height
|
||||
* of the display window as defined in the size() function.
|
||||
*/
|
||||
|
||||
size(200, 200);
|
||||
background(127);
|
||||
noStroke();
|
||||
for(int i=0; i<height; i+=20) {
|
||||
fill(0);
|
||||
rect(0, i, width, 10);
|
||||
fill(255);
|
||||
rect(i, 0, 10, height);
|
||||
|
||||
void setup() {
|
||||
size(640, 360);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(127);
|
||||
noStroke();
|
||||
for (int i=0; i<height; i+=20) {
|
||||
fill(0);
|
||||
rect(0, i, width, 10);
|
||||
fill(255);
|
||||
rect(i, 0, 10, height);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,21 +7,23 @@
|
||||
* the same pushMatrix() and popMatrix() group.
|
||||
*/
|
||||
|
||||
float x = 50;
|
||||
float y = 100;
|
||||
float x, y;
|
||||
float angle1 = 0.0;
|
||||
float angle2 = 0.0;
|
||||
float segLength = 50;
|
||||
float segLength = 100;
|
||||
|
||||
void setup() {
|
||||
size(200, 200);
|
||||
size(640, 360);
|
||||
smooth();
|
||||
strokeWeight(20.0);
|
||||
stroke(0, 100);
|
||||
strokeWeight(30);
|
||||
stroke(255, 160);
|
||||
|
||||
x = width * 0.3;
|
||||
y = height * 0.5;
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(226);
|
||||
background(0);
|
||||
|
||||
angle1 = (mouseX/float(width) - 0.5) * -PI;
|
||||
angle2 = (mouseY/float(height) - 0.5) * PI;
|
||||
|
||||
@@ -13,16 +13,15 @@ float angle;
|
||||
float jitter;
|
||||
|
||||
void setup() {
|
||||
size(200, 200);
|
||||
size(640, 360);
|
||||
smooth();
|
||||
noStroke();
|
||||
fill(255);
|
||||
rectMode(CENTER);
|
||||
frameRate(30);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(102);
|
||||
background(51);
|
||||
|
||||
// during even-numbered seconds (0, 2, 4, 6...)
|
||||
if (second() % 2 == 0) {
|
||||
@@ -32,5 +31,5 @@ void draw() {
|
||||
float c = cos(angle);
|
||||
translate(width/2, height/2);
|
||||
rotate(c);
|
||||
rect(0, 0, 115, 115);
|
||||
rect(0, 0, 180, 180);
|
||||
}
|
||||
|
||||
@@ -11,16 +11,15 @@
|
||||
float a = 0.0;
|
||||
float s = 0.0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200,200);
|
||||
void setup() {
|
||||
size(640, 360);
|
||||
noStroke();
|
||||
rectMode(CENTER);
|
||||
frameRate(30);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
void draw() {
|
||||
|
||||
background(102);
|
||||
|
||||
a = a + 0.04;
|
||||
|
||||
@@ -8,17 +8,14 @@
|
||||
*/
|
||||
|
||||
float x, y;
|
||||
float size = 40.0;
|
||||
float size = 80.0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200,200);
|
||||
void setup() {
|
||||
size(640, 360);
|
||||
noStroke();
|
||||
frameRate(30);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
void draw() {
|
||||
background(102);
|
||||
|
||||
x = x + 0.8;
|
||||
|
||||
@@ -5,23 +5,21 @@
|
||||
* Using rotate() and triangle() functions generate a pretty
|
||||
* flower. Uncomment the line "// rotate(rot+=radians(spin));"
|
||||
* in the triBlur() function for a nice variation.
|
||||
*
|
||||
* Updated 27 February 2010.
|
||||
*/
|
||||
|
||||
PVector[] p = new PVector[3];
|
||||
float shift = 1.0;
|
||||
float shift = 0.2;
|
||||
float fade = 0;
|
||||
float fillCol = 0;
|
||||
float rot = 0;
|
||||
float spin = 0;
|
||||
|
||||
void setup() {
|
||||
size(200, 200);
|
||||
size(640, 360);
|
||||
background(0);
|
||||
smooth();
|
||||
fade = 255.0 / (width/2.0/shift);
|
||||
spin = 360.0 / (width/2.0/shift);
|
||||
fade = 255.0 / (width*0.5 / shift);
|
||||
spin = 360.0 / (width*0.5 / shift);
|
||||
p[0] = new PVector(-width/2, height/2);
|
||||
p[1] = new PVector(width/2, height/2);
|
||||
p[2] = new PVector(0, -height/2);
|
||||
@@ -34,13 +32,11 @@ void triBlur() {
|
||||
fill(fillCol);
|
||||
fillCol += fade;
|
||||
rotate(spin);
|
||||
// another interesting variation: uncomment the line below
|
||||
// rotate(rot+=radians(spin));
|
||||
triangle(p[0].x += shift, p[0].y -= shift/2,
|
||||
p[1].x -= shift, p[1].y -= shift/2,
|
||||
p[2].x, p[2].y += shift);
|
||||
if (p[0].x < 0) {
|
||||
// recursive call
|
||||
// ecursive call
|
||||
triBlur();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,17 +9,16 @@ PFont fontA;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200, 200);
|
||||
size(640, 360);
|
||||
background(0);
|
||||
smooth();
|
||||
// Load the font. Fonts must be placed within the data
|
||||
// directory of your sketch. A font must first be created
|
||||
// using the 'Create Font...' option in the Tools menu.
|
||||
fontA = loadFont("CourierNew36.vlw");
|
||||
textAlign(CENTER);
|
||||
|
||||
// Create the font
|
||||
fontA = createFont("Courier", 42);
|
||||
|
||||
// Set the font and its size (in units of pixels)
|
||||
textFont(fontA, 32);
|
||||
textFont(fontA);
|
||||
textAlign(CENTER);
|
||||
|
||||
// Only draw once
|
||||
noLoop();
|
||||
@@ -32,13 +31,13 @@ void draw()
|
||||
|
||||
// Set the left and top margin
|
||||
int margin = 6;
|
||||
int gap = 30;
|
||||
int gap = 60;
|
||||
translate(margin*1.5, margin*2);
|
||||
|
||||
// Create a matrix of letterforms
|
||||
int counter = 0;
|
||||
for(int i=0; i<margin; i++) {
|
||||
for(int j=0; j<margin; j++) {
|
||||
for(int i = 0; i < margin; i++) {
|
||||
for(int j = 0; j < margin; j++) {
|
||||
char letter;
|
||||
|
||||
// Select the letter
|
||||
@@ -59,7 +58,7 @@ void draw()
|
||||
}
|
||||
|
||||
// Draw the letter to the screen
|
||||
text(letter, 15+j*gap, 20+i*gap);
|
||||
text(letter, 15+j*gap*1.6, 20+i*gap);
|
||||
|
||||
// Increment the counter
|
||||
counter++;
|
||||
|
||||
@@ -9,7 +9,7 @@ boolean overLeftButton = false;
|
||||
boolean overRightButton = false;
|
||||
|
||||
void setup() {
|
||||
size(200, 200);
|
||||
size(640, 360);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
|
||||
@@ -12,16 +12,16 @@ PImage img;
|
||||
|
||||
void setup() {
|
||||
size(640, 360);
|
||||
img = loadImage("http://processing.org/img/processing_cover.gif");
|
||||
img = loadImage("http://processing.org/img/processing.gif");
|
||||
noLoop();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
if (img != null) {
|
||||
image(img, 0, 0);
|
||||
image(img, 0, img.height);
|
||||
image(img, 0, img.height * 2);
|
||||
for (int i = 0; i < 5; i++) {
|
||||
image(img, 0, img.height * i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ ArrayList balls;
|
||||
int ballWidth = 48;
|
||||
|
||||
void setup() {
|
||||
size(200, 200);
|
||||
size(640, 360);
|
||||
smooth();
|
||||
noStroke();
|
||||
|
||||
|
||||
@@ -33,8 +33,8 @@ void setup() {
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(255);
|
||||
fill(0);
|
||||
background(51);
|
||||
fill(255);
|
||||
|
||||
// Look at words one at a time
|
||||
String s = tokens[counter];
|
||||
|
||||
@@ -10,15 +10,17 @@
|
||||
*/
|
||||
|
||||
Animation animation1, animation2;
|
||||
float xpos, ypos;
|
||||
float xpos;
|
||||
float ypos;
|
||||
float drag = 30.0;
|
||||
|
||||
void setup() {
|
||||
size(200, 200);
|
||||
size(640, 360);
|
||||
background(255, 204, 0);
|
||||
frameRate(24);
|
||||
animation1 = new Animation("PT_Shifty_", 38);
|
||||
animation2 = new Animation("PT_Teddy_", 60);
|
||||
ypos = height * 0.25;
|
||||
}
|
||||
|
||||
void draw() {
|
||||
|
||||
@@ -17,7 +17,7 @@ int[][][] world;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(640, 200, P2D);
|
||||
size(640, 360);
|
||||
frameRate(12);
|
||||
sx = width;
|
||||
sy = height;
|
||||
|
||||
@@ -20,7 +20,7 @@ color black = color(0, 0, 0);
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(640, 200, P2D);
|
||||
size(640, 360);
|
||||
frameRate(24);
|
||||
clearscr();
|
||||
w = new World();
|
||||
|
||||
Reference in New Issue
Block a user