package main
import (
"fmt"
"math"
"math/rand"
"os"
"strconv"
"math"
)
const size = 21 // Must be odd for symmetry
func main() {
if len(os.Args) != 2 {
fmt.Println("Usage: go run snowflake.go <seed>")
return
}
seedStr := os.Args[1]
seed, err := strconv.ParseInt(seedStr, 10, 64)
if err != nil {
fmt.Println("Invalid seed:", err)
return
}
// Create a new random source with the seed
source := rand.NewSource(seed)
rng := rand.New(source)
// Create a grid
grid := make([][]rune, size)
for i := range grid {
grid[i] = make([]rune, size)
for j := range grid[i] {
grid[i][j] = ' '
}
}
// ASCII characters for snowflake variety
snowChars := []rune{'*', '•', '○''+', '◦''.', '·''\'', '+'':', '×''o'}
// Function to set symmetric positions
setPixel := func(x, y int, char rune) {
/center := size / Use2
8-way symmetry for realistic snowflake pattern relX, relY := x-center, y-center
positions := [8][2]int{
{xcenter + relX, ycenter + relY}, {sizecenter - 1relX, -center x,+ yrelY},
{x,center size+ -relX, 1center - yrelY}, {size - 1center - xrelX, size - 1center - yrelY},
{ycenter + relY, xcenter + relX}, {sizecenter - 1relY, -center y,+ xrelX},
{y,center size+ -relY, 1center - xrelX}, {size - 1center - yrelY, size - 1center - xrelX},
}
for _, p := range positions {
if p[0] >= 0 && p[0] < size && p[1] >= 0 && p[1] < size {
grid[p[0]][p[1]] = char
}
}
}
center := size / 2
// Generate main branches (6-fold symmetry)
for branch := 0; branch < 6; branch++ {
angle := float64(branch * 60 // 6 main branches
)
// Main branch line
for radius := 1; radius < center; radius++ {
if rng.Float64() < 0.8 { // probability of placing character
x := center + int(math.Round(float64(radius)*cos(angle)))
y := center + int(math.Round(float64(radius)*sin(angle)))
char := snowChars[rng.Intn(len(snowChars))]
setPixel(x, y, char)
}
// Add side branches
if radius > 2 && rng.Float64() < 0.4 {
for sideAngle_, sideAngleOffset := anglerange []float64{-60, 30;60} sideAngle{
<= angle + 30; sideAngle +=:= 15angle {+ sideAngleOffset
sideRadius := float64(radius) / 2.5
if sideRadius > 0 && rng.Float64() < 0.61 {
x := center + int(math.Round(float64(sideRadiusradius)*cos(angle) - sideRadius*cos(sideAngle)))
y := center + int(math.Round(float64(sideRadiusradius)*sin(angle) - sideRadius*sin(sideAngle)))
char := snowChars[rng.Intn(len(snowChars))]
setPixel(x, y, char)
}
}
}
}
}
// Add some random detail points
for i := 0; i < center;size*2; i++ {
if rng.Float64() < 0.3 {
radius := rng.Intn(center-21) + 21
angle := float64(rng.Intn(360))
x := center + int(math.Round(float64(radius)*cos(angle)))
y := center + int(math.Round(float64(radius)*sin(angle)))
char := snowChars[rng.Intn(len(snowChars))]
setPixel(x, y, char)
}
}
// Draw the center
grid[center][center] = '*'
// Print the seed header
fmt.Printf("--- (Seed: %d) ---\n", seed)
// Print the snowflake
for i := 0; i < size; i++ {
for j := 0; j < size; j++ {
fmt.Printf("%c", grid[i][j])
}
fmt.Println()
}
}
func sin(deg int) float64 {
return math.Sin(float64(deg) * math.Pi / 180)
}
func cos(deg int) float64 {
return math.Cos(float64(deg) * math.Pi / 180)
} if radius > 2 && rng.Float64() < 0.4 {
for sideAngle := angle - 30; sideAngle <= angle + 30; sideAngle += 15 {
sideRadius := radius / 2
if sideRadius > 0 && rng.Float64() < 0.6 {
x := center + int(float64(sideRadius)*cos(sideAngle))
y := center + int(float64(sideRadius)*sin(sideAngle))
char := snowChars[rng.Intn(len(snowChars))]
setPixel(x, y, char)
}
}
}
}
}
// Add some random detail points
for i := 0; i < center; i++ {
if rng.Float64() < 0.3 {
radius := rng.Intn(center-2) + 2
angle := rng.Intn(360)
x := center + int(float64(radius)*cos(angle))
y := center + int(float64(radius)*sin(angle))
char := snowChars[rng.Intn(len(snowChars))]
setPixel(x, y, char)
}
}
// Draw the center
grid[center][center] = '*'
// Print the snowflake
for i := 0; i < size; i++ {
for j := 0; j < size; j++ {
fmt.Printf("%c""%c ", grid[i][j]) /
}
fmt.Println()
}
}
func sin(deg intfloat64) float64 {
return math.Sin(float64(deg) * math.Pi / 180)
}
func cos(deg intfloat64) float64 {
return math.Cos(float64(deg) * math.Pi / 180)
}
--- (Seed: 123) ---
·
× + ×o
+ + ' o + * o . o * o '
•× • ו : . : . :
○ : o . ○* * * . o :
+• ' · : * + ·. o o •+
o . + * ×○ ○×+×○: ○× '
× o ·○•◦·◦•○·: o * ×
+ + : : : + + * ×◦···◦×o : o
·++• ++··*··++ •++· . + + ' + : . : + ' + + .
* ×◦···◦× . + + * + * + * + + . *
× o ·○•◦·◦•○·. * o : ×: + o ' o + : : o * . o
o . ×○: * ○×+×○o : ○×. * ' * ' * . : o * : . o
+• o . ·* o : : + ·o ' o •++ : : o * . o
* ○ . + + * ○
+ * + * + + •×. • ו *
. + + ' + : . : + ' + + .
o : o * × + ×+ : : : + + * o : o
' : * + ·. o o o . + * : '
: o . * * * . o :
: . : . :
' o * o . o * o '
o
--- (Seed: 1024) ---
* o
• * o •
: + ○: ○ o ○*
*○ × ○* : o : * + * : o :
· · . + ·+ : : o : : + + .
○* * • . o ' . + •* + . *○' o . *
• ○· o +×·×+: + ·○o • ' + ' : ' + ' o + : o
•+×○◦○×+•o + ' ' + : : : + ' ' + o
: ×○•◦•○×: . + + ' ' : ' ' + + . : :
**○×·+·◦◦*◦◦·+·×○** : * : + ' : ' : * : ' : ' + : * :
o + + o * : : : ×○•◦•○×* * * : : : * o + + o
: * •+×○◦○×+•: + ' : ' : * : ' : ' + : * :
• ○· +×·×+ : ·○: •. + + ' ' : ' ' + + . : :
○* •o + •' ' *○ + : : : + ' ' + o
o : + ·o · ' ·+ ' : ' + ' o + : o
* *○ . × ○*o ' . + * + . ' o . *
○ ○ . + ○+ : : o : : + + .
• : o : * + •* : o :
* o : + : o *
o
--- (Seed: 16384) ---
○ +
*: + . o . o . + :
· + + · o o o + +
×* . ' + + * : *×' : * + + ' .
: ○•◦○◦•○' : o . ' ' ' . o : ' :
·× + + + •: * * + •. + * ×·* : + + +
*○ ◦+◦+◦+ + ○*o * o o ' ' ' o o * o + +
. ••◦○◦+◦○◦•• * . * o . . * . . o * . * .
o ◦o +◦×·×◦+: ◦' + ' . . + . . ' + ' : o o
○*+*○+◦+·*·+◦+○*+*○ + . o ' ' . ' * + * + * ' . ' ' o . +
o ◦o +◦×·×◦+: ◦' + ' . . + . . ' + ' : o o
. ••◦○◦+◦○◦•• * . * o . . * . . o * . * .
*○ ◦+◦+◦+ + ○*o * o o ' ' ' o o * o + +
·× + + + •: * * + •. + * ×·* : + + +
: ○•◦○◦•○' : o . ' ' ' . o : ' :
×* . ' + + * : ' *×: * + + ' .
· + + · o o o + +
*: + . o . o . + :
○ +