Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/*
*.png
*.mp4

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ That's the magic of generative algorithms!

## Usage

go run cmd/physarum/main.go
go run main.go

## Examples

Expand Down
15 changes: 15 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module physarum

go 1.15

require (
github.com/go-gl/gl v0.0.0-20210315015930-ae072cafe09d
github.com/go-gl/glfw v0.0.0-20210311203641-62640a716d48
github.com/gonum/blas v0.0.0-20181208220705-f22b278b28ac // indirect
github.com/gonum/floats v0.0.0-20181209220543-c233463c7e82 // indirect
github.com/gonum/integrate v0.0.0-20181209220457-a422b5c0fdf2 // indirect
github.com/gonum/internal v0.0.0-20181124074243-f884aa714029 // indirect
github.com/gonum/lapack v0.0.0-20181123203213-e4cdc5a0bff9 // indirect
github.com/gonum/matrix v0.0.0-20181209220409-c518dec07be9 // indirect
github.com/gonum/stat v0.0.0-20181125101827-41a0da705a5b
)
18 changes: 18 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
github.com/go-gl/gl v0.0.0-20210315015930-ae072cafe09d h1:o81yRlBATU4PRn97lydmsq8hTRNXI4wlR/VvUQhFRVY=
github.com/go-gl/gl v0.0.0-20210315015930-ae072cafe09d/go.mod h1:482civXOzJJCPzJ4ZOX/pwvXBWSnzD4OKMdH4ClKGbk=
github.com/go-gl/glfw v0.0.0-20210311203641-62640a716d48 h1:2Ql7UigDMdlF+Ii12kdox7RKw3J1+uGhXn9FyYbbd20=
github.com/go-gl/glfw v0.0.0-20210311203641-62640a716d48/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/gonum/blas v0.0.0-20181208220705-f22b278b28ac h1:Q0Jsdxl5jbxouNs1TQYt0gxesYMU4VXRbsTlgDloZ50=
github.com/gonum/blas v0.0.0-20181208220705-f22b278b28ac/go.mod h1:P32wAyui1PQ58Oce/KYkOqQv8cVw1zAapXOl+dRFGbc=
github.com/gonum/floats v0.0.0-20181209220543-c233463c7e82 h1:EvokxLQsaaQjcWVWSV38221VAK7qc2zhaO17bKys/18=
github.com/gonum/floats v0.0.0-20181209220543-c233463c7e82/go.mod h1:PxC8OnwL11+aosOB5+iEPoV3picfs8tUpkVd0pDo+Kg=
github.com/gonum/integrate v0.0.0-20181209220457-a422b5c0fdf2 h1:GUSkTcIe1SlregbHNUKbYDhBsS8lNgYfIp4S4cToUyU=
github.com/gonum/integrate v0.0.0-20181209220457-a422b5c0fdf2/go.mod h1:pDgmNM6seYpwvPos3q+zxlXMsbve6mOIPucUnUOrI7Y=
github.com/gonum/internal v0.0.0-20181124074243-f884aa714029 h1:8jtTdc+Nfj9AR+0soOeia9UZSvYBvETVHZrugUowJ7M=
github.com/gonum/internal v0.0.0-20181124074243-f884aa714029/go.mod h1:Pu4dmpkhSyOzRwuXkOgAvijx4o+4YMUJJo9OvPYMkks=
github.com/gonum/lapack v0.0.0-20181123203213-e4cdc5a0bff9 h1:7qnwS9+oeSiOIsiUMajT+0R7HR6hw5NegnKPmn/94oI=
github.com/gonum/lapack v0.0.0-20181123203213-e4cdc5a0bff9/go.mod h1:XA3DeT6rxh2EAE789SSiSJNqxPaC0aE9J8NTOI0Jo/A=
github.com/gonum/matrix v0.0.0-20181209220409-c518dec07be9 h1:V2IgdyerlBa/MxaEFRbV5juy/C3MGdj4ePi+g6ePIp4=
github.com/gonum/matrix v0.0.0-20181209220409-c518dec07be9/go.mod h1:0EXg4mc1CNP0HCqCz+K4ts155PXIlUywf0wqN+GfPZw=
github.com/gonum/stat v0.0.0-20181125101827-41a0da705a5b h1:fbskpz/cPqWH8VqkQ7LJghFkl2KPAiIFUHrTJ2O3RGk=
github.com/gonum/stat v0.0.0-20181125101827-41a0da705a5b/go.mod h1:Z4GIJBJO3Wa4gD4vbwQxXXZ+WHmW6E9ixmNrwvs0iZs=
3 changes: 1 addition & 2 deletions cmd/physarum/main.go → main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package main
import (
"math/rand"
_ "net/http/pprof"
"physarum/physarum"
"time"

"github.com/fogleman/physarum/pkg/physarum"
)

func main() {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions pkg/physarum/model.go → physarum/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ func direction(rnd *rand.Rand, C, L, R float32) float32 {
return 0
}

/*
func weightedDirection(rnd *rand.Rand, C, L, R float32) float32 {
W := [3]float32{C, L, R}
D := [3]float32{0, -1, 1}
Expand All @@ -204,3 +205,4 @@ func weightedDirection(rnd *rand.Rand, C, L, R float32) float32 {
}
return D[2]
}
*/
90 changes: 90 additions & 0 deletions physarum/palette.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package physarum

import (
"fmt"
"image/color"
"math/rand"
)

type Palette []color.RGBA

func ShuffledPalette(palette Palette) Palette {
result := make(Palette, len(palette))
for i, j := range rand.Perm(len(result)) {
result[i] = palette[j]
}
return result
}

func RandomPalette() Palette {
palette := Palettes[rand.Intn(len(Palettes))]
return ShuffledPalette(palette)
}

func (p Palette) Print() {
for _, c := range p {
fmt.Printf("HexColor(0x%02X%02X%02X),\n", c.R, c.G, c.B)
}
fmt.Println()
}

var (
Palettes = []Palette{
{
HexColor(0xFA2B31),
HexColor(0xFFBF1F),
HexColor(0xFFF146),
HexColor(0xABE319),
HexColor(0x00C481),
},
{
HexColor(0x004358),
HexColor(0x1F8A70),
HexColor(0xBEDB39),
HexColor(0xFFE11A),
HexColor(0xFD7400),
},
{
HexColor(0x334D5C),
HexColor(0x45B29D),
HexColor(0xEFC94C),
HexColor(0xE27A3F),
HexColor(0xDF5A49),
},
{
HexColor(0xFF8000),
HexColor(0xFFD933),
HexColor(0xCCCC52),
HexColor(0x8FB359),
HexColor(0x192B33),
},
{
HexColor(0x730046),
HexColor(0xBFBB11),
HexColor(0xFFC200),
HexColor(0xE88801),
HexColor(0xC93C00),
},
{
HexColor(0xE6DD00),
HexColor(0x8CB302),
HexColor(0x008C74),
HexColor(0x004C66),
HexColor(0x332B40),
},
{
HexColor(0xF15A5A),
HexColor(0xF0C419),
HexColor(0x4EBA6F),
HexColor(0x2D95BF),
HexColor(0x955BA5),
},
{
HexColor(0xF41C54),
HexColor(0xFF9F00),
HexColor(0xFBD506),
HexColor(0xA8BF12),
HexColor(0x00AAB5),
},
}
)
File renamed without changes.
4 changes: 2 additions & 2 deletions pkg/physarum/run.go → physarum/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func one(model *Model, iterations int) {
}
palette := RandomPalette()
im := Image(model.W, model.H, model.Data(), palette, 0, 0, 1/2.2)
SavePNG(path, im, png.DefaultCompression)
_ = SavePNG(path, im, png.DefaultCompression)
}

func frames(model *Model, rate int) {
Expand All @@ -39,7 +39,7 @@ func frames(model *Model, rate int) {
saveImage := func(path string, w, h int, grids [][]float32, ch chan bool) {
max := particles / float32(width*height) * 20
im := Image(w, h, grids, palette, 0, max, 1/2.2)
SavePNG(path, im, png.BestSpeed)
_ = SavePNG(path, im, png.BestSpeed)
if ch != nil {
ch <- true
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
88 changes: 0 additions & 88 deletions pkg/physarum/palette.go

This file was deleted.

6 changes: 3 additions & 3 deletions cmd/viewer/main.go → viewer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ import (
"log"
"math"
"math/rand"
"physarum/physarum"
"runtime"
"sort"
"time"

"github.com/fogleman/physarum/pkg/physarum"
"github.com/go-gl/gl/v2.1/gl"
"github.com/go-gl/glfw/v3.1/glfw"
"github.com/gonum/stat"
)

const (
width = 512
height = 512
width = 2048
height = 1024
particles = 1 << 20
blurRadius = 1
blurPasses = 2
Expand Down