Initial commit
This commit is contained in:
commit
0ebd216c99
|
@ -0,0 +1,3 @@
|
|||
.vscode/*
|
||||
slime_mold
|
||||
build/*
|
|
@ -0,0 +1,25 @@
|
|||
CXX=g++
|
||||
HEADERDIR=./header
|
||||
INCLUDE := $(shell find $(HEADERDIR) -type d | sed -e 's/^/-I/' | tr '\n' ' ' | sed 's/.$$//')
|
||||
CXXFLAGS=-g $(INCLUDE)
|
||||
SRCDIR=./src
|
||||
SRC := $(shell find $(SRCDIR) -name '*.cpp' | tr '\n' ' ' | sed 's/.$$//')
|
||||
OBJDIR=./build/debug/obj
|
||||
OBJ := $(SRC:$(SRCDIR)/%.cpp=$(OBJDIR)/%.o)
|
||||
LIBS=-lSDL2
|
||||
EXECUTABLE=slime_mold
|
||||
|
||||
all: debug
|
||||
|
||||
$(OBJ): $(OBJDIR)/%.o : $(SRCDIR)/%.cpp
|
||||
@echo "Compiling source $< into object $@"
|
||||
@mkdir -p '$(@D)'
|
||||
@$(CXX) -c $(CXXFLAGS) $< -o $@
|
||||
|
||||
debug: $(OBJ)
|
||||
@echo "Compiling executable"
|
||||
@$(CXX) $(CXXFLAGS) -o $(EXECUTABLE) $^ $(LIBS)
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJDIR)/*
|
||||
rm $(EXECUTABLE)
|
|
@ -0,0 +1,17 @@
|
|||
# Slime Mold Simulation
|
||||
|
||||
A visually interesting slime mold simulation using SDL2 and C++.
|
||||
|
||||
## Requirements
|
||||
|
||||
* `g++`
|
||||
* `make`
|
||||
* `libsdl2-dev`
|
||||
|
||||
## Compilation and Running
|
||||
|
||||
Use `make` to compile. An executable called slime_mold will be generated.
|
||||
|
||||
```./slime_mold [width height]```
|
||||
|
||||
If a width and height is not provided a 300x300 pixel simulation will be ran.
|
|
@ -0,0 +1,47 @@
|
|||
#include <SDL2/SDL.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int width, height;
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
width = height = 300;
|
||||
}
|
||||
else
|
||||
{
|
||||
width = atoi(argv[1]);
|
||||
height = atoi(argv[2]);
|
||||
}
|
||||
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0)
|
||||
{
|
||||
std::cout << "Video Init Error." << std::endl;
|
||||
}
|
||||
|
||||
SDL_Window* window = SDL_CreateWindow("Slime Mold Simulator", SDL_WINDOWPOS_CENTERED-width/2, SDL_WINDOWPOS_CENTERED-height/2, width, height, SDL_WINDOW_SHOWN);
|
||||
|
||||
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00);
|
||||
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
|
||||
|
||||
SDL_Rect half_screen = (SDL_Rect){width/4, height/4, width/2, height/2};
|
||||
|
||||
SDL_RenderFillRect(renderer, &half_screen);
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
SDL_Delay(2000);
|
||||
|
||||
SDL_DestroyWindow(window);
|
||||
|
||||
SDL_Quit();
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue