Коди

Коди

Остапенко Дмитро

//WITHOUT WIND CODE

package main


import (

"fmt"

"math/rand"

"strings"


"github.com/fatih/color"

)


func main() {

var j int = 32

space := ""

z := ""

for i := 1; i <= 63; i = i + 2 {

space = strings.Repeat(" ", j)

fmt.Print(space)

if j%6 == 0 { //дощик

z = strings.Repeat("$", i)

col := color.New(color.FgHiCyan)

col.Print(z)

} else {

for n := 1; n <= i; n = n + 1 {

if rand.Intn(20) == 7 { //іграшки

g := rand.Intn(4)

if g == 0 {

col := color.New(color.FgHiRed)

col.Print("♣")

} else if g == 1 {

col := color.New(color.FgHiMagenta)

col.Print("♣")

} else if g == 2 {

col := color.New(color.FgHiBlue)

col.Print("♣")

} else if g == 3 {

col := color.New(color.FgYellow)

col.Print("♣")

}

} else { //гілка з снігом або без

if rand.Intn(24) == 11 {

col := color.New(color.FgHiWhite)

col.Print("*")

} else {

col := color.New(color.FgHiGreen)

col.Print("*")

}

}

}

}

fmt.Print("\n")

j = j - 1

}

j = 32

col := color.New(color.BgYellow)

for i := 0; i < 6; i = i + 1 { //стовбур

space = strings.Repeat(" ", j-2)

fmt.Print(space)

col.Print("   \n")

}

}

//WITH WIND CODE

package main


import (

"fmt"

"math/rand"

"strings"


"github.com/fatih/color"

)


func main() {

var j int = 32

space := ""

z := ""

wind := 28

for i := 1; i <= 63; i = i + 2 {

space = strings.Repeat(" ", j)

if wind > 0 {

space = space + strings.Repeat(" ", wind)

}

fmt.Print(space)

if j%6 == 0 { //дощик

z = strings.Repeat("$", i)

col := color.New(color.FgHiCyan)

col.Print(z)

} else {

for n := 1; n <= i; n = n + 1 {

if rand.Intn(20) == 7 { //іграшки

g := rand.Intn(4)

if g == 0 {

col := color.New(color.FgHiRed)

col.Print("♣")

} else if g == 1 {

col := color.New(color.FgHiMagenta)

col.Print("♣")

} else if g == 2 {

col := color.New(color.FgHiBlue)

col.Print("♣")

} else if g == 3 {

col := color.New(color.FgYellow)

col.Print("♣")

}

} else { //гілка з снігом або без

if rand.Intn(24) == 11 {

col := color.New(color.FgHiWhite)

col.Print("*")

} else {

col := color.New(color.FgHiGreen)

col.Print("*")

}

}

}

}

fmt.Print("\n")

j = j - 1

wind = wind - 1

}

j = 32

wind = 3

col := color.New(color.BgYellow)

for i := 0; i < 6; i = i + 1 { //стовбур

if wind < 0 {

wind = 0

}

space = strings.Repeat(" ", j+(wind-2))

fmt.Print(space)

col.Print("   \n")

wind = wind - 1

}

}

Report Page