-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHalftoner.pde
129 lines (103 loc) · 2.84 KB
/
Halftoner.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import drop.*;
SDrop drop;
PImage img;
import processing.pdf.*;
color elcolor = color(0);
//int imageHeight = img.height;
//int imageWidth = img.width;
void setup() {
//fullScreen();
size(1500,1700);
frameRate(60);
drop = new SDrop(this);
ellipseMode(CENTER);
img = loadImage("acme.jpg");
img.get () ;
noStroke();
smooth();
}
void draw() {
background( 255 );
fill( elcolor );
//translate(height/2, width/2);
// rotate(radians(millis() * 0.01));
// rotate(radians(30));
// translate(-height/2, -width/2);
if(img !=null) {
for (int y=0;y<img.height;y+=steps) {
for (int x=0;x<img.width;x+=steps) {
float val = ( red( img.get(x, y) ) + green( img.get(x, y) ) + blue( img.get(x, y) ) ) / 3;
float s = map(val, 0, 255, 1, 3 * scl );
s = (3 * scl) - s;
pushMatrix();
translate(0.5, 0.5);
shearX(PI);
ellipse(x*scl, y*scl, s * dotSize , s * dotSize );
popMatrix();
}
}
}
}
float dotSize = 1;
float scl = 2;
float steps1 = 3;
float steps = 3;
void keyPressed() {
switch(key) {
case('+'): scl+=0.09;break;
case('-'): scl-=0.09;break;
case('e'): export();break;
case('c'): elcolor = color(0, 255, 255);break;
case('m'): elcolor = color(255, 0, 255);break;
case('y'): elcolor = color(255, 255, 0);break;
case('k'): elcolor = color(0);break;
}
if (key == CODED) {
if (keyCode == UP) {
dotSize+=0.09;
println(dotSize);
text(dotSize, 20, 20);
} else if (keyCode == DOWN) {
dotSize-=0.09;
println("dotsize"+dotSize);
}
}
if (key == CODED) {
if (keyCode == LEFT) {
steps+=0.4;
} else if (keyCode == RIGHT) {
steps-=0.4;
}
}
}
void export() {
PGraphics exporting = createGraphics(int(img.width * scl) , int(img.height * scl), PDF, "foto-"+int(random(10000))+".pdf");
exporting.beginDraw();
exporting.image(img, 0, 0);
exporting.background( 255 );
exporting.fill( elcolor );
exporting.noStroke();
for (int y=0;y<img.height;y+=steps) {
for (int x=0;x<img.width;x+=steps) {
float val = ( red( img.get(x, y) ) + green( img.get(x, y) ) + blue( img.get(x, y) ) ) / 4;
float s = map(val, 0, 255, 1, 3 * scl );
s = (3 * scl) - s;
exporting.ellipse(x*scl, y*scl, s * dotSize , s * dotSize );
}
}
exporting.endDraw(); // stop and save pdf
exporting.dispose();
println("... done exporting.");
}
void dropEvent(DropEvent theDropEvent) {
println("");
println("isFile()\t"+theDropEvent.isFile());
println("isImage()\t"+theDropEvent.isImage());
println("isURL()\t"+theDropEvent.isURL());
// if the dropped object is an image, then
// load the image into our PImage.
if(theDropEvent.isImage()) {
println("### loading image ...");
img = theDropEvent.loadImage();
}
}