Processing IDE Dersleri | Processing IDE Kurulumu | Processing IDE Programlama Dersleri
İmleç üzerine geldiğinde "tickle" kelimesi titriyor. Bazen ekrandan gıdıklanabilir.
String message = "tickle";
float x, y; // X and Y coordinates of text
float hr, vr; // horizontal and vertical radius of the text
void setup() {
size(640, 360);
// Create the font
textFont(createFont("SourceCodePro-Regular.ttf", 36));
textAlign(CENTER, CENTER);
hr = textWidth(message) / 2;
vr = (textAscent() + textDescent()) / 2;
noStroke();
x = width / 2;
y = height / 2;
}
void draw() {
// Instead of clearing the background, fade it by drawing
// a semi-transparent rectangle on top
fill(204, 120);
rect(0, 0, width, height);
// If the cursor is over the text, change the position
if (abs(mouseX - x) < hr &&
abs(mouseY - y) < vr) {
x += random(-5, 5);
y += random(-5, 5);
}
fill(0);
text("tickle", x, y);
}
Bir çizgi parçası imleç tarafından itilir ve çekilir.
float x = 100;
float y = 100;
float angle1 = 0.0;
float segLength = 50;
void setup() {
size(640, 360);
strokeWeight(20.0);
stroke(255, 100);
}
void draw() {
background(0);
float dx = mouseX - x;
float dy = mouseY - y;
angle1 = atan2(dy, dx);
x = mouseX - (cos(angle1) * segLength);
y = mouseY - (sin(angle1) * segLength);
segment(x, y, angle1);
ellipse(x, y, 20, 20);
}
void segment(float x, float y, float a) {
pushMatrix();
translate(x, y);
rotate(a);
line(0, 0, segLength, 0);
popMatrix();
}
İmleç konumunu iki parçalı bir kol takip eder. Segmentler arasındaki bağıl açı atan2 () ile, konum ise sin () ve cos () ile hesaplanır.
float[] x = new float[2];
float[] y = new float[2];
float segLength = 50;
void setup() {
size(640, 360);
strokeWeight(20.0);
stroke(255, 100);
}
void draw() {
background(0);
dragSegment(0, mouseX, mouseY);
dragSegment(1, x[0], y[0]);
}
void dragSegment(int i, float xin, float yin) {
float dx = xin - x[i];
float dy = yin - y[i];
float angle = atan2(dy, dx);
x[i] = xin - cos(angle) * segLength;
y[i] = yin - sin(angle) * segLength;
segment(x[i], y[i], angle);
}
void segment(float x, float y, float a) {
pushMatrix();
translate(x, y);
rotate(a);
line(0, 0, segLength, 0);
popMatrix();
}
Parçalı bir çizgi fareyi takip eder. Her bir segmentten diğerine olan göreceli açı atan2 () ile hesaplanır ve bir sonrakinin konumu sin () ve cos () ile hesaplanır.
float[] x = new float[20];
float[] y = new float[20];
float segLength = 18;
void setup() {
size(640, 360);
strokeWeight(9);
stroke(255, 100);
}
void draw() {
background(0);
dragSegment(0, mouseX, mouseY);
for(int i=0; i<x.length-1; i++) {
dragSegment(i+1, x[i], y[i]);
}
}
void dragSegment(int i, float xin, float yin) {
float dx = xin - x[i];
float dy = yin - y[i];
float angle = atan2(dy, dx);
x[i] = xin - cos(angle) * segLength;
y[i] = yin - sin(angle) * segLength;
segment(x[i], y[i], angle);
}
void segment(float x, float y, float a) {
pushMatrix();
translate(x, y);
rotate(a);
line(0, 0, segLength, 0);
popMatrix();
}
Kol, atan2 () ile açıları hesaplayarak farenin konumunu takip eder.
float segLength = 80;
float x, y, x2, y2;
void setup() {
size(640, 360);
strokeWeight(20.0);
stroke(255, 100);
x = width/2;
y = height/2;
x2 = x;
y2 = y;
}
void draw() {
background(0);
float dx = mouseX - x;
float dy = mouseY - y;
float angle1 = atan2(dy, dx);
float tx = mouseX - cos(angle1) * segLength;
float ty = mouseY - sin(angle1) * segLength;
dx = tx - x2;
dy = ty - y2;
float angle2 = atan2(dy, dx);
x = x2 + cos(angle2) * segLength;
y = y2 + sin(angle2) * segLength;
segment(x, y, angle1);
segment(x2, y2, angle2);
}
void segment(float x, float y, float a) {
pushMatrix();
translate(x, y);
rotate(a);
line(0, 0, segLength, 0);
popMatrix();
}
Kol, atan2 () ile açıları hesaplayarak farenin konumunu takip eder.
int numSegments = 10;
float[] x = new float[numSegments];
float[] y = new float[numSegments];
float[] angle = new float[numSegments];
float segLength = 26;
float targetX, targetY;
void setup() {
size(640, 360);
strokeWeight(20.0);
stroke(255, 100);
x[x.length-1] = width/2; // Set base x-coordinate
y[x.length-1] = height; // Set base y-coordinate
}
void draw() {
background(0);
reachSegment(0, mouseX, mouseY);
for(int i=1; i<numSegments; i++) {
reachSegment(i, targetX, targetY);
}
for(int i=x.length-1; i>=1; i--) {
positionSegment(i, i-1);
}
for(int i=0; i<x.length; i++) {
segment(x[i], y[i], angle[i], (i+1)*2);
}
}
void positionSegment(int a, int b) {
x[b] = x[a] + cos(angle[a]) * segLength;
y[b] = y[a] + sin(angle[a]) * segLength;
}
void reachSegment(int i, float xin, float yin) {
float dx = xin - x[i];
float dy = yin - y[i];
angle[i] = atan2(dy, dx);
targetX = xin - cos(angle[i]) * segLength;
targetY = yin - sin(angle[i]) * segLength;
}
void segment(float x, float y, float a, float sw) {
strokeWeight(sw);
pushMatrix();
translate(x, y);
rotate(a);
line(0, 0, segLength, 0);
popMatrix();
}
Kol, atan2 () ile açıları hesaplayarak topun konumunu takip eder.
int numSegments = 8;
float[] x = new float[numSegments];
float[] y = new float[numSegments];
float[] angle = new float[numSegments];
float segLength = 26;
float targetX, targetY;
float ballX = 50;
float ballY = 50;
int ballXDirection = 1;
int ballYDirection = -1;
void setup() {
size(640, 360);
strokeWeight(20.0);
stroke(255, 100);
noFill();
x[x.length-1] = width/2; // Set base x-coordinate
y[x.length-1] = height; // Set base y-coordinate
}
void draw() {
background(0);
strokeWeight(20);
ballX = ballX + 1.0 * ballXDirection;
ballY = ballY + 0.8 * ballYDirection;
if(ballX > width-25 || ballX < 25) {
ballXDirection *= -1;
}
if(ballY > height-25 || ballY < 25) {
ballYDirection *= -1;
}
ellipse(ballX, ballY, 30, 30);
reachSegment(0, ballX, ballY);
for(int i=1; i<numSegments; i++) {
reachSegment(i, targetX, targetY);
}
for(int i=x.length-1; i>=1; i--) {
positionSegment(i, i-1);
}
for(int i=0; i<x.length; i++) {
segment(x[i], y[i], angle[i], (i+1)*2);
}
}v
oid positionSegment(int a, int b) {
x[b] = x[a] + cos(angle[a]) * segLength;
y[b] = y[a] + sin(angle[a]) * segLength;
}
void reachSegment(int i, float xin, float yin) {
float dx = xin - x[i];
float dy = yin - y[i];
angle[i] = atan2(dy, dx);
targetX = xin - cos(angle[i]) * segLength;
targetY = yin - sin(angle[i]) * segLength;
}
void segment(float x, float y, float a, float sw) {
strokeWeight(sw);
pushMatrix();
translate(x, y);
rotate(a);
line(0, 0, segLength, 0);
popMatrix();
}