Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving performance and Adding options #17

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .github/dependabot.yml

This file was deleted.

61 changes: 0 additions & 61 deletions .github/workflows/codeql-analysis.yml

This file was deleted.

32 changes: 0 additions & 32 deletions .github/workflows/go.yml

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore

This file was deleted.

12 changes: 6 additions & 6 deletions FyneApp.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Website = "https://github.com/tucuxi/metaballs"
Website = "https://github.com/FattyMango/Metaballs"

[Details]
Icon = "Icon.png"
Name = "Metaballs"
ID = "com.github.tucuxi.metaballs"
Version = "1.2.2"
Build = 1
Icon = "Icon.png"
Name = "Metaball"
ID = "com.github.FattyMango.Metaballs"
Version = "1.3.0"
Build = 13
Binary file removed Icon.png
Binary file not shown.
21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

37 changes: 37 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.PHONY: run
run:
@go run cmd/main.go

.PHONY: buildrun
buildrun:
@ $(MAKE) build && ./metaballs

.PHONY: build
build:
@CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build


.PHONY: build-win
build-win:
#
@sudo apt-get install gcc-mingw-w64
@GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CXX=x86_64-w64-mingw32-g++ CC=x86_64-w64-mingw32-gcc go build -o ./metaballs.exe ./cmd

.PHONY: build-win-fyne
build-win-fyne:
@go install github.com/fyne-io/fyne-cross@latest
@fyne-cross windows -arch=amd64

.PHONY: build-linux
build-linux:
@GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -o ./metaballs ./cmd


.PHONY: build-linux-fyne
build-linux-fyne:
@go install github.com/fyne-io/fyne-cross@latest
@fyne-cross linux -arch=amd64

.PHONY: pprof-cpu
pprof-cpu:
@go tool pprof -http localhost:8080 profile/cpu.pprof
Binary file removed Preview.png
Binary file not shown.
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
# Metaballs in Go

A 2D animation of moving metaballs, implemented with Go and the Fyne toolkit, based on the marching square algorithm.
A 2D animation of moving metaballs, implemented with Go, Fyne toolkit and BubbleTea TUI , based on the marching square algorithm.

![Preview](Preview.png)
## Usage
### Linux
```bash
./metaballs
```

### Windows
Open the `metaballs.exe` file

Then you can interact with the TUI using the keyboard to set your preferences:
![TUI](docs/img/tui.png)

After setting your preferences, press `q` to confirm and start the animation.

![Animation](docs/img/metaball.gif)

## References

* [Metaballs and Marching Squares](https://jamie-wong.com/2014/08/19/metaballs-and-marching-squares/), by Jamie Wong
* [How Computers Draw Weird Shapes](https://www.youtube.com/watch?v=6oMZb3yP_H8), on YouTube
* [Fyne toolkit](https://developer.fyne.io/)
* [Fyne toolkit](https://developer.fyne.io/)
* [Bubble Tea](https://github.com/charmbracelet/bubbletea)
34 changes: 34 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package app

import (
"fmt"
"metaballs/internal"
"os"

tea "github.com/charmbracelet/bubbletea"

)


func Run() {
model := initialModel()

t := tea.NewProgram(model)
if _, err := t.Run(); err != nil {
fmt.Printf("Alas, there's been an error: %v", err)
os.Exit(1)
}

ballSize := Map_BallSize[METABALL_SELECTIONS["Ball Size"].GetSelected()]
ballSpeed := Map_BallSpeed[METABALL_SELECTIONS["Ball Speed"].GetSelected()]

screenSize := Map_ScreenSize[METABALL_SELECTIONS["Screen Size"].GetSelected()]
resolution := Map_Resolution[METABALL_SELECTIONS["Resolution"].GetSelected()]
fps := Map_FPS[METABALL_SELECTIONS["FPS"].GetSelected()]

ballCount := Map_BallCount[METABALL_SELECTIONS["Ball Count"].GetSelected()]
ballColor := Map_BallColor[METABALL_SELECTIONS["Ball Color"].GetSelected()]

metaBallApp := internal.NewMetaBallApp(ballCount, ballSpeed, ballSize, ballColor, fps, screenSize, resolution)
metaBallApp.Run()
}
49 changes: 49 additions & 0 deletions app/mapping.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package app

import "metaballs/internal"

var (
Map_BallSize = map[string]internal.BallSize{
"Small": internal.SmallSizeBall,
"Medium": internal.MediumSizeBall,
"Large": internal.LargeSizeBall,
}

Map_BallSpeed = map[string]internal.BallSpeed{
"Slow": internal.SlowSpeedBall,
"Medium": internal.NormalSpeedBall,
"Fast": internal.FastSpeedBall,
}

Map_ScreenSize = map[string]internal.ScreenSize{
"Small": internal.ScreenSmall,
"Medium": internal.ScreenMedium,
"Large": internal.ScreenLarge,
}

Map_Resolution = map[string]internal.Resolution{
"Low": internal.Resolution512,
"Medium": internal.Resolution1024,
"High": internal.Resolution2048,
}

Map_FPS = map[string]internal.FPS{
"30": internal.FPS30,
"45": internal.FPS45,
"60": internal.FPS60,

}

Map_BallCount = map[string]uint8{
"4": 4,
"8": 8,
"20": 20,
}

Map_BallColor = map[string]internal.BallColor{
"Pink": internal.Pink,
"Cyan": internal.Cyan,
"Gray": internal.Gray,
}

)
Loading