Processing IDE Dersleri | Processing IDE Kurulumu | Processing IDE Programlama Dersleri
Bu örnek, programda bir sayı yerine bir adla başvurulabilecek renkler için değişkenler oluşturur.
size(640, 360);
noStroke();
background(51, 0, 0);
color inside = color(204, 102, 0);
color middle = color(204, 153, 0);
color outside = color(153, 51, 0);
// These statements are equivalent to the statements above.
// Programmers may use the format they prefer.
//color inside = #CC6600;
//color middle = #CC9900;
//color outside = #993300;
pushMatrix();
translate(80, 80);
fill(outside);
rect(0, 0, 200, 200);
fill(middle);
rect(40, 60, 120, 120);
fill(inside);
rect(60, 90, 80, 80);
popMatrix();
pushMatrix();
translate(360, 80);
fill(inside);
rect(0, 0, 200, 200);
fill(outside);
rect(40, 60, 120, 120);
fill(middle);
rect(60, 90, 80, 80);
popMatrix();
Her bir renk diğer renklere göre algılanır. Üst ve alt çubukların her biri aynı bileşen renklerini içerir, ancak farklı bir görüntü sırası, tek tek renklerin farklı görünmesine neden olur.
color a, b, c, d, e;
void setup() {
size(640, 360);
noStroke();
a = color(165, 167, 20);
b = color(77, 86, 59);
c = color(42, 106, 105);
d = color(165, 89, 20);
e = color(146, 150, 127);
noLoop(); // Draw only one time
}
void draw() {
drawBand(a, b, c, d, e, 0, width/128);
drawBand(c, a, d, b, e, height/2, width/128);
}
void drawBand(color v, color w, color x, color y, color z, int ypos, int barWidth) {
int num = 5;
color[] colorOrder = { v, w, x, y, z };
for(int i = 0; i < width; i += barWidth*num) {
for(int j = 0; j < num; j++) {
fill(colorOrder[j]);
rect(i+j*barWidth, ypos, barWidth, height/2);
}
}
}
Ton, bir nesneden yansıyan veya nesneden iletilen renktir ve genellikle rengin adı olarak anılır (kırmızı, mavi, sarı, vb.) Tonunu değiştirmek için imleci her çubuğun üzerinde dikey olarak hareket ettirin.
int barWidth = 20;
int lastBar = -1;
void setup()
{
size(640, 360);
colorMode(HSB, height, height, height);
noStroke();
background(0);
}
void draw()
{
int whichBar = mouseX / barWidth;
if (whichBar != lastBar) {
int barX = whichBar * barWidth;
fill(mouseY, height, height);
rect(barX, 0, barWidth, height);
lastBar = whichBar;
}
}
Bir renkten diğerine degrade oluşturmak için bir dizi eş merkezli daire çizer.
int dim;
void setup() {
size(640, 360);
dim = width/2;
background(0);
colorMode(HSB, 360, 100, 100);
noStroke();
ellipseMode(RADIUS);
frameRate(1);
}
void draw() {
background(0);
for (int x = 0; x <= width; x+=dim) {
drawGradient(x, height/2);
}
}
void drawGradient(float x, float y) {
int radius = dim/2;
float h = random(0, 360);
for (int r = radius; r > 0; --r) {
fill(h, 90, 90);
ellipse(x, y, r, r);
h = (h + 1) % 360;
}
}