mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Arm.
|
||||
*
|
||||
* The angle of each segment is controlled with the mouseX and
|
||||
* mouseY position. The transformations applied to the first segment
|
||||
* are also applied to the second segment because they are inside
|
||||
* the same pushMatrix() and popMatrix() group.
|
||||
*/
|
||||
|
||||
float x = 50;
|
||||
float y = 100;
|
||||
float angle1 = 0.0;
|
||||
float angle2 = 0.0;
|
||||
float segLength = 50;
|
||||
|
||||
void setup() {
|
||||
size(200, 200);
|
||||
smooth();
|
||||
strokeWeight(20.0);
|
||||
stroke(0, 100);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(226);
|
||||
|
||||
angle1 = (mouseX/float(width) - 0.5) * -PI;
|
||||
angle2 = (mouseY/float(height) - 0.5) * PI;
|
||||
|
||||
pushMatrix();
|
||||
segment(x, y, angle1);
|
||||
segment(segLength, 0, angle2);
|
||||
popMatrix();
|
||||
}
|
||||
|
||||
void segment(float x, float y, float a) {
|
||||
translate(x, y);
|
||||
rotate(a);
|
||||
line(0, 0, segLength, 0);
|
||||
}
|
||||
@@ -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 Arm extends PApplet {
|
||||
|
||||
/**
|
||||
* Arm.
|
||||
*
|
||||
* The angle of each segment is controlled with the mouseX and
|
||||
* mouseY position. The transformations applied to the first segment
|
||||
* are also applied to the second segment because they are inside
|
||||
* the same pushMatrix() and popMatrix() group.
|
||||
*/
|
||||
|
||||
float x = 50;
|
||||
float y = 100;
|
||||
float angle1 = 0.0f;
|
||||
float angle2 = 0.0f;
|
||||
float segLength = 50;
|
||||
|
||||
public void setup() {
|
||||
size(200, 200);
|
||||
smooth();
|
||||
strokeWeight(20.0f);
|
||||
stroke(0, 100);
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
background(226);
|
||||
|
||||
angle1 = (mouseX/PApplet.parseFloat(width) - 0.5f) * -PI;
|
||||
angle2 = (mouseY/PApplet.parseFloat(height) - 0.5f) * PI;
|
||||
|
||||
pushMatrix();
|
||||
segment(x, y, angle1);
|
||||
segment(segLength, 0, angle2);
|
||||
popMatrix();
|
||||
}
|
||||
|
||||
public void segment(float x, float y, float a) {
|
||||
translate(x, y);
|
||||
rotate(a);
|
||||
line(0, 0, segLength, 0);
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "Arm" });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Arm.
|
||||
*
|
||||
* The angle of each segment is controlled with the mouseX and
|
||||
* mouseY position. The transformations applied to the first segment
|
||||
* are also applied to the second segment because they are inside
|
||||
* the same pushMatrix() and popMatrix() group.
|
||||
*/
|
||||
|
||||
float x = 50;
|
||||
float y = 100;
|
||||
float angle1 = 0.0;
|
||||
float angle2 = 0.0;
|
||||
float segLength = 50;
|
||||
|
||||
void setup() {
|
||||
size(200, 200);
|
||||
smooth();
|
||||
strokeWeight(20.0);
|
||||
stroke(0, 100);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(226);
|
||||
|
||||
angle1 = (mouseX/float(width) - 0.5) * -PI;
|
||||
angle2 = (mouseY/float(height) - 0.5) * PI;
|
||||
|
||||
pushMatrix();
|
||||
segment(x, y, angle1);
|
||||
segment(segLength, 0, angle2);
|
||||
popMatrix();
|
||||
}
|
||||
|
||||
void segment(float x, float y, float a) {
|
||||
translate(x, y);
|
||||
rotate(a);
|
||||
line(0, 0, segLength, 0);
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Rotate.
|
||||
*
|
||||
* Rotating a square around the Z axis. To get the results
|
||||
* you expect, send the rotate function angle parameters that are
|
||||
* values between 0 and PI*2 (TWO_PI which is roughly 6.28). If you prefer to
|
||||
* think about angles as degrees (0-360), you can use the radians()
|
||||
* method to convert your values. For example: scale(radians(90))
|
||||
* is identical to the statement scale(PI/2).
|
||||
*/
|
||||
|
||||
float angle;
|
||||
float jitter;
|
||||
|
||||
void setup() {
|
||||
size(200, 200);
|
||||
smooth();
|
||||
noStroke();
|
||||
fill(255);
|
||||
rectMode(CENTER);
|
||||
frameRate(30);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(102);
|
||||
|
||||
// during even-numbered seconds (0, 2, 4, 6...)
|
||||
if (second() % 2 == 0) {
|
||||
jitter = random(-0.1, 0.1);
|
||||
}
|
||||
angle = angle + jitter;
|
||||
float c = cos(angle);
|
||||
translate(width/2, height/2);
|
||||
rotate(c);
|
||||
rect(0, 0, 115, 115);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
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 Rotate extends PApplet {
|
||||
|
||||
/**
|
||||
* Rotate.
|
||||
*
|
||||
* Rotating a square around the Z axis. To get the results
|
||||
* you expect, send the rotate function angle parameters that are
|
||||
* values between 0 and PI*2 (TWO_PI which is roughly 6.28). If you prefer to
|
||||
* think about angles as degrees (0-360), you can use the radians()
|
||||
* method to convert your values. For example: scale(radians(90))
|
||||
* is identical to the statement scale(PI/2).
|
||||
*/
|
||||
|
||||
public void setup()
|
||||
{
|
||||
size(200,200);
|
||||
noStroke();
|
||||
fill(255);
|
||||
frameRate(30);
|
||||
}
|
||||
|
||||
float angle;
|
||||
float cosine;
|
||||
float jitter;
|
||||
|
||||
public void draw()
|
||||
{
|
||||
background(102);
|
||||
|
||||
if(second()%2 == 0){
|
||||
jitter = (random(-0.1f, 0.1f));
|
||||
}
|
||||
angle = angle + jitter;
|
||||
cosine = cos(angle);
|
||||
|
||||
translate(width/2, height/2);
|
||||
rotate(cosine);
|
||||
rectMode(CENTER);
|
||||
rect(0, 0, 115, 115);
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "Rotate" });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Rotate.
|
||||
*
|
||||
* Rotating a square around the Z axis. To get the results
|
||||
* you expect, send the rotate function angle parameters that are
|
||||
* values between 0 and PI*2 (TWO_PI which is roughly 6.28). If you prefer to
|
||||
* think about angles as degrees (0-360), you can use the radians()
|
||||
* method to convert your values. For example: scale(radians(90))
|
||||
* is identical to the statement scale(PI/2).
|
||||
*/
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200,200);
|
||||
noStroke();
|
||||
fill(255);
|
||||
frameRate(30);
|
||||
}
|
||||
|
||||
float angle;
|
||||
float cosine;
|
||||
float jitter;
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(102);
|
||||
|
||||
if(second()%2 == 0){
|
||||
jitter = (random(-0.1, 0.1));
|
||||
}
|
||||
angle = angle + jitter;
|
||||
cosine = cos(angle);
|
||||
|
||||
translate(width/2, height/2);
|
||||
rotate(cosine);
|
||||
rectMode(CENTER);
|
||||
rect(0, 0, 115, 115);
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Scale
|
||||
* by Denis Grutze.
|
||||
*
|
||||
* Paramenters for the scale() function are values specified
|
||||
* as decimal percentages. For example, the method call scale(2.0)
|
||||
* will increase the dimension of the shape by 200 percent.
|
||||
* Objects always scale from the origin.
|
||||
*/
|
||||
|
||||
float a = 0.0;
|
||||
float s = 0.0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200,200);
|
||||
noStroke();
|
||||
rectMode(CENTER);
|
||||
frameRate(30);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(102);
|
||||
|
||||
a = a + 0.04;
|
||||
s = cos(a)*2;
|
||||
|
||||
translate(width/2, height/2);
|
||||
scale(s);
|
||||
fill(51);
|
||||
rect(0, 0, 50, 50);
|
||||
|
||||
translate(75, 0);
|
||||
fill(255);
|
||||
scale(s);
|
||||
rect(0, 0, 50, 50);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
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 Scale extends PApplet {
|
||||
|
||||
/**
|
||||
* Scale
|
||||
* by Denis Grutze.
|
||||
*
|
||||
* Paramenters for the scale() function are values specified
|
||||
* as decimal percentages. For example, the method call scale(2.0)
|
||||
* will increase the dimension of the shape by 200 percent.
|
||||
* Objects always scale from the origin.
|
||||
*/
|
||||
|
||||
float a = 0.0f;
|
||||
float s = 0.0f;
|
||||
|
||||
public void setup()
|
||||
{
|
||||
size(200,200);
|
||||
noStroke();
|
||||
rectMode(CENTER);
|
||||
frameRate(30);
|
||||
}
|
||||
|
||||
public void draw()
|
||||
{
|
||||
background(102);
|
||||
|
||||
a = a + 0.04f;
|
||||
s = cos(a)*2;
|
||||
|
||||
translate(width/2, height/2);
|
||||
scale(s);
|
||||
fill(51);
|
||||
rect(0, 0, 50, 50);
|
||||
|
||||
translate(75, 0);
|
||||
fill(255);
|
||||
scale(s);
|
||||
rect(0, 0, 50, 50);
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "Scale" });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Scale
|
||||
* by Denis Grutze.
|
||||
*
|
||||
* Paramenters for the scale() function are values specified
|
||||
* as decimal percentages. For example, the method call scale(2.0)
|
||||
* will increase the dimension of the shape by 200 percent.
|
||||
* Objects always scale from the origin.
|
||||
*/
|
||||
|
||||
float a = 0.0;
|
||||
float s = 0.0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200,200);
|
||||
noStroke();
|
||||
rectMode(CENTER);
|
||||
frameRate(30);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(102);
|
||||
|
||||
a = a + 0.04;
|
||||
s = cos(a)*2;
|
||||
|
||||
translate(width/2, height/2);
|
||||
scale(s);
|
||||
fill(51);
|
||||
rect(0, 0, 50, 50);
|
||||
|
||||
translate(75, 0);
|
||||
fill(255);
|
||||
scale(s);
|
||||
rect(0, 0, 50, 50);
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Translate.
|
||||
*
|
||||
* The translate() function allows objects to be moved
|
||||
* to any location within the window. The first parameter
|
||||
* sets the x-axis offset and the second parameter sets the
|
||||
* y-axis offset.
|
||||
*/
|
||||
|
||||
float x, y;
|
||||
float size = 40.0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200,200);
|
||||
noStroke();
|
||||
frameRate(30);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(102);
|
||||
|
||||
x = x + 0.8;
|
||||
|
||||
if (x > width + size) {
|
||||
x = -size;
|
||||
}
|
||||
|
||||
translate(x, height/2-size/2);
|
||||
fill(255);
|
||||
rect(-size/2, -size/2, size, size);
|
||||
|
||||
// Transforms accumulate.
|
||||
// Notice how this rect moves twice
|
||||
// as fast as the other, but it has
|
||||
// the same parameter for the x-axis value
|
||||
translate(x, size);
|
||||
fill(0);
|
||||
rect(-size/2, -size/2, size, size);
|
||||
}
|
||||
@@ -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 Translate extends PApplet {
|
||||
|
||||
/**
|
||||
* Translate.
|
||||
*
|
||||
* The translate() function allows objects to be moved
|
||||
* to any location within the window. The first parameter
|
||||
* sets the x-axis offset and the second parameter sets the
|
||||
* y-axis offset.
|
||||
*/
|
||||
|
||||
float x, y;
|
||||
float size = 40.0f;
|
||||
|
||||
public void setup()
|
||||
{
|
||||
size(200,200);
|
||||
noStroke();
|
||||
frameRate(30);
|
||||
}
|
||||
|
||||
public void draw()
|
||||
{
|
||||
background(102);
|
||||
|
||||
x = x + 0.8f;
|
||||
|
||||
if (x > width + size) {
|
||||
x = -size;
|
||||
}
|
||||
|
||||
translate(x, height/2-size/2);
|
||||
fill(255);
|
||||
rect(-size/2, -size/2, size, size);
|
||||
|
||||
// Transforms accumulate.
|
||||
// Notice how this rect moves twice
|
||||
// as fast as the other, but it has
|
||||
// the same parameter for the x-axis value
|
||||
translate(x, size);
|
||||
fill(0);
|
||||
rect(-size/2, -size/2, size, size);
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "Translate" });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Translate.
|
||||
*
|
||||
* The translate() function allows objects to be moved
|
||||
* to any location within the window. The first parameter
|
||||
* sets the x-axis offset and the second parameter sets the
|
||||
* y-axis offset.
|
||||
*/
|
||||
|
||||
float x, y;
|
||||
float size = 40.0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(200,200);
|
||||
noStroke();
|
||||
frameRate(30);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(102);
|
||||
|
||||
x = x + 0.8;
|
||||
|
||||
if (x > width + size) {
|
||||
x = -size;
|
||||
}
|
||||
|
||||
translate(x, height/2-size/2);
|
||||
fill(255);
|
||||
rect(-size/2, -size/2, size, size);
|
||||
|
||||
// Transforms accumulate.
|
||||
// Notice how this rect moves twice
|
||||
// as fast as the other, but it has
|
||||
// the same parameter for the x-axis value
|
||||
translate(x, size);
|
||||
fill(0);
|
||||
rect(-size/2, -size/2, size, size);
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Triangle Flower
|
||||
* by Ira Greenberg.
|
||||
*
|
||||
* 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 fade = 0;
|
||||
float fillCol = 0;
|
||||
float rot = 0;
|
||||
float spin = 0;
|
||||
|
||||
void setup() {
|
||||
size(200, 200);
|
||||
background(0);
|
||||
smooth();
|
||||
fade = 255.0 / (width/2.0/shift);
|
||||
spin = 360.0 / (width/2.0/shift);
|
||||
p[0] = new PVector(-width/2, height/2);
|
||||
p[1] = new PVector(width/2, height/2);
|
||||
p[2] = new PVector(0, -height/2);
|
||||
noStroke();
|
||||
translate(width/2, height/2);
|
||||
triBlur();
|
||||
}
|
||||
|
||||
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
|
||||
triBlur();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
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 TriangleFlower extends PApplet {
|
||||
|
||||
/**
|
||||
* Triangle Flower
|
||||
* by Ira Greenberg.
|
||||
*
|
||||
* Using rotate() and triangle() functions generate a pretty
|
||||
* flower. Uncomment the line "// rotate(rot+=radians(spin));"
|
||||
* in the triBlur() function for a nice variation.
|
||||
*/
|
||||
|
||||
Point[]p = new Point[3];
|
||||
float shift = 1.0f;
|
||||
float fade = 0;
|
||||
float fillCol = 0;
|
||||
float rot = 0;
|
||||
float spin = 0;
|
||||
|
||||
public void setup(){
|
||||
size(200, 200);
|
||||
background(0);
|
||||
smooth();
|
||||
fade = 255.0f/(width/2.0f/shift);
|
||||
spin = 360.0f/(width/2.0f/shift);
|
||||
p[0] = new Point(-width/2, height/2);
|
||||
p[1] = new Point(width/2, height/2);
|
||||
p[2] = new Point(0, -height/2);
|
||||
noStroke();
|
||||
translate(width/2, height/2);
|
||||
triBlur();
|
||||
}
|
||||
|
||||
public 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
|
||||
triBlur();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "TriangleFlower" });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Triangle Flower
|
||||
* by Ira Greenberg.
|
||||
*
|
||||
* Using rotate() and triangle() functions generate a pretty
|
||||
* flower. Uncomment the line "// rotate(rot+=radians(spin));"
|
||||
* in the triBlur() function for a nice variation.
|
||||
*/
|
||||
|
||||
Point[]p = new Point[3];
|
||||
float shift = 1.0;
|
||||
float fade = 0;
|
||||
float fillCol = 0;
|
||||
float rot = 0;
|
||||
float spin = 0;
|
||||
|
||||
void setup(){
|
||||
size(200, 200);
|
||||
background(0);
|
||||
smooth();
|
||||
fade = 255.0/(width/2.0/shift);
|
||||
spin = 360.0/(width/2.0/shift);
|
||||
p[0] = new Point(-width/2, height/2);
|
||||
p[1] = new Point(width/2, height/2);
|
||||
p[2] = new Point(0, -height/2);
|
||||
noStroke();
|
||||
translate(width/2, height/2);
|
||||
triBlur();
|
||||
}
|
||||
|
||||
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
|
||||
triBlur();
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
Reference in New Issue
Block a user