Compare commits
8 Commits
main
...
771cabed8f
| Author | SHA1 | Date | |
|---|---|---|---|
| 771cabed8f | |||
| 96f4f51e69 | |||
| 525936c6e7 | |||
| 060b9f9182 | |||
| 59fd47e684 | |||
| 593b813988 | |||
| 5f6305a2f2 | |||
| dddf8ca632 |
@@ -8,11 +8,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||
# set(CMAKE_VERBOSE_MAKEFILE ON)
|
||||
add_compile_options(-ggdb)
|
||||
|
||||
include_directories(
|
||||
external/include
|
||||
shared/inc
|
||||
)
|
||||
|
||||
include_directories(external/include/)
|
||||
link_libraries(
|
||||
${CMAKE_SOURCE_DIR}/external/libimgui.a
|
||||
${CMAKE_SOURCE_DIR}/external/libraylib.a
|
||||
@@ -22,7 +18,11 @@ link_libraries(
|
||||
m
|
||||
)
|
||||
|
||||
add_library(shared STATIC
|
||||
add_executable(app
|
||||
app/src/main.cpp
|
||||
app/src/App.cpp
|
||||
app/src/DnaStore.cpp
|
||||
app/src/sys.cpp
|
||||
shared/src/canvas/BackGround.cpp
|
||||
shared/src/canvas/BackGroundColors.cpp
|
||||
shared/src/canvas/Canvas.cpp
|
||||
@@ -32,33 +32,36 @@ add_library(shared STATIC
|
||||
shared/src/values/mrand.cpp
|
||||
shared/src/values/Similarity.cpp
|
||||
shared/src/TcpSocket.cpp
|
||||
shared/src/sql.cpp
|
||||
)
|
||||
|
||||
add_executable(app
|
||||
app/src/main.cpp
|
||||
app/src/App.cpp
|
||||
app/src/DnaStore.cpp
|
||||
app/src/sys.cpp
|
||||
)
|
||||
target_include_directories(app PRIVATE app/inc)
|
||||
target_link_libraries(app PRIVATE shared)
|
||||
# Add include directories
|
||||
target_include_directories(app PRIVATE app/inc shared/inc )
|
||||
|
||||
add_executable(server
|
||||
server/src/server.cpp
|
||||
server/src/checker.cpp
|
||||
|
||||
shared/src/sql.cpp
|
||||
shared/src/TcpSocket.cpp
|
||||
shared/src/values/Dna.cpp
|
||||
shared/src/values/DnaManager.cpp
|
||||
shared/src/values/mrand.cpp
|
||||
)
|
||||
target_include_directories(server PRIVATE server/inc)
|
||||
target_link_libraries(server PRIVATE shared)
|
||||
# Add include directories
|
||||
target_include_directories(server PRIVATE server/inc shared/inc)
|
||||
|
||||
add_executable(view
|
||||
view/src/main.cpp
|
||||
view/src/Vapp.cpp
|
||||
shared/src/canvas/BackGround.cpp
|
||||
shared/src/canvas/BackGroundColors.cpp
|
||||
shared/src/canvas/Canvas.cpp
|
||||
shared/src/canvas/Tree.cpp
|
||||
shared/src/values/Dna.cpp
|
||||
shared/src/values/DnaManager.cpp
|
||||
shared/src/values/mrand.cpp
|
||||
shared/src/values/Similarity.cpp
|
||||
|
||||
shared/src/sql.cpp
|
||||
)
|
||||
target_include_directories(view PRIVATE view/inc)
|
||||
target_link_libraries(view PRIVATE shared)
|
||||
|
||||
add_executable(slike
|
||||
random/slike.cpp
|
||||
)
|
||||
target_link_libraries(slike PRIVATE shared)
|
||||
# Add include directories
|
||||
target_include_directories(view PRIVATE view/inc shared/inc)
|
||||
104
Readme.md
104
Readme.md
@@ -1,90 +1,26 @@
|
||||
# Treender
|
||||
|
||||
A genetic algorithm visualization tool with interactive evolution simulation.
|
||||
# Code style
|
||||
|
||||
## Overview
|
||||
## Naming Conventions:
|
||||
- PascalCase:
|
||||
- Functions
|
||||
- Class names
|
||||
- Struct names
|
||||
|
||||
Treender is a C++ application that simulates genetic algorithms through an interactive visual interface. Users can observe and influence the evolution of digital organisms represented as visual patterns.
|
||||
- camelCase:
|
||||
- Class attributes
|
||||
- Class methods
|
||||
- Struct attributes
|
||||
- Variables
|
||||
|
||||
## Features
|
||||
## Class Structure:
|
||||
|
||||
- **Interactive Evolution**: Like/dislike organisms to guide evolution
|
||||
- **Genetic Algorithm**: DNA-based reproduction with mutation
|
||||
- **Visual Representation**: Organisms displayed as colorful patterns
|
||||
- **Client-Server Architecture**: Separate app and server components
|
||||
- **Cross-Platform**: Supports Web, Android, and Desktop platforms
|
||||
- Header (.h) Files:
|
||||
- Declare public methods and attributes first, followed by private members.
|
||||
- Implementation (.cpp) Files:
|
||||
- Implement methods in the same order as declared in the corresponding header file.
|
||||
|
||||
## Architecture
|
||||
|
||||
```
|
||||
Treender
|
||||
├── app/ # Main application (Raylib + Dear ImGui)
|
||||
├── server/ # TCP server for data management
|
||||
├── shared/ # Shared code (DNA logic, networking)
|
||||
├── external/ # Third-party libraries
|
||||
└── data.db # SQLite database
|
||||
```
|
||||
|
||||
## Components
|
||||
|
||||
### Application
|
||||
- **Main Entry**: `app/src/main.cpp`
|
||||
- **Core Class**: `App` class handles rendering, input, and evolution logic
|
||||
- **Visualization**: Uses Raylib for graphics and Dear ImGui for UI
|
||||
|
||||
### Server
|
||||
- **TCP Server**: Handles client connections and data persistence
|
||||
- **Database**: SQLite for storing organism data and user preferences
|
||||
- **Block Management**: Tracks warnings and blocked organisms
|
||||
|
||||
### Shared Library
|
||||
- **DNA System**: Genetic algorithm implementation (`Dna.cpp`)
|
||||
- **Networking**: TCP socket communication
|
||||
- **Data Structures**: Shared between app and server
|
||||
|
||||
## Building
|
||||
|
||||
### Prerequisites
|
||||
- CMake 3.10+
|
||||
- C++17 compiler
|
||||
- Raylib
|
||||
- Dear ImGui
|
||||
- SQLite3
|
||||
|
||||
### Build Instructions
|
||||
|
||||
```bash
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make
|
||||
```
|
||||
## Running
|
||||
|
||||
1. Start the server:
|
||||
```bash
|
||||
./build/server
|
||||
```
|
||||
|
||||
2. Run the application:
|
||||
```bash
|
||||
./build/app
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
- **Like/Disike**: Click on organisms to influence evolution
|
||||
- **Rotation**: Drag to rotate the view
|
||||
- **Statistics**: View similarity scores and generation information
|
||||
|
||||
## Database
|
||||
|
||||
The application uses SQLite database (`data.db`) to store:
|
||||
- Organism DNA data
|
||||
- User preferences
|
||||
- Blocked/warned organisms
|
||||
|
||||
## Screenshots
|
||||
|
||||

|
||||

|
||||
## Include order
|
||||
- Std
|
||||
- local ( form inc dir )
|
||||
- external raylib
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 168 KiB |
147
random/slike.cpp
147
random/slike.cpp
@@ -1,147 +0,0 @@
|
||||
#include <raylib.h>
|
||||
#include <raymath.h>
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
|
||||
Vector2 newPoint(Vector2 start, float len, float angleD){
|
||||
float angleR = (angleD * PI) / 180; // radian
|
||||
return {start.x + len * cos(angleR), start.y - len * sin(angleR)};
|
||||
}
|
||||
|
||||
void drawBranch(Vector2 startV, Vector2 endV, Color startC, Color endC, int startR, int endR){
|
||||
float fstep = 0.05;
|
||||
for (float i = 0; i < 1.05; i += fstep)
|
||||
{
|
||||
Vector2 point = Vector2Lerp(startV, endV, i);
|
||||
Color color = ColorLerp(startC, endC, i);
|
||||
int size = Lerp(startR, endR, i);
|
||||
DrawCircleV(point, size, color);
|
||||
}
|
||||
}
|
||||
|
||||
constexpr float screenWidth = 800;
|
||||
constexpr float screenHeight = 800;
|
||||
|
||||
constexpr float len = 300;
|
||||
constexpr float angleD = 100;
|
||||
constexpr Vector2 start = {screenWidth / 2, screenHeight - 100};
|
||||
constexpr float radius = 20;
|
||||
constexpr float radiusS = 80;
|
||||
constexpr float radiusE = 60;
|
||||
constexpr Color colorS = RED;
|
||||
constexpr Color colorE = GREEN;
|
||||
|
||||
typedef void (*slika)();
|
||||
|
||||
int idx = 0;
|
||||
|
||||
std::vector<slika> v_slik = {
|
||||
[]()
|
||||
{
|
||||
DrawCircleV(start, radius, BLACK);
|
||||
},
|
||||
|
||||
[]()
|
||||
{
|
||||
Vector2 end = {start.x, start.y - len};
|
||||
DrawCircleV(start, radius, BLACK);
|
||||
DrawLineEx(start, end, 10, BLACK);
|
||||
},
|
||||
|
||||
[]()
|
||||
{
|
||||
Vector2 end = newPoint(start, len, angleD);
|
||||
DrawCircleV(start, radius, BLACK);
|
||||
DrawLineEx(start, end, 10, BLACK);
|
||||
DrawCircleV(end, radius, BLACK);
|
||||
DrawCircleSectorLines(start, len / 3, 360 - angleD, 360, 30, BLACK);
|
||||
},
|
||||
|
||||
[]()
|
||||
{
|
||||
Vector2 end = newPoint(start, len, angleD);
|
||||
DrawCircleV(start, radius, BLACK);
|
||||
DrawLineEx(start, end, 10, BLACK);
|
||||
DrawCircleV(end, radius, BLACK);
|
||||
DrawCircleLinesV(start, radiusS, BLACK);
|
||||
DrawCircleLinesV(end, radiusE, BLACK);
|
||||
},
|
||||
|
||||
[]()
|
||||
{
|
||||
Vector2 end = newPoint(start, len, angleD);
|
||||
DrawLineEx(start, end, 10, BLACK);
|
||||
DrawCircleV(start, radiusS, colorS);
|
||||
DrawCircleV(end, radiusE, colorE);
|
||||
},
|
||||
|
||||
[]()
|
||||
{
|
||||
Vector2 end = newPoint(start, len, angleD);
|
||||
drawBranch(start, end, colorS, colorE, radiusS, radiusE);
|
||||
},
|
||||
|
||||
[]()
|
||||
{
|
||||
Vector2 p = newPoint(start, len, angleD);
|
||||
drawBranch(start, p, colorS, colorE, radiusS, radiusE);
|
||||
Vector2 p1 = newPoint(p, len, 135);
|
||||
Vector2 p2 = newPoint(p, len, 90);
|
||||
Vector2 p3 = newPoint(p, len, 45);
|
||||
DrawLineEx(p, p1, 10, BLACK);
|
||||
DrawLineEx(p, p2, 10, BLACK);
|
||||
DrawLineEx(p, p3, 10, BLACK);
|
||||
DrawCircleV(p, radius, BLACK);
|
||||
DrawCircleV(p1, radius, BLACK);
|
||||
DrawCircleV(p2, radius, BLACK);
|
||||
DrawCircleV(p3, radius, BLACK);
|
||||
},
|
||||
|
||||
[]()
|
||||
{
|
||||
Vector2 p = newPoint(start, len, angleD);
|
||||
drawBranch(start, p, colorS, colorE, radiusS, radiusE);
|
||||
Vector2 p1 = newPoint(p, len, 135);
|
||||
Vector2 p2 = newPoint(p, len, 90);
|
||||
Vector2 p3 = newPoint(p, len, 45);
|
||||
drawBranch(p, p1, colorE, BLUE, radiusE, 50);
|
||||
drawBranch(p, p2, colorE, ORANGE, radiusE, 50);
|
||||
drawBranch(p, p3, colorE, PURPLE, radiusE, 50);
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
InitWindow(screenWidth, screenHeight, "Slike");
|
||||
SetTargetFPS(60);
|
||||
|
||||
while (!WindowShouldClose())
|
||||
{
|
||||
BeginDrawing();
|
||||
if (IsKeyPressed(KEY_S))
|
||||
{
|
||||
TakeScreenshot(TextFormat("slika%.2d.png", idx));
|
||||
}
|
||||
if (IsKeyPressed(KEY_N))
|
||||
{
|
||||
idx++;
|
||||
if (idx >= v_slik.size())
|
||||
idx = v_slik.size() - 1;
|
||||
}
|
||||
if (IsKeyPressed(KEY_P))
|
||||
{
|
||||
idx--;
|
||||
if (idx < 0)
|
||||
idx = 0;
|
||||
}
|
||||
ClearBackground(WHITE);
|
||||
v_slik[idx]();
|
||||
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
|
||||
CloseWindow();
|
||||
return 0;
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
|
||||
#include "canvas/BackGround.hpp"
|
||||
#include "canvas/BackGroundColors.hpp"
|
||||
|
||||
@@ -136,11 +136,7 @@ namespace Similarity
|
||||
}
|
||||
else if (f == &Similarity::hamming_distance)
|
||||
{
|
||||
return "hamming_distance";
|
||||
}
|
||||
else if (f == &Similarity::hamming_distance_without_seeds)
|
||||
{
|
||||
return "hamming_distance_without_seeds";
|
||||
return "hamming";
|
||||
}
|
||||
else if (f == &Similarity::levenshtein_distance)
|
||||
{
|
||||
@@ -148,7 +144,7 @@ namespace Similarity
|
||||
}
|
||||
else
|
||||
{
|
||||
return "unknown nameofFunc";
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,6 +167,7 @@ namespace Similarity
|
||||
|
||||
const auto int_ms = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
|
||||
|
||||
TraceLog(LOG_INFO, "%s, %d", nameofFunc(f), int_ms);
|
||||
return average_similarity * 100.0f;
|
||||
}
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 52 KiB After Width: | Height: | Size: 52 KiB |
|
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 3.3 KiB |
@@ -28,7 +28,6 @@ public:
|
||||
private:
|
||||
bool showSelection;
|
||||
bool showStats;
|
||||
bool saveToFile;
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *get_gen_num;
|
||||
std::vector<int64_t> ids;
|
||||
|
||||
@@ -110,7 +110,7 @@ void Vapp::update()
|
||||
stageOfDrawing = DrawingStage::save;
|
||||
break;
|
||||
case DrawingStage::save:
|
||||
if(saveToFile) drawToFile();
|
||||
drawToFile();
|
||||
stageOfDrawing = DrawingStage::done;
|
||||
break;
|
||||
case DrawingStage::done:
|
||||
@@ -140,10 +140,6 @@ void Vapp::draw()
|
||||
{
|
||||
setUpTable();
|
||||
}
|
||||
if(ImGui::MenuItem("Save to File", nullptr, saveToFile, true))
|
||||
{
|
||||
saveToFile = !saveToFile;
|
||||
}
|
||||
ImGui::EndMainMenuBar();
|
||||
}
|
||||
|
||||
@@ -339,28 +335,27 @@ void Vapp::setUpTable()
|
||||
}
|
||||
|
||||
sql::reset(get_gen_stmt);
|
||||
if(saveToFile)
|
||||
|
||||
int64_t id = ids[selected_id_index];
|
||||
char buff[50];
|
||||
sprintf(buff, "%ld.txt", id);
|
||||
std::ofstream file(buff);
|
||||
|
||||
file << "| index | euclidean_distance | cosine_similarity | cosine_similarity_int | hamming_distance | levenshtein_distance | dot_minmax |\n";
|
||||
file << "| --- | --- | --- | --- | --- | --- | --- |\n";
|
||||
|
||||
|
||||
|
||||
for (size_t i = 0; i < similTable.size(); i++)
|
||||
{
|
||||
int64_t id = ids[selected_id_index];
|
||||
const char* buff = TextFormat("%ld.txt", id);
|
||||
std::ofstream file(buff);
|
||||
|
||||
file << "| index | euclidean_distance | cosine_similarity | cosine_similarity_int | hamming_distance | levenshtein_distance | dot_minmax |\n";
|
||||
file << "| --- | --- | --- | --- | --- | --- | --- |\n";
|
||||
|
||||
|
||||
|
||||
for (size_t i = 0; i < similTable.size(); i++)
|
||||
file << "|" << i << "|";
|
||||
for (size_t j = 0; j < similTable[i].size(); j++)
|
||||
{
|
||||
file << "|" << i << "|";
|
||||
for (size_t j = 0; j < similTable[i].size(); j++)
|
||||
{
|
||||
file << similTable[i][j] << "|";
|
||||
}
|
||||
file << "\n";
|
||||
file << similTable[i][j] << "|";
|
||||
}
|
||||
file << "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sql::finalize(get_gen_stmt);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user