Processing IDE Dersleri | Processing IDE Kurulumu | Processing IDE Programlama Dersleri
Bir tarayıcıda bir URL açmak için düğmeye tıklayın
boolean overButton = false;
void setup() {
size(640, 360);
}
void draw() {
background(204);
if (overButton == true) {
fill(255);
} else {
noFill();
}
rect(105, 60, 75, 75);
line(135, 105, 155, 85);
line(140, 85, 155, 85);
line(155, 85, 155, 100);
}
void mousePressed() {
if (overButton) {
link("https://sites.google.com/view/ardunoprojectturkey/ana-sayfa/processingide");
}
}
void mouseMoved() {
checkButtons();
}
void mouseDragged() {
checkButtons();
}
void checkButtons() {
if (mouseX > 105 && mouseX < 180 && mouseY > 60 && mouseY <135) {
overButton = true;
} else {
overButton = false;
}
}
Gövdeler üzerinde etkili olan çoklu kuvvetin gösterilmesi (Mover sınıfı) Gövdeler sürekli olarak yerçekimine maruz kalır Gövdeler "su" içindeyken sıvı direnci yaşarlar * PVector ile çalışmanın temelleri için.
// Five moving bodies
Mover[] movers = new Mover[10];
// Liquid
Liquid liquid;
void setup() {
size(640, 360);
reset();
// Create liquid object
liquid = new Liquid(0, height/2, width, height/2, 0.1);
}
void draw() {
background(0);
// Draw water
liquid.display();
for (Mover mover : movers) {
// Is the Mover in the liquid?
if (liquid.contains(mover)) {
// Calculate drag force
PVector drag = liquid.drag(mover);
// Apply drag force to Mover
mover.applyForce(drag);
}
// Gravity is scaled by mass here!
PVector gravity = new PVector(0, 0.1*mover.mass);
// Apply gravity
mover.applyForce(gravity);
// Update and display
mover.update();
mover.display();
mover.checkEdges();
}
fill(255);
text("click mouse to reset", 10, 30);
}
void mousePressed() {
reset();
}
// Restart all the Mover objects randomly
void reset() {
for (int i = 0; i < movers.length; i++) {
movers[i] = new Mover(random(0.5, 3), 40+i*70, 0);
}
}
/**
* Forces (Gravity and Fluid Resistence) with Vectors
* by Daniel Shiffman.
*
* Demonstration of multiple force acting on bodies (Mover class)
* Bodies experience gravity continuously
* Bodies experience fluid resistance when in "water"
*/
class Mover {
// position, velocity, and acceleration
PVector position;
PVector velocity;
PVector acceleration;
// Mass is tied to size
float mass;
Mover(float m, float x, float y) {
mass = m;
position = new PVector(x, y);
velocity = new PVector(0, 0);
acceleration = new PVector(0, 0);
}
// Newton's 2nd law: F = M * A
// or A = F / M
void applyForce(PVector force) {
// Divide by mass
PVector f = PVector.div(force, mass);
// Accumulate all forces in acceleration
acceleration.add(f);
}
void update() {
// Velocity changes according to acceleration
velocity.add(acceleration);
// position changes by velocity
position.add(velocity);
// We must clear acceleration each frame
acceleration.mult(0);
}
// Draw Mover
void display() {
stroke(255);
strokeWeight(2);
fill(255, 200);
ellipse(position.x, position.y, mass*16, mass*16);
}
// Bounce off bottom of window
void checkEdges() {
if (position.y > height) {
velocity.y *= -0.9; // A little dampening when hitting the bottom
position.y = height;
}
}
}
/**
* Forces (Gravity and Fluid Resistence) with Vectors
* by Daniel Shiffman.
*
* Demonstration of multiple force acting on bodies (Mover class)
* Bodies experience gravity continuously
* Bodies experience fluid resistance when in "water"
*/
// Liquid class
class Liquid {
// Liquid is a rectangle
float x, y, w, h;
// Coefficient of drag
float c;
Liquid(float x_, float y_, float w_, float h_, float c_) {
x = x_;
y = y_;
w = w_;
h = h_;
c = c_;
}
// Is the Mover in the Liquid?
boolean contains(Mover m) {
PVector l = m.position;
if (l.x > x && l.x < x + w && l.y > y && l.y < y + h) {
return true;
} else {
return false;
}
}
// Calculate drag force
PVector drag(Mover m) {
// Magnitude is coefficient * speed squared
float speed = m.velocity.mag();
float dragMagnitude = c * speed * speed;
// Direction is inverse of velocity
PVector drag = m.velocity.copy();
drag.mult(-1);
// Scale according to magnitude
drag.setMag(dragMagnitude);
return drag;
}
void display() {
noStroke();
fill(127);
rect(x, y, w, h);
}
}
Bu örnek, değişken sayıda nesneyi depolamak için Java ArrayList'in nasıl kullanılacağını gösterir. ArrayList'e öğeler eklenebilir ve buradan kaldırılabilir. * Zıplayan toplar eklemek için fareyi tıklayın.
ArrayList<Ball> balls;
int ballWidth = 48;
void setup() {
size(640, 360);
noStroke();
// Create an empty ArrayList (will store Ball objects)
balls = new ArrayList<Ball>();
// Start by adding one element
balls.add(new Ball(width/2, 0, ballWidth));
}
void draw() {
background(255);
// With an array, we say balls.length, with an ArrayList, we say balls.size()
// The length of an ArrayList is dynamic
// Notice how we are looping through the ArrayList backwards
// This is because we are deleting elements from the list
for (int i = balls.size()-1; i >= 0; i--) {
// An ArrayList doesn't know what it is storing so we have to cast the object coming out
Ball ball = balls.get(i);
ball.move();
ball.display();
if (ball.finished()) {
// Items can be deleted with remove()
balls.remove(i);
}
}
}
void mousePressed() {
// A new ball object is added to the ArrayList (by default to the end)
balls.add(new Ball(mouseX, mouseY, ballWidth));
}
// Simple bouncing ball class
class Ball {
float x;
float y;
float speed;
float gravity;
float w;
float life = 255;
Ball(float tempX, float tempY, float tempW) {
x = tempX;
y = tempY;
w = tempW;
speed = 0;
gravity = 0.1;
}
void move() {
// Add gravity to speed
speed = speed + gravity;
// Add speed to y location
y = y + speed;
// If square reaches the bottom
// Reverse speed
if (y > height) {
// Dampening
speed = speed * -0.8;
y = height;
}
}
boolean finished() {
// Balls fade out
life--;
if (life < 0) {
return true;
} else {
return false;
}
}
void display() {
// Display the circle
fill(0,life);
//stroke(0,life);
ellipse(x,y,w,w);
}
}
Arka planın rengini değiştirmek için görüntünün ortasındaki renkli şekillerden birine tıklayın.
int rectX, rectY; // Position of square button
int circleX, circleY; // Position of circle button
int rectSize = 90; // Diameter of rect
int circleSize = 93; // Diameter of circle
color rectColor, circleColor, baseColor;
color rectHighlight, circleHighlight;
color currentColor;
boolean rectOver = false;
boolean circleOver = false;
void setup() {
size(640, 360);
rectColor = color(0);
rectHighlight = color(51);
circleColor = color(255);
circleHighlight = color(204);
baseColor = color(102);
currentColor = baseColor;
circleX = width/2+circleSize/2+10;
circleY = height/2;
rectX = width/2-rectSize-10;
rectY = height/2-rectSize/2;
ellipseMode(CENTER);
}
void draw() {
update(mouseX, mouseY);
background(currentColor);
if (rectOver) {
fill(rectHighlight);
} else {
fill(rectColor);
}
stroke(255);
rect(rectX, rectY, rectSize, rectSize);
if (circleOver) {
fill(circleHighlight);
} else {
fill(circleColor);
}
stroke(0);
ellipse(circleX, circleY, circleSize, circleSize);
}
void update(int x, int y) {
if ( overCircle(circleX, circleY, circleSize) ) {
circleOver = true;
rectOver = false;
} else if ( overRect(rectX, rectY, rectSize, rectSize) ) {
rectOver = true;
circleOver = false;
} else {
circleOver = rectOver = false;
}
}
void mousePressed() {
if (circleOver) {
currentColor = circleColor;
}
if (rectOver) {
currentColor = rectColor;
}
}
boolean overRect(int x, int y, int width, int height) {
if (mouseX >= x && mouseX <= x+width &&
mouseY >= y && mouseY <= y+height) {
return true;
} else {
return false;
}
}
boolean overCircle(int x, int y, int diameter) {
float disX = x - mouseX;
float disY = y - mouseY;
if (sqrt(sq(disX) + sq(disY)) < diameter/2 ) {
return true;
} else {
return false;
}
}