mirror of
https://github.com/processing/processing4.git
synced 2026-02-14 02:45:36 +01:00
Merge branch 'master' of github.com:processing/processing
This commit is contained in:
@@ -1,102 +0,0 @@
|
||||
/**
|
||||
* Bezier Ellipse
|
||||
* By Ira Greenberg
|
||||
*
|
||||
* Generates an ellipse using bezier() and
|
||||
* trig functions. Approximately every 1/2
|
||||
* second a new ellipse is plotted using
|
||||
* random values for control/anchor points.
|
||||
*/
|
||||
|
||||
// arrays to hold ellipse coordinate data
|
||||
float[] px, py, cx, cy, cx2, cy2;
|
||||
|
||||
// global variable-points in ellipse
|
||||
int pts = 4;
|
||||
|
||||
color controlPtCol = #222222;
|
||||
color anchorPtCol = #BBBBBB;
|
||||
|
||||
void setup(){
|
||||
size(640, 360);
|
||||
setEllipse(pts, 65, 65);
|
||||
frameRate(1);
|
||||
}
|
||||
|
||||
void draw(){
|
||||
background(145);
|
||||
drawEllipse();
|
||||
setEllipse(int(random(3, 12)), random(-100, 150), random(-100, 150));
|
||||
}
|
||||
|
||||
// Draw ellipse with anchor/control points
|
||||
void drawEllipse(){
|
||||
strokeWeight(1.125);
|
||||
stroke(255);
|
||||
noFill();
|
||||
// Create ellipse
|
||||
for (int i=0; i<pts; i++){
|
||||
if (i==pts-1) {
|
||||
bezier(px[i], py[i], cx[i], cy[i], cx2[i], cy2[i], px[0], py[0]);
|
||||
}
|
||||
else{
|
||||
bezier(px[i], py[i], cx[i], cy[i], cx2[i], cy2[i], px[i+1], py[i+1]);
|
||||
}
|
||||
}
|
||||
strokeWeight(.75);
|
||||
stroke(0);
|
||||
rectMode(CENTER);
|
||||
|
||||
// Control handles and tangent lines
|
||||
for ( int i = 0; i < pts; i++){
|
||||
if (i==pts-1){ // Last loop iteration-close path
|
||||
line(px[0], py[0], cx2[i], cy2[i]);
|
||||
}
|
||||
if (i>0){
|
||||
line(px[i], py[i], cx2[i-1], cy2[i-1]);
|
||||
}
|
||||
line(px[i], py[i], cx[i], cy[i]);
|
||||
}
|
||||
|
||||
for ( int i=0; i< pts; i++){
|
||||
fill(controlPtCol);
|
||||
noStroke();
|
||||
// Control handles
|
||||
ellipse(cx[i], cy[i], 4, 4);
|
||||
ellipse(cx2[i], cy2[i], 4, 4);
|
||||
|
||||
fill(anchorPtCol);
|
||||
stroke(0);
|
||||
// Anchor points
|
||||
rect(px[i], py[i], 5, 5);
|
||||
}
|
||||
}
|
||||
|
||||
// Fill arrays with ellipse coordinate data
|
||||
void setEllipse(int points, float radius, float controlRadius){
|
||||
pts = points;
|
||||
px = new float[points];
|
||||
py = new float[points];
|
||||
cx = new float[points];
|
||||
cy = new float[points];
|
||||
cx2 = new float[points];
|
||||
cy2 = new float[points];
|
||||
float angle = 360.0/points;
|
||||
float controlAngle1 = angle/3.0;
|
||||
float controlAngle2 = controlAngle1*2.0;
|
||||
for ( int i=0; i<points; i++){
|
||||
px[i] = width/2+cos(radians(angle))*radius;
|
||||
py[i] = height/2+sin(radians(angle))*radius;
|
||||
cx[i] = width/2+cos(radians(angle+controlAngle1))*
|
||||
controlRadius/cos(radians(controlAngle1));
|
||||
cy[i] = height/2+sin(radians(angle+controlAngle1))*
|
||||
controlRadius/cos(radians(controlAngle1));
|
||||
cx2[i] = width/2+cos(radians(angle+controlAngle2))*
|
||||
controlRadius/cos(radians(controlAngle1));
|
||||
cy2[i] = height/2+sin(radians(angle+controlAngle2))*
|
||||
controlRadius/cos(radians(controlAngle1));
|
||||
|
||||
// Increment angle so trig functions keep chugging along
|
||||
angle+=360.0/points;
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,28 @@
|
||||
/**
|
||||
* Pie Chart
|
||||
* By Ira Greenberg
|
||||
*
|
||||
* Uses the arc() function to generate a pie chart from the data
|
||||
* stored in an array.
|
||||
*/
|
||||
|
||||
|
||||
float diameter;
|
||||
int[] angles = { 30, 10, 45, 35, 60, 38, 75, 67 };
|
||||
float lastAngle = 0;
|
||||
|
||||
void setup() {
|
||||
size(640, 360);
|
||||
background(100);
|
||||
noStroke();
|
||||
diameter = min(width, height) * 0.75;
|
||||
noLoop(); // Run once and stop
|
||||
}
|
||||
|
||||
|
||||
void draw() {
|
||||
for (int i = 0; i < angles.length; i++) {
|
||||
fill(angles[i] * 3.0);
|
||||
background(100);
|
||||
pieChart(300, angles);
|
||||
}
|
||||
|
||||
void pieChart(float diameter, int[] data) {
|
||||
float lastAngle = 0;
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
float gray = map(i, 0, data.length, 0, 255);
|
||||
fill(gray);
|
||||
arc(width/2, height/2, diameter, diameter, lastAngle, lastAngle+radians(angles[i]));
|
||||
lastAngle += radians(angles[i]);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ int p3 = p2+d;
|
||||
int p4 = p3+d;
|
||||
|
||||
size(640, 360);
|
||||
noSmooth();
|
||||
background(0);
|
||||
translate(140, 0);
|
||||
|
||||
|
||||
46
java/examples/Basics/Form/RegularPolygon/RegularPolygon.pde
Normal file
46
java/examples/Basics/Form/RegularPolygon/RegularPolygon.pde
Normal file
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Regular Polygon
|
||||
*
|
||||
* What is your favorite? Pentagon? Hexagon? Heptagon?
|
||||
* No? What about the icosagon? The polygon() function
|
||||
* created for this example is capable of drawing any
|
||||
* regular polygon. Try placing different numbers into the
|
||||
* polygon() function calls within draw() to explore.
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
size(640, 360);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(102);
|
||||
|
||||
pushMatrix();
|
||||
translate(width*0.2, height*0.5);
|
||||
rotate(frameCount / 200.0);
|
||||
polygon(0, 0, 82, 3);
|
||||
popMatrix();
|
||||
|
||||
pushMatrix();
|
||||
translate(width*0.5, height*0.5);
|
||||
rotate(frameCount / 50.0);
|
||||
polygon(0, 0, 80, 20);
|
||||
popMatrix();
|
||||
|
||||
pushMatrix();
|
||||
translate(width*0.8, height*0.5);
|
||||
rotate(frameCount / -100.0);
|
||||
polygon(0, 0, 70, 7);
|
||||
popMatrix();
|
||||
}
|
||||
|
||||
void polygon(float x, float y, float radius, int npoints) {
|
||||
float angle = TWO_PI / npoints;
|
||||
beginShape();
|
||||
for (float a = 0; a < TWO_PI; a += angle) {
|
||||
float sx = x + cos(a) * radius;
|
||||
float sy = y + sin(a) * radius;
|
||||
vertex(sx, sy);
|
||||
}
|
||||
endShape(CLOSE);
|
||||
}
|
||||
48
java/examples/Basics/Form/Star/Star.pde
Normal file
48
java/examples/Basics/Form/Star/Star.pde
Normal file
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Star
|
||||
*
|
||||
* The star() function created for this example is capable of drawing a
|
||||
* wide range of different forms. Try placing different numbers into the
|
||||
* star() function calls within draw() to explore.
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
size(640, 360);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(102);
|
||||
|
||||
pushMatrix();
|
||||
translate(width*0.2, height*0.5);
|
||||
rotate(frameCount / 200.0);
|
||||
star(0, 0, 5, 70, 3);
|
||||
popMatrix();
|
||||
|
||||
pushMatrix();
|
||||
translate(width*0.5, height*0.5);
|
||||
rotate(frameCount / 50.0);
|
||||
star(0, 0, 80, 100, 40);
|
||||
popMatrix();
|
||||
|
||||
pushMatrix();
|
||||
translate(width*0.8, height*0.5);
|
||||
rotate(frameCount / -100.0);
|
||||
star(0, 0, 30, 70, 5);
|
||||
popMatrix();
|
||||
}
|
||||
|
||||
void star(float x, float y, float radius1, float radius2, int npoints) {
|
||||
float angle = TWO_PI / npoints;
|
||||
float halfAngle = angle/2.0;
|
||||
beginShape();
|
||||
for (float a = 0; a < TWO_PI; a += angle) {
|
||||
float sx = x + cos(a) * radius2;
|
||||
float sy = y + sin(a) * radius2;
|
||||
vertex(sx, sy);
|
||||
sx = x + cos(a+halfAngle) * radius1;
|
||||
sy = y + sin(a+halfAngle) * radius1;
|
||||
vertex(sx, sy);
|
||||
}
|
||||
endShape(CLOSE);
|
||||
}
|
||||
@@ -1,43 +1,41 @@
|
||||
/**
|
||||
* TRIANGLE_STRIP Mode
|
||||
* Triangle Strip
|
||||
* by Ira Greenberg.
|
||||
*
|
||||
* Generate a closed ring using the vertex() function and
|
||||
* beginShape(TRIANGLE_STRIP) mode. The outerRad and innerRad
|
||||
* beginShape(TRIANGLE_STRIP) mode. The outsideRadius and insideRadius
|
||||
* variables control ring's radii respectively.
|
||||
*/
|
||||
|
||||
int x;
|
||||
int y;
|
||||
float outerRad;
|
||||
float innerRad;
|
||||
float outsideRadius = 150;
|
||||
float insideRadius = 100;
|
||||
|
||||
void setup() {
|
||||
size(640, 360);
|
||||
background(204);
|
||||
x = width/2;
|
||||
y = height/2;
|
||||
outerRad = min(width, height) * 0.4;
|
||||
innerRad = outerRad * 0.6;
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(204);
|
||||
|
||||
int pts = int(map(mouseX, 0, width, 6, 60));
|
||||
float rot = 180.0/pts;
|
||||
int numPoints = int(map(mouseX, 0, width, 6, 60));
|
||||
float angle = 0;
|
||||
|
||||
float angleStep = 180.0/numPoints;
|
||||
|
||||
beginShape(TRIANGLE_STRIP);
|
||||
for (int i = 0; i <= pts; i++) {
|
||||
float px = x + cos(radians(angle)) * outerRad;
|
||||
float py = y + sin(radians(angle)) * outerRad;
|
||||
angle += rot;
|
||||
for (int i = 0; i <= numPoints; i++) {
|
||||
float px = x + cos(radians(angle)) * outsideRadius;
|
||||
float py = y + sin(radians(angle)) * outsideRadius;
|
||||
angle += angleStep;
|
||||
vertex(px, py);
|
||||
px = x + cos(radians(angle)) * innerRad;
|
||||
py = y + sin(radians(angle)) * innerRad;
|
||||
px = x + cos(radians(angle)) * insideRadius;
|
||||
py = y + sin(radians(angle)) * insideRadius;
|
||||
vertex(px, py);
|
||||
angle += rot;
|
||||
angle += angleStep;
|
||||
}
|
||||
endShape();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user