Processing IDE Dersleri | Processing IDE Kurulumu | Processing IDE Programlama Dersleri
Merhabalar
Processing’de bazı genel kullanımlı metodlar vardır.
draw() , setup bunlardan en önemli olanlarıdır.
setup() metodu : Kendi içeriğinde bulunan kodu sadece program ilk derlendiğinde çalışır.Genel manada kullanacağını ortamın şekillendirirken tek seferde kullanıcak değerler yazılır.
draw() metodu : Kendi içeriğinde tekrar tekrar çalıştırılacak animasyon efekt gibi değerlerin yazıldığı bölümdür.
Yukarıdaki metodlar dışında değişkenlerimizi tanımlayabiliriz.
void setup() {
size(250,250);
}
int eksenX = 10;
int eksenY = 10;
void draw() {
background(185,60,0);
fill(10,10,255);
rect(eksenX, eksenY, 20, 20);
eksenX = eksenX + 1;
eksenY = eksenY + 1;
}
Senin favorin nedir? Pentagon? Altıgen? Heptagon mu? Hayır? İcosagon ne olacak? Bu örnek için oluşturulan poligon () işlevi, herhangi bir normal çokgeni çizebilir. Keşfetmek için draw () içindeki polygon () işlev çağrılarına farklı numaralar yerleştirmeyi deneyin.
void setup() {
size(640, 360);
}
void draw() {
background(102);
pushMatrix();
translate(width*0.2, height*0.5);
rotate(frameCount / 200.0);
polygon(0, 0, 82, 3); // Triangle
popMatrix();
pushMatrix();
translate(width*0.5, height*0.5);
rotate(frameCount / 50.0);
polygon(0, 0, 80, 20); // Icosagon
popMatrix();
pushMatrix();
translate(width*0.8, height*0.5);
rotate(frameCount / -100.0);
polygon(0, 0, 70, 7); // Heptagon
popMatrix();
}
void polygon(float x, float y, float radius, int npoints) {
float angle = TWO_PI / npoints;
beginShape();
for (float a = 0; a < TWO_PI; a += angle) {
float sx = x + cos(a) * radius;
float sy = y + sin(a) * radius;
vertex(sx, sy);
}
endShape(CLOSE);
}
Gözlerin yönünü değiştirmek için fareyi hareket ettirin. Atan2 () işlevi, her gözden imlece olan açıyı hesaplar.
Eye e1, e2, e3;
void setup() {
size(640, 360);
noStroke();
e1 = new Eye( 250, 16, 120);
e2 = new Eye( 164, 185, 80);
e3 = new Eye( 420, 230, 220);
}
void draw() {
background(102);
e1.update(mouseX, mouseY);
e2.update(mouseX, mouseY);
e3.update(mouseX, mouseY);
e1.display();
e2.display();
e3.display();
}
class Eye {
int x, y;
int size;
float angle = 0.0;
Eye(int tx, int ty, int ts) {
x = tx;
y = ty;
size = ts;
}
void update(int mx, int my) {
angle = atan2(my-y, mx-x);
}
void display() {
pushMatrix();
translate(x, y);
fill(255);
ellipse(0, 0, size, size);
rotate(angle);
fill(153, 204, 0);
ellipse(size/4, 0, size/2, size/2);
popMatrix();
}
}
Kutupsal bir koordinatı (r, teta) kartezyen'e (x, y) dönüştürün: x = rcos (theta) y = rsin (theta)
float r;
// Angle and angular velocity, accleration
float theta;
float theta_vel;
float theta_acc;
void setup() {
size(640, 360);
// Initialize all values
r = height * 0.45;
theta = 0;
theta_vel = 0;
theta_acc = 0.0001;
}
void draw() {
background(0);
// Translate the origin point to the center of the screen
translate(width/2, height/2);
// Convert polar to cartesian
float x = r * cos(theta);
float y = r * sin(theta);
// Draw the ellipse at the cartesian coordinate
ellipseMode(CENTER);
noStroke();
fill(200);
ellipse(x, y, 32, 32);
// Apply acceleration and velocity to angle (r remains static in this example)
theta_vel += theta_acc;
theta += theta_vel;
}
Konum atamak için 1D Perlin Noise kullanma.
float xoff = 0.0;
float xincrement = 0.01;
void setup() {
size(640, 360);
background(0);
noStroke();
}
void draw() {
// Create an alpha blended background
fill(0, 10);
rect(0,0,width,height);
//float n = random(0,width); // Try this line instead of noise
// Get a noise value based on xoff and scale it according to the window's width
float n = noise(xoff)*width;
// With each cycle, increment xoff
xoff += xincrement;
// Draw the ellipse at the value produced by perlin noise
fill(200);
ellipse(n,height/2, 64, 64);
}