Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Apress
committed
Oct 17, 2016
0 parents
commit 368c16e
Showing
872 changed files
with
38,965 additions
and
0 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright (c) 2013, Friends of Ed (An Apress Company) | ||
All rights reserved. | ||
|
||
The code provided here accompanies the book: | ||
|
||
Processing: Creative Coding and Generative Art in Processing 2 | ||
By Ira Greenberg, Dianna Xu, and Deepak Kumar | ||
Friends of Ed (An APress Company), 2013 | ||
ISBN-13 978-1430244646 | ||
|
||
This source code is provided "as is" for educational purposes only. | ||
Any express or implied warranties, including, but not limited to, the | ||
implied warraties of mechanibility and fitness for a particular purpose | ||
are disclaimed. In no event shall the copyright owner be liable for any | ||
direct, indirect, incidental, special, exemplary, or consequential damages | ||
(including but not limited to, procurement of substitute goods or services; | ||
loss of use, data, or profits; or business interruption) however caused | ||
and on any theory of liability, whether in contract, strict liability, or | ||
tort (including negligence or otherwise) arising in any way out of the use | ||
of this code, even if advised of the possibility of such damage. |
Binary file not shown.
105 changes: 105 additions & 0 deletions
105
CodeToAccompany9781430244646/ch02/algorithmic_face/algorithmic_face.pde
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/*------------------------------------------------------------ | ||
Copyright (c) 2013, friends of Ed (An Apress Company) | ||
All rights reserved. | ||
The code provided here accompanies the book: | ||
Processing: Creative Coding and Generative Art in Processing 2 | ||
By Ira Greenberg, Dianna Xu, and Deepak Kumar | ||
friends of Ed (An APress Company), 2013 | ||
ISBN-13 978-1430244646 | ||
Please refer to the associated README for a full disclaimer. | ||
------------------------------------------------------------*/ | ||
// algorithmic_face.pde, chapter 2 | ||
// Algorithmic approach to drawing a face. | ||
|
||
// Simple Algorithmic Face | ||
size(600, 800); | ||
background(0); | ||
stroke(255); | ||
noFill(); | ||
// draw ellipses from top left corner | ||
ellipseMode(CORNER); | ||
|
||
// BEGIN DECLARE/INITIALIZE VARIABLES | ||
// HEAD | ||
float headHeight = 600; | ||
float headWidth = headHeight*5/7; | ||
float head_x = (width-headWidth)/2; | ||
float head_y = (height-headHeight)/2; | ||
|
||
// EYES | ||
float eyeWidth = headWidth/5; | ||
float eyeHeight = eyeWidth/2; | ||
float irisDiam = eyeHeight; | ||
float pupilDiam = irisDiam/3; | ||
float eye_y = head_y+headHeight/2-eyeHeight/2; | ||
// left | ||
float leftEye_x = head_x+eyeWidth; | ||
float leftIris_x = leftEye_x + eyeWidth/2-irisDiam/2; | ||
float leftPupil_x = leftEye_x + eyeWidth/2-pupilDiam/2; | ||
// right | ||
float rightEye_x = head_x+eyeWidth*3; | ||
float rightIris_x = rightEye_x + eyeWidth/2-irisDiam/2; | ||
float rightPupil_x = rightEye_x + eyeWidth/2-pupilDiam/2; | ||
|
||
//EYEBROWS | ||
float eyeBrowWidth = eyeWidth*1.25; | ||
float eyeBrowHeight = eyeHeight/4; | ||
float eyeBrow_y = eye_y - eyeHeight - eyeBrowHeight/2; | ||
// left | ||
float leftEyeBrow_x = leftEye_x - (eyeBrowWidth-eyeWidth); | ||
// right | ||
float rightEyeBrow_x = rightEye_x; | ||
|
||
// NOSE | ||
float nose_x = head_x+eyeWidth*2; | ||
float nose_y = head_y + headHeight - headHeight/4; | ||
|
||
// MOUTH | ||
float mouthWidth = eyeWidth*1.5; | ||
float mouthHeight = headHeight/12; | ||
float mouth_x = leftIris_x+irisDiam/2+eyeWidth/4; | ||
float mouth_y = nose_y + mouthHeight; | ||
|
||
// EARS | ||
float earWidth = eyeHeight*1.5; | ||
float earHeight = headHeight/4; | ||
float ear_y = eyeBrow_y; | ||
// left | ||
float leftEar_x = head_x-earWidth/2; | ||
// right | ||
float rightEar_x = head_x+headWidth-earWidth/2; | ||
|
||
// BEGIN DRAWING | ||
// Draw head | ||
ellipse(head_x, head_y, headWidth, headHeight); | ||
// left eye | ||
ellipse(leftEye_x, eye_y, eyeWidth, eyeHeight); | ||
// Draw left iris | ||
ellipse(leftIris_x, eye_y, irisDiam, irisDiam); | ||
// Draw left pupil | ||
ellipse(leftPupil_x, eye_y+eyeHeight/2-pupilDiam/2, pupilDiam, pupilDiam); | ||
// Draw right eye | ||
ellipse(rightEye_x, eye_y, eyeWidth, eyeHeight); | ||
// Draw right iris | ||
ellipse(rightIris_x, eye_y, irisDiam, irisDiam); | ||
// Draw right pupil | ||
ellipse(rightPupil_x, eye_y+eyeHeight/2-pupilDiam/2, pupilDiam, pupilDiam); | ||
// Draw left eyebrow | ||
rect(leftEyeBrow_x, eyeBrow_y, eyeBrowWidth, eyeBrowHeight); | ||
// Draw right eyebrow | ||
rect(rightEyeBrow_x, eyeBrow_y, eyeBrowWidth, eyeBrowHeight); | ||
// Draw nose | ||
triangle(nose_x, nose_y, nose_x+eyeWidth, nose_y, nose_x + eyeWidth/2, nose_y-eyeWidth); | ||
// Draw Mouth - top lip | ||
arc(mouth_x, mouth_y-mouthHeight/2, mouthWidth, mouthHeight, PI, TWO_PI); | ||
// Draw Mouth - bottom lip | ||
arc(mouth_x, mouth_y-mouthHeight/2, mouthWidth, mouthHeight, 0, PI); | ||
// Draw Mouth – crease | ||
line(mouth_x, mouth_y, mouth_x+mouthWidth, mouth_y); | ||
// Draw left ear | ||
arc(leftEar_x, ear_y, earWidth, earHeight, PI/2.3, PI*1.55); | ||
// Draw right ear | ||
arc(rightEar_x, ear_y, earWidth, earHeight, -PI/1.8, PI/1.8); | ||
|
Binary file not shown.
43 changes: 43 additions & 0 deletions
43
CodeToAccompany9781430244646/ch02/arcs_example/arcs_example.pde
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/*------------------------------------------------------------ | ||
Copyright (c) 2013, friends of Ed (An Apress Company) | ||
All rights reserved. | ||
The code provided here accompanies the book: | ||
Processing: Creative Coding and Generative Art in Processing 2 | ||
By Ira Greenberg, Dianna Xu, and Deepak Kumar | ||
friends of Ed (An APress Company), 2013 | ||
ISBN-13 978-1430244646 | ||
Please refer to the associated README for a full disclaimer. | ||
------------------------------------------------------------*/ | ||
// arcs_example.pde, chapter 2 | ||
// Creates a page of randomized arcs. | ||
|
||
PFont font; | ||
|
||
void setup() { | ||
size(1000, 1000); | ||
background(255); | ||
fill(0); | ||
font = createFont("ArialMT-48.vlw", 20); | ||
textFont(font, 18); | ||
int cols = 4; | ||
int rows = 4; | ||
|
||
float cellW = width/cols; | ||
float cellH = height/rows; | ||
|
||
|
||
for (int i=0; i<rows; i++) { | ||
for (int j=0; j<cols; j++) { | ||
makeArc(cellW/2+cellW*j, cellH/2+cellH*i, cellW*.5, cellH*.5, random(PI), random(PI, TWO_PI)); | ||
} | ||
} | ||
} | ||
|
||
void makeArc(float x, float y, float w, float h, float t1, float t2) { | ||
arc(x, y, w, h, t1, t2); | ||
text("start = " + int(degrees(t1)) + " degs", x-w/2, y+h*.75); | ||
text("end = " + int(degrees(t2)) + " degs", x-w/2, y+h*.925); | ||
} | ||
|
Binary file not shown.
35 changes: 35 additions & 0 deletions
35
CodeToAccompany9781430244646/ch02/complex_algorithmic_face/complex_algorithmic_face.pde
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/*------------------------------------------------------------ | ||
Copyright (c) 2013, friends of Ed (An Apress Company) | ||
All rights reserved. | ||
The code provided here accompanies the book: | ||
Processing: Creative Coding and Generative Art in Processing 2 | ||
By Ira Greenberg, Dianna Xu, and Deepak Kumar | ||
friends of Ed (An APress Company), 2013 | ||
ISBN-13 978-1430244646 | ||
Please refer to the associated README for a full disclaimer. | ||
------------------------------------------------------------*/ | ||
// complex_algorithmic_face.pde, chapter 2 | ||
// Complex algorithmic approach to drawing a face using | ||
// functions and curves. | ||
|
||
// BEGIN DECLARE/INITIALIZE HEAD VARIABLES | ||
float headHeight = 600; | ||
float headWidth = headHeight*5/7; | ||
float head_x = (width-headWidth)/2; | ||
float head_y = (height-headHeight)/2; | ||
|
||
void setup() { | ||
size(600, 800); | ||
background(0); | ||
stroke(255); | ||
noFill(); | ||
|
||
ellipseMode(CORNER); | ||
translate(width/2, height/2); | ||
// Draw head | ||
head(head_x, head_y, headWidth, headHeight); | ||
|
||
} | ||
|
44 changes: 44 additions & 0 deletions
44
CodeToAccompany9781430244646/ch02/complex_algorithmic_face/ear.pde
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
void ear(float xTop, float yTop, float xBot, float yBot, float xRidge, float yRidge, float w, float h, int whichEar) { | ||
curveTightness(-1); | ||
pushMatrix(); | ||
|
||
if (whichEar == 0) { // left | ||
// outer ear | ||
beginShape(); | ||
curveVertex(xTop+10, yTop+85); | ||
curveVertex(xTop, yTop); | ||
curveVertex(xTop-w/2.3, yTop+35); | ||
curveVertex(xBot, yBot); | ||
curveVertex(xBot+w, yBot-30); | ||
endShape(); | ||
|
||
// innner ridge: | ||
beginShape(); | ||
curveVertex(xRidge, yRidge+80); | ||
curveVertex(xRidge, yRidge); | ||
curveVertex(xTop-w/2.3, yTop+35); | ||
curveVertex(xTop-w/2.5, yTop+175); | ||
endShape(); | ||
} | ||
else { // right | ||
// outer ear | ||
beginShape(); | ||
curveVertex(xTop+10, yTop+85); | ||
curveVertex(xTop, yTop); | ||
curveVertex(xTop+w/2.3, yTop+35); | ||
curveVertex(xBot, yBot); | ||
curveVertex(xBot-w, yBot-30); | ||
endShape(); | ||
|
||
// innner ridge: | ||
beginShape(); | ||
curveVertex(xRidge, yRidge+80); | ||
curveVertex(xRidge, yRidge); | ||
curveVertex(xTop+w/2.3, yTop+35); | ||
curveVertex(xTop+w/2.5, yTop+175); | ||
endShape(); | ||
} | ||
|
||
popMatrix(); | ||
} | ||
|
62 changes: 62 additions & 0 deletions
62
CodeToAccompany9781430244646/ch02/complex_algorithmic_face/eye.pde
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
void eye(float x, float y, float w, float h, int which) { | ||
float pupilDiam = h*.25; | ||
|
||
ellipseMode(CENTER); | ||
curveTightness(-.5); | ||
pushMatrix(); | ||
|
||
|
||
if (which == 0) { // left | ||
// top | ||
beginShape(); | ||
curveVertex(x+w, y); | ||
curveVertex(x, y+h/2); | ||
curveVertex(x+w/2, y); | ||
curveVertex(x+w, y+h/1.25); | ||
curveVertex(x+w, y+h/1.25); | ||
endShape(); | ||
|
||
// bottom | ||
beginShape(); | ||
curveVertex(x+w, y+h/1.25); | ||
curveVertex(x+w, y+h/1.25); | ||
curveVertex(x+w/2, y+h); | ||
curveVertex(x, y+h/2); | ||
curveVertex(x, y+h/2); | ||
//ellipse(x, y, 2, 2); | ||
endShape(); | ||
|
||
// iris | ||
ellipse((x+w/2), (y+h/2), h, h); | ||
// pupil | ||
ellipse((x+w/2), (y+h/2), pupilDiam, pupilDiam); | ||
} | ||
else { // right | ||
// top | ||
beginShape(); | ||
curveVertex(x, y); | ||
curveVertex(x+w, y+h/2); | ||
curveVertex(x+w/2, y); | ||
curveVertex(x, y+h/1.25); | ||
curveVertex(x, y+h/1.25); | ||
endShape(); | ||
|
||
// bottom | ||
beginShape(); | ||
curveVertex(x+w, y+h/2); | ||
curveVertex(x+w, y+h/2); | ||
curveVertex(x+w/2, y+h); | ||
curveVertex(x, y+h/1.25); | ||
curveVertex(x, y+h/1.25); | ||
endShape(); | ||
|
||
// iris | ||
ellipse((x+w/2), (y+h/2), h, h); | ||
// pupil | ||
ellipse((x+w/2), (y+h/2), pupilDiam, pupilDiam); | ||
} | ||
|
||
popMatrix(); | ||
ellipseMode(CORNER); | ||
} | ||
|
Oops, something went wrong.