mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
Examples updates for 2.0
This commit is contained in:
@@ -7,12 +7,12 @@
|
||||
* that define the shape of the curve.
|
||||
*/
|
||||
|
||||
size(200, 200);
|
||||
size(640, 360);
|
||||
background(0);
|
||||
stroke(255);
|
||||
noFill();
|
||||
smooth();
|
||||
|
||||
for(int i = 0; i < 100; i += 20) {
|
||||
bezier(90-(i/2.0), 20+i, 210, 10, 220, 150, 120-(i/8.0), 150+(i/4.0));
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ color controlPtCol = #222222;
|
||||
color anchorPtCol = #BBBBBB;
|
||||
|
||||
void setup(){
|
||||
size(200, 200);
|
||||
size(640, 360);
|
||||
smooth();
|
||||
setEllipse(pts, 65, 65);
|
||||
frameRate(1);
|
||||
@@ -30,12 +30,12 @@ void draw(){
|
||||
setEllipse(int(random(3, 12)), random(-100, 150), random(-100, 150));
|
||||
}
|
||||
|
||||
// draw ellipse with anchor/control points
|
||||
// Draw ellipse with anchor/control points
|
||||
void drawEllipse(){
|
||||
strokeWeight(1.125);
|
||||
stroke(255);
|
||||
noFill();
|
||||
// create ellipse
|
||||
// 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]);
|
||||
@@ -48,9 +48,9 @@ void drawEllipse(){
|
||||
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
|
||||
// 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){
|
||||
@@ -62,18 +62,18 @@ void drawEllipse(){
|
||||
for ( int i=0; i< pts; i++){
|
||||
fill(controlPtCol);
|
||||
noStroke();
|
||||
//control handles
|
||||
// Control handles
|
||||
ellipse(cx[i], cy[i], 4, 4);
|
||||
ellipse(cx2[i], cy2[i], 4, 4);
|
||||
|
||||
fill(anchorPtCol);
|
||||
stroke(0);
|
||||
//anchor points
|
||||
// Anchor points
|
||||
rect(px[i], py[i], 5, 5);
|
||||
}
|
||||
}
|
||||
|
||||
// fill up arrays with ellipse coordinate data
|
||||
// Fill arrays with ellipse coordinate data
|
||||
void setEllipse(int points, float radius, float controlRadius){
|
||||
pts = points;
|
||||
px = new float[points];
|
||||
@@ -97,7 +97,7 @@ void setEllipse(int points, float radius, float controlRadius){
|
||||
cy2[i] = height/2+sin(radians(angle+controlAngle2))*
|
||||
controlRadius/cos(radians(controlAngle1));
|
||||
|
||||
//increment angle so trig functions keep chugging along
|
||||
// Increment angle so trig functions keep chugging along
|
||||
angle+=360.0/points;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,19 +5,27 @@
|
||||
* Uses the arc() function to generate a pie chart from the data
|
||||
* stored in an array.
|
||||
*/
|
||||
|
||||
size(200, 200);
|
||||
background(100);
|
||||
smooth();
|
||||
noStroke();
|
||||
|
||||
float diameter = min(width, height) * 0.75;
|
||||
int[] angs = {30, 10, 45, 35, 60, 38, 75, 67};
|
||||
float lastAng = 0;
|
||||
|
||||
for (int i = 0; i < angs.length; i++){
|
||||
fill(angs[i] * 3.0);
|
||||
arc(width/2, height/2, diameter, diameter, lastAng, lastAng+radians(angs[i]));
|
||||
lastAng += radians(angs[i]);
|
||||
float diameter;
|
||||
int[] angles = { 30, 10, 45, 35, 60, 38, 75, 67 };
|
||||
float lastAngle = 0;
|
||||
|
||||
void setup() {
|
||||
size(640, 360);
|
||||
background(100);
|
||||
smooth();
|
||||
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);
|
||||
arc(width/2, height/2, diameter, diameter, lastAngle, lastAngle+radians(angles[i]));
|
||||
lastAngle += radians(angles[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,14 +6,15 @@
|
||||
* The four variables set the positions based on the value of 'd'.
|
||||
*/
|
||||
|
||||
int d = 40;
|
||||
int d = 70;
|
||||
int p1 = d;
|
||||
int p2 = p1+d;
|
||||
int p3 = p2+d;
|
||||
int p4 = p3+d;
|
||||
|
||||
size(200, 200);
|
||||
size(640, 360);
|
||||
background(0);
|
||||
translate(140, 0);
|
||||
|
||||
// Draw gray box
|
||||
stroke(153);
|
||||
|
||||
@@ -8,14 +8,18 @@
|
||||
* of parameters to determine the shape's position and size.
|
||||
*/
|
||||
|
||||
size(200, 200);
|
||||
size(640, 360);
|
||||
smooth();
|
||||
background(0);
|
||||
noStroke();
|
||||
fill(226);
|
||||
triangle(10, 10, 10, 200, 45, 200);
|
||||
rect(45, 45, 35, 35);
|
||||
quad(105, 10, 120, 10, 120, 200, 80, 200);
|
||||
ellipse(140, 80, 40, 40);
|
||||
triangle(160, 10, 195, 200, 160, 200);
|
||||
fill(204);
|
||||
triangle(18, 18, 18, 360, 81, 360);
|
||||
fill(153);
|
||||
rect(81, 81, 63, 63);
|
||||
fill(204);
|
||||
quad(189, 18, 216, 18, 216, 360, 144, 360);
|
||||
fill(255);
|
||||
ellipse(252, 144, 72, 72);
|
||||
fill(204);
|
||||
triangle(288, 18, 351, 360, 288, 360);
|
||||
|
||||
|
||||
@@ -8,45 +8,46 @@
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
size(200, 200);
|
||||
size(640, 360);
|
||||
colorMode(RGB, 100);
|
||||
smooth();
|
||||
background(0);
|
||||
noFill();
|
||||
noLoop();
|
||||
noLoop(); // Run once and stop
|
||||
}
|
||||
|
||||
void draw() {
|
||||
stroke(40);
|
||||
beginShape();
|
||||
for(int i=0; i<width; i++) {
|
||||
for(int i = 0; i < width; i++) {
|
||||
vertex(i, singraph((float)i/width)*height);
|
||||
}
|
||||
endShape();
|
||||
|
||||
stroke(55);
|
||||
beginShape();
|
||||
for(int i=0; i<width; i++) {
|
||||
for(int i = 0; i < width; i++) {
|
||||
vertex(i, quad((float)i/width)*height);
|
||||
}
|
||||
endShape();
|
||||
|
||||
stroke(70);
|
||||
beginShape();
|
||||
for(int i=0; i<width; i++) {
|
||||
for(int i = 0; i < width; i++) {
|
||||
vertex(i, quadHump((float)i/width)*height);
|
||||
}
|
||||
endShape();
|
||||
|
||||
stroke(85);
|
||||
beginShape();
|
||||
for(int i=0; i<width; i++) {
|
||||
for(int i = 0; i < width; i++) {
|
||||
vertex(i, hump((float)i/width)*height);
|
||||
}
|
||||
endShape();
|
||||
|
||||
stroke(100);
|
||||
beginShape();
|
||||
for(int i=0; i<width; i++) {
|
||||
for(int i = 0; i < width; i++) {
|
||||
vertex(i, squared((float)i/width)*height);
|
||||
}
|
||||
endShape();
|
||||
|
||||
@@ -9,28 +9,38 @@
|
||||
* Trig functions generate ring.
|
||||
*/
|
||||
|
||||
size(200, 200);
|
||||
background(204);
|
||||
smooth();
|
||||
|
||||
int x = width/2;
|
||||
int y = height/2;
|
||||
float outerRad = min(width, height) * 0.4;
|
||||
float innerRad = outerRad * 0.6;
|
||||
float px = 0, py = 0, angle = 0;
|
||||
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;
|
||||
|
||||
beginShape(TRIANGLE_STRIP);
|
||||
for (int i = 0; i < pts; i++) {
|
||||
px = x + cos(radians(angle))*outerRad;
|
||||
py = y + sin(radians(angle))*outerRad;
|
||||
angle += rot;
|
||||
vertex(px, py);
|
||||
px = x + cos(radians(angle))*innerRad;
|
||||
py = y + sin(radians(angle))*innerRad;
|
||||
vertex(px, py);
|
||||
angle += rot;
|
||||
void setup() {
|
||||
size(640, 360);
|
||||
background(204);
|
||||
smooth();
|
||||
x = width/2;
|
||||
y = height/2;
|
||||
outerRad = min(width, height) * 0.4;
|
||||
innerRad = outerRad * 0.6;
|
||||
}
|
||||
|
||||
void draw() {
|
||||
beginShape(TRIANGLE_STRIP);
|
||||
for (int i = 0; i < pts; i++) {
|
||||
px = x + cos(radians(angle)) * outerRad;
|
||||
py = y + sin(radians(angle)) * outerRad;
|
||||
angle += rot;
|
||||
vertex(px, py);
|
||||
px = x + cos(radians(angle)) * innerRad;
|
||||
py = y + sin(radians(angle)) * innerRad;
|
||||
vertex(px, py);
|
||||
angle += rot;
|
||||
}
|
||||
endShape();
|
||||
}
|
||||
endShape();
|
||||
|
||||
|
||||
@@ -9,10 +9,14 @@
|
||||
* To stop drawing the shape, call the endShape() functions.
|
||||
*/
|
||||
|
||||
size(200, 200);
|
||||
size(640, 360);
|
||||
background(0);
|
||||
noFill();
|
||||
|
||||
translate(140, 20);
|
||||
scale(1.5);
|
||||
strokeWeight(.5);
|
||||
|
||||
stroke(102);
|
||||
beginShape();
|
||||
curveVertex(168, 182);
|
||||
|
||||
Reference in New Issue
Block a user