Skip to content

Commit d2c19f0

Browse files
committed
tweaks and fixes
1 parent 3534022 commit d2c19f0

2 files changed

Lines changed: 61 additions & 32 deletions

File tree

content/examples/Basics/Color/Reading/Reading.pde

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,42 @@
55
* The many colors of the image are created through modulating the
66
* red, green, and blue values. This is an exageration of an LCD display.
77
*/
8-
8+
99
size(200, 200);
1010
noStroke();
1111
background(0);
1212

1313
// Load an image from the data directory
14-
PImage c;
15-
c = loadImage("cait.jpg");
14+
PImage img = loadImage("cait.jpg");
15+
img.loadPixels();
1616

17-
int xoff = 0;
18-
int yoff = 0;
19-
int p = 2;
20-
int pix = p*3;
17+
// figure out how big to make each block based on
18+
// the sketch area and the size of the input image
19+
int eachW = width / img.width;
20+
int eachH = height / img.height;
21+
int each = min(eachW, eachH);
22+
// vertical stripes will be a third as wide
23+
int stripeW = each / 3;
24+
// make sure the block size is a multiple of 3
25+
each = 3 * stripeW;
2126

27+
int left = (width - (img.width * each)) / 2;
28+
int top = (height - (img.height * each)) / 2;
2229

23-
for(int i = 0; i < c.width*c.height; i += 1)
24-
{
25-
int here = c.pixels[i];
26-
27-
fill(red(here), 0, 0);
28-
rect(xoff, yoff, p, pix);
29-
30-
fill(0, green(here), 0);
31-
rect(xoff+p, yoff, p, pix);
30+
for (int y = 0; y < img.height; y++) {
31+
int y1 = top + y*each;
3232

33-
fill(0, 0, blue(here));
34-
rect(xoff+p*2, yoff, p, pix);
35-
36-
xoff+=pix;
37-
if(xoff >= width-pix) {
38-
xoff = 0;
39-
yoff += pix;
33+
for (int x = 0; x < img.width; x++) {
34+
int pixel = img.get(x, y);
35+
int x1 = left + x*each;
36+
37+
fill(red(pixel), 0, 0);
38+
rect(x1 + stripeW*0, y1, stripeW, each);
39+
40+
fill(0, green(pixel), 0);
41+
rect(x1 + stripeW*1, y1, stripeW, each);
42+
43+
fill(0, 0, blue(pixel));
44+
rect(x1 + stripeW*2, y1, stripeW, each);
4045
}
4146
}
42-

content/examples/Basics/Input/Clock/Clock.pde

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,61 @@
44
* The current time can be read with the second(), minute(),
55
* and hour() functions. In this example, sin() and cos() values
66
* are used to set the position of the hands.
7+
*
8+
* Updated 27 February 2010 to handle size() changes.
79
*/
810

11+
int cx, cy;
12+
float secondsRadius;
13+
float minutesRadius;
14+
float hoursRadius;
15+
float clockDiameter;
16+
917
void setup() {
1018
size(200, 200);
1119
stroke(255);
1220
smooth();
21+
22+
int radius = min(width, height) / 2;
23+
secondsRadius = radius * 0.72;
24+
minutesRadius = radius * 0.60;
25+
hoursRadius = radius * 0.50;
26+
clockDiameter = radius * 1.8;
27+
28+
cx = width / 2;
29+
cy = height / 2;
1330
}
14-
void draw() {
31+
32+
void draw2() {
1533
background(0);
34+
35+
// Draw the clock background
1636
fill(80);
1737
noStroke();
38+
ellipse(cx, cy, clockDiameter, clockDiameter);
39+
1840
// Angles for sin() and cos() start at 3 o'clock;
1941
// subtract HALF_PI to make them start at the top
20-
ellipse(100, 100, 160, 160);
2142
float s = map(second(), 0, 60, 0, TWO_PI) - HALF_PI;
2243
float m = map(minute() + norm(second(), 0, 60), 0, 60, 0, TWO_PI) - HALF_PI;
2344
float h = map(hour() + norm(minute(), 0, 60), 0, 24, 0, TWO_PI * 2) - HALF_PI;
45+
46+
// Draw the hands of the clock
2447
stroke(255);
2548
strokeWeight(1);
26-
line(100, 100, cos(s) * 72 + 100, sin(s) * 72 + 100);
49+
line(cx, cy, cx + cos(s) * secondsRadius, cy + sin(s) * secondsRadius);
2750
strokeWeight(2);
28-
line(100, 100, cos(m) * 60 + 100, sin(m) * 60 + 100);
51+
line(cx, cy, cx + cos(m) * minutesRadius, cy + sin(m) * minutesRadius);
2952
strokeWeight(4);
30-
line(100, 100, cos(h) * 50 + 100, sin(h) * 50 + 100);
53+
line(cx, cy, cx + cos(h) * hoursRadius, cy + sin(h) * hoursRadius);
3154

3255
// Draw the minute ticks
3356
strokeWeight(2);
57+
beginShape(POINTS);
3458
for (int a = 0; a < 360; a+=6) {
35-
float x = 100 + ( cos(radians(a)) * 72 );
36-
float y = 100 + ( sin(radians(a)) * 72 );
37-
point(x, y);
59+
float x = cx + cos(radians(a)) * secondsRadius;
60+
float y = cy + sin(radians(a)) * secondsRadius;
61+
vertex(x, y);
3862
}
63+
endShape();
3964
}

0 commit comments

Comments
 (0)