“Terraform” by telfir32
https://openprocessing.org/sketch/877049
License CreativeCommons Attribution ShareAlike
https://creativecommons.org/licenses/by-sa/3.0
{{filePath}}
{{width}} x {{height}}
Report Sketch
Oh, that naughty sketch! Please let us know what the issue is below.
Apply Template
Applying this template will reset your sketch and remove all your changes. Are you sure you would like to continue?
Report Sketch
Report Comment
Please confirm that you would like to report the comment below.
We will review your submission and take any actions necessary per our Community Guidelines. In addition to reporting this comment, you can also block the user to prevent any future interactions.
Please report comments only when necessary. Unnecessary or abusive use of this tool may result in your own account being suspended.
Are you sure you want to delete your sketch?
Any files uploaded will be deleted as well.
Delete Comment?
This will also delete all the replies to this comment.
Delete this tab? Any code in it will be deleted as well.
Select a collection to submit your sketch
We Need Your Support
Since 2008, OpenProcessing has provided tools for creative coders to learn, create, and share over a million open source projects in a friendly environment.
Niche websites like ours need your continued support for future development and maintenance, while keeping it an ad-free platform that respects your data and privacy!
Please consider subscribing below to show your support with a "Plus" badge on your profile and get access to many other features!
CC Attribution ShareAlike
Terraform
xxxxxxxxxx
int cell_all_x = 15;
int cell_all_y = 10;
float [][] plants = new float[cell_all_x][cell_all_y];
int x_step; // ширина шага между ячейками
int y_step; // высота шага между ячейками
// Интерфейс
int interface_width = 300; // ширина интерфейса
int interface_colors[] = {0, 0, 0}; /// цвет интерфейса в RGB
int text_step_y = 50;
int text_step_x = 170;
PFont myFont; // текст
int gameboard_width; // ширина игрового поля
int interface_x0; // координата по x, с которой начинается интерфейс
int x; // координаты курсора мыши
int y;
int cell_x; // ячейки по x и y, в которых находится курсор (активная ячейка)
int cell_y;
int cell_number; // номер активной ячейки (в которой находится курсор)
// Растения
float plant_number; // количество растений в активной ячейке
float plant_step = 10; // количество прибавляющихся растений
void setup() {
size (1000, 500);
stroke(0);
fill (0);
myFont = createFont("TimesNewRoman", 14);
textFont(myFont, 15);
// рандомная растительность
for (int i = 0; i < cell_all_x; i++) {
for (int j = 0; j < cell_all_y; j++) {
plants[i][j] = int(random(255));
}
}
gameboard_width = width - interface_width;
interface_x0 = gameboard_width + 20;
}
void draw() {
background(255);
x_step = int ( gameboard_width / cell_all_x);
y_step = int (height / cell_all_y);
draw_interface();
draw_plants();
draw_numbers();
}
void draw_plants(){
for (int j = 0; j < cell_all_y; j = j + 1){
for (int i = 0; i < cell_all_x; i = i + 1){
fill (0, int(plants[i][j]), 0);
rect (i*x_step, j * y_step, x_step, y_step);
}
}
}
void draw_numbers(){
fill (0);
int n = 1;
for (int j = 0; j < cell_all_y; j = j + 1){
for (int i = 0; i < cell_all_x; i = i + 1){
text (n, x_step/3 + i * x_step, y_step/2 + j * y_step);
n = n + 1;
}
}
}
void draw_interface(){
int text_y = 50;
// определение квадрата, в котором курсор мыши
x = mouseX;
x = constrain(x, 0, gameboard_width - 10);
y = mouseY;
if (x < gameboard_width){
cell_x = int (x / x_step) + 1 ;
cell_y = int (y / y_step) + 1 ;
cell_number = cell_all_x * (cell_y - 1) + cell_x;
plant_number = plants [cell_x - 1] [cell_y - 1];
}
fill (interface_colors[0], interface_colors[1], interface_colors[2]);
text ("x =", interface_x0, text_y);
text (x, interface_x0 + text_step_x, text_y);
text_y = text_y + text_step_y;
text ("y =", interface_x0, text_y);
text (y, interface_x0 + text_step_x, text_y);
text_y = text_y + text_step_y;
text ("Ячейка по х", interface_x0, text_y);
text (cell_x, interface_x0 + text_step_x, text_y);
text_y = text_y + text_step_y;
text ("Ячейка по y", interface_x0, text_y);
text (cell_y, interface_x0 + text_step_x, text_y);
text_y = text_y + text_step_y;
text ("Номер ячейки", interface_x0, text_y);
text (cell_number, interface_x0 + text_step_x, text_y);
text_y = text_y + text_step_y;
text ("Растений", interface_x0, text_y);
text (int(plant_number), interface_x0 + text_step_x, text_y);
}
void mouseClicked() {
plants [cell_x - 1] [cell_y - 1] = plants [cell_x - 1] [cell_y - 1] + plant_step;
plants [cell_x - 1] [cell_y - 1] = constrain(plants [cell_x - 1] [cell_y - 1], 0, );
}
See More Shortcuts