xxxxxxxxxx
let suSeviyesi = 20;
let pompagövdesiX = 185;
let pompagövdesiY = 40;
let pompagövdesiWidth = 30;
let pompagövdesiHeight = 40;
let boru1X = 230;
let boru1Y = 75;
let boru1Width = 60;
let boru1Height = 10;
let boru2X = 280;
let boru2Y = 75;
let boru2Width = 10;
let boru2Height = 30;
let pompatepesiX = 195;
let pompatepesiY = 105;
let pompatepesiWidth = 10;
let pompatepesiHeight = 190;
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
let şişeHeight = 200;
let şişeWidth = 120;
let boyunHeight = 30;
let boyunWidth = 60;
let şişeX = width / 2 - şişeWidth / 2;
let şişeY = height / 2 - şişeHeight / 2;
// Damacana gövdesi
fill(200);
strokeWeight(5);
rect(şişeX, şişeY, şişeWidth, şişeHeight, 20);
// Pompa Gövdesi
fill(255);
strokeWeight(5);
rect(pompagövdesiX, pompagövdesiY, pompagövdesiWidth, pompagövdesiHeight);
// Pompa
fill(97, 221, 255);
strokeWeight(5);
rect(şişeX + (şişeWidth - boyunWidth) / 2, şişeY - boyunHeight, boyunWidth, boyunHeight, 5);
// Pompa Boruları
fill(97, 221, 255);
strokeWeight(5);
rect(boru1X, boru1Y, boru1Width, boru1Height);
fill(97, 221, 255);
strokeWeight(5);
rect(boru2X, boru2Y, boru2Width, boru2Height);
fill(255);
strokeWeight(5);
rect(pompatepesiX, pompatepesiY, pompatepesiWidth, pompatepesiHeight);
// Su Seviyesi
fill(3, 140, 252);
strokeWeight(5);
rect(şişeX, şişeY + (şişeHeight - suSeviyesi), şişeWidth, suSeviyesi, 20);
}
function keyPressed() {
// F tuşuna basıldığında
if (key === "f" || key === "F") {
let randomIncrease = random(0, 200); // Rastgele artış miktarı
let randomDecrease = random(0, -200); // Rastgele azalma miktarı
suSeviyesi += randomIncrease; // Su seviyesini rastgele artır
suSeviyesi += randomDecrease; // Su seviyesini rastgele azalt
suSeviyesi = constrain(suSeviyesi, 20, 200); // Su seviyesini 20 ile 200 arasında tut
}
}
//Decompose:
//The code assembles different elements to create an object. Each visual element is treated separately.
//While setup() and draw() functions execute the main functionalities, the keyPressed() function changes the water level when a specific key is pressed.
//Variables store different properties, enhancing the code's readability.
//Pattern Recognition:
//The code uses simple shapes to draw elements using P5.js, such as "rect".
//The random change in the water level follows a constrained pattern.
//Abstraction:
//The code simplifies real objects. For example, the jug, pump, and pipes are represented by simple rectangles.
//Variables represent specific properties. For instance, waterLevel represents the water level, while bottleHeight and bottleWidth represent the dimensions of the jug.
//The code performs functions like changing the water level when a specific key is pressed, allowing for different variations.
//Algorithm:
//An algorithm is used to animate the changing water level.
//For each frame, the water level is randomly altered, providing continuous variation.
//An algorithm is used to change the water level when a specific key is pressed.
//The keyPressed() function precisely fulfills this function.