
参照画像を指定し起動した状態

ピックした色が右袖にスタックされる
my first processing output: color sampler
プロセシングのお勉強用に、カラーピッカーを作りながら、書き方を学習した。そんな習作。
-
任意の画像を指定のフォルダに入れ、ファイル名を指定するとウインドウに表示される。
カーソル位置がウインドウ右上に拡大表示され、カラーピックを補助する。
ピックした色は右袖にスタックされプレビューできる。
[s]キーで、ピックしたRGB値がタブ切りプレインテキストとして書き出される。
[p]キーで、pdf書き出しされ、illustratorなどpdf編集可能なアプリケーション上でそのままカラーオブジェクトとして使用可能。
//colorSAMPLER revision0127b by morh
import processing.pdf.*;
boolean saveOneFrame = false;
PImage a;
color [] d = new color[100];
int i, j, r;
int Mtx = 100;
PShape s;
int Rx,Ry;
void setup() {
// background(255);
noStroke();
a = loadImage(“536035974_fd6abacf00_o.jpg”);
size(a.width+Mtx, a.height);
s = loadShape(“colorsampler.svg”);
}
void draw() {
if (saveOneFrame == true) { // When the saveOneFrame boolean is true,
beginRecord(PDF, “lines.pdf”); // start recording to the PDF
}
image(a, 0,0, a.width,a.height);
//preview square
PImage crop = get(mouseX-Mtx/4, mouseY-Mtx/4,Mtx/2, Mtx/2);
image(crop, a.width, 0, Mtx, Mtx);
float H = float((height-Mtx)/(i+1));//list of previous colors
for (int j = 0; j < i; j++) {
fill(d[j]);
rectMode(CORNER);
rect(a.width, Mtx+H*j, a.width+Mtx, Mtx+H*(j+1));
}
color c = get(mouseX, mouseY); //preview of active color
fill(c);
rect(a.width, Mtx+H*i, a.width+Mtx, Mtx+H*(i+1));
stroke(255);//focus point in active color
line(a.width+(Mtx/2-5), Mtx/2, a.width+(Mtx/2+5), Mtx/2);
line(a.width+(Mtx/2), Mtx/2-5, a.width+(Mtx/2), Mtx/2+5);
noStroke();
//beheaver of logos
float dst = dist(a.width/2, a.height/2, mouseX, mouseY);
if((abs(dst)>a.width)||(abs(dst)>a.height/2)){
// if((mouseX>a.width)||(mouseX<0)||(mouseY>a.height)||(mouseY<0)){
// if(!(mouseX<a.width)||!(mouseY<a.height)){
smooth();//logo
int ofst = 15;
float hfofst = float(ofst/2);
int sh = 35;
// color bkgd = color(255, 255, 255, 40);//background color for low-key image
color bkgd = color(0, 0, 0, 50);
if(a.width>445){ //logos layout horizontal
strokeCap(SQUARE);
strokeWeight(ofst);
stroke(bkgd);
noFill();
rect(hfofst, hfofst, a.width-ofst, a.height-sh);
noStroke();
strokeWeight(1);
fill(bkgd);
rect(0, a.height-(sh-ofst), a.width, a.height);
shape(s, 10, height-30);
}
else {//logos layout vertical
strokeCap(SQUARE);
strokeWeight(ofst);
stroke(bkgd);
noFill();
rect(sh, hfofst, a.width-sh-hfofst, a.height-ofst);
noStroke();
strokeWeight(1);
fill(bkgd);
rect(0, 0, sh-hfofst, a.height);
pushMatrix();
translate(sh, 10);
rotate(PI/2);
shape(s,0,0);
popMatrix();
}
noStroke();
strokeWeight(1);
}
if (saveOneFrame == true) { // If the PDF has been recording,
endRecord(); // stop recording,
saveOneFrame = false; // and set the boolean value to false
}
}
void mousePressed() {
if(i<d.length){
d[i] = get(mouseX, mouseY);
i++;
}
}
void keyPressed() {
switch (key) {
case ’s’: // Press s key to save the value data
String[] lines = new String[d.length];
for (int i = 0; i < d.length; i++) {
lines[i] = str(red(d[i])) + “\t” + str(green(d[i])) + “\t” + str(blue(d[i]));
}
saveStrings(“lines.txt”, lines);
println(“Color Values Saved”);
break;
case ‘p’: //Press p key to print pdf
saveOneFrame = true; // trigger PDF recording within the draw()
println(“Image Printed”);
break;
case ‘r’:
if(i<d.length){
Rx =int(random(0, a.width));
Ry =int(random(0, a.height));
stroke(255);
line(Rx, 0, Rx, a.height);
line(0, Ry, a.width, Ry);
// d[i] = get(Rx, Ry);
noStroke();
break;
}
}
}
my first processing output: color sampler
プロセシングのお勉強用に、カラーピッカーを作りながら、書き方を学習した。そんな習作。
-
任意の画像を指定のフォルダに入れ、ファイル名を指定するとウインドウに表示される。
カーソル位置がウインドウ右上に拡大表示され、カラーピックを補助する。
ピックした色は右袖にスタックされプレビューできる。
[p]キーで、pdf書き出しされ、illustratorなどpdf編集可能なアプリケーション上でそのままカラー
オブジェクトとして使用可能。
[s]キーで、ピックしたRGB値がタブ切りプレインテキストとして書き出される。
//colorSAMPLER revision0127b by morh
import processing.pdf.*;
boolean saveOneFrame = false;
PImage a;
color [] d = new color[100];
int i, j, r;
int Mtx = 100;
PShape s;
int Rx,Ry;
void setup() {
// background(255);
noStroke();
a = loadImage(“536035974_fd6abacf00_o.jpg”);
size(a.width+Mtx, a.height);
s = loadShape(“colorsampler.svg”);
}
void draw() {
if (saveOneFrame == true) { // When the saveOneFrame boolean is true,
beginRecord(PDF, “lines.pdf”); // start recording to the PDF
}
image(a, 0,0, a.width,a.height);
//preview square
PImage crop = get(mouseX-Mtx/4, mouseY-Mtx/4,Mtx/2, Mtx/2);
image(crop, a.width, 0, Mtx, Mtx);
float H = float((height-Mtx)/(i+1));//list of previous colors
for (int j = 0; j < i; j++) {
fill(d[j]);
rectMode(CORNER);
rect(a.width, Mtx+H*j, a.width+Mtx, Mtx+H*(j+1));
}
color c = get(mouseX, mouseY); //preview of active color
fill(c);
rect(a.width, Mtx+H*i, a.width+Mtx, Mtx+H*(i+1));
stroke(255);//focus point in active color
line(a.width+(Mtx/2-5), Mtx/2, a.width+(Mtx/2+5), Mtx/2);
line(a.width+(Mtx/2), Mtx/2-5, a.width+(Mtx/2), Mtx/2+5);
noStroke();
//beheaver of logos
float dst = dist(a.width/2, a.height/2, mouseX, mouseY);
if((abs(dst)>a.width)||(abs(dst)>a.height/2)){
// if((mouseX>a.width)||(mouseX<0)||(mouseY>a.height)||(mouseY<0)){
// if(!(mouseX<a.width)||!(mouseY<a.height)){
smooth();//logo
int ofst = 15;
float hfofst = float(ofst/2);
int sh = 35;
// color bkgd = color(255, 255, 255, 40);//background color for low-key image
color bkgd = color(0, 0, 0, 50);
if(a.width>445){ //logos layout horizontal
strokeCap(SQUARE);
strokeWeight(ofst);
stroke(bkgd);
noFill();
rect(hfofst, hfofst, a.width-ofst, a.height-sh);
noStroke();
strokeWeight(1);
fill(bkgd);
rect(0, a.height-(sh-ofst), a.width, a.height);
shape(s, 10, height-30);
}
else {//logos layout vertical
strokeCap(SQUARE);
strokeWeight(ofst);
stroke(bkgd);
noFill();
rect(sh, hfofst, a.width-sh-hfofst, a.height-ofst);
noStroke();
strokeWeight(1);
fill(bkgd);
rect(0, 0, sh-hfofst, a.height);
pushMatrix();
translate(sh, 10);
rotate(PI/2);
shape(s,0,0);
popMatrix();
}
noStroke();
strokeWeight(1);
}
if (saveOneFrame == true) { // If the PDF has been recording,
endRecord(); // stop recording,
saveOneFrame = false; // and set the boolean value to false
}
}
void mousePressed() {
if(i<d.length){
d[i] = get(mouseX, mouseY);
i++;
}
}
void keyPressed() {
switch (key) {
case ’s’: // Press s key to save the value data
String[] lines = new String[d.length];
for (int i = 0; i < d.length; i++) {
lines[i] = str(red(d[i])) + “\t” + str(green(d[i])) + “\t” + str(blue(d[i]));
}
saveStrings(“lines.txt”, lines);
println(“Color Values Saved”);
break;
case ‘p’: //Press p key to print pdf
saveOneFrame = true; // trigger PDF recording within the draw()
println(“Image Printed”);
break;
case ‘r’:
if(i<d.length){
Rx =int(random(0, a.width));
Ry =int(random(0, a.height));
stroke(255);
line(Rx, 0, Rx, a.height);
line(0, Ry, a.width, Ry);
// d[i] = get(Rx, Ry);
noStroke();
break;
}
}
}