Skip to content

Commit

Permalink
Add build arguments to choose the file
Browse files Browse the repository at this point in the history
  • Loading branch information
hugolgst committed Mar 15, 2020
1 parent 95c65be commit 95f6d02
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: go
go:
- "1.14"
6 changes: 3 additions & 3 deletions image/draw.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func DrawPoint(img image.RGBA, x, y, width int, color color.RGBA) {

// DrawCircle draws in the given image the middle circle of the visualization with
// the 10 segments in color.
func DrawCircle(img image.RGBA, radius, width, imageWidth, imageHeight int) {
func DrawCircle(img image.RGBA, radius, width, image int) {
fmt.Println("Drawing main circle")

// Draw multiples layers for the width
Expand All @@ -63,8 +63,8 @@ func DrawCircle(img image.RGBA, radius, width, imageWidth, imageHeight int) {
}

// Calculate the coordinates for `t` in the center of the image
x := float64(radius + w) * math.Cos(t) + float64(imageWidth/2)
y := float64(radius + w) * math.Sin(t) + float64(imageHeight/2)
x := float64(radius + w) * math.Cos(t) + float64(image/2)
y := float64(radius + w) * math.Sin(t) + float64(image/2)
// Draw the point
img.Set(int(x), int(y), color)

Expand Down
8 changes: 4 additions & 4 deletions image/visualization.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import (
)

// DrawData draws in the given image all the points for the parsed decimals
func DrawData(img image.RGBA, parsedDigits [][][]int, imageWidth, imageHeight int) {
func DrawData(img image.RGBA, parsedDigits [][][]int, radius, image int) {
fmt.Println("Drawing the data")

// Iterate through segments
for segmentIndex, segment := range parsedDigits {
// Browse all the lines
for line := 0; line < len(segment); line++ {
// Calculate the radius for the actual line
r := float64(420 + line * 25)
r := float64(radius*5/4 + line * radius/15)

// Arbitrary number of iterations
iterations := 55
Expand All @@ -25,8 +25,8 @@ func DrawData(img image.RGBA, parsedDigits [][][]int, imageWidth, imageHeight in
// Draw the points
for i := 0; i < int(iterations*2); i++ {
// Calculate the coordinates
x1 := r*math.Cos(t)+float64(imageWidth/2)
y1 := r*math.Sin(t)+float64(imageHeight/2)
x1 := r*math.Cos(t)+float64(image/2)
y1 := r*math.Sin(t)+float64(image/2)

t += math.Pi/float64(iterations)
size := iterations/5
Expand Down
19 changes: 13 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@ func CreateImage(width int, height int, background color.RGBA) *image.RGBA {
}

func main() {
filePath := os.Args[1]
if filePath == "" {
fmt.Println("The file path was not found, using resources/pi by default.")
filePath = "resources/pi.txt"
}

// Read and parse π
pi := digits.SerializeDigits("resources/pi.txt", 2300)
d := 2000
pi := digits.SerializeDigits(filePath, d)
parsedDigits := digits.ParseDigits(pi)

// Create the image
Expand All @@ -31,18 +38,18 @@ func main() {
panic(err)
}

width, height := 4500, 4500
dim := d*2
background := color.RGBA{A: 255}
img := CreateImage(width, height, background)
img := CreateImage(dim, dim, background)

// Draw the elements
digartImage.DrawCircle(*img, 350, 40, width, height)
digartImage.DrawData(*img, parsedDigits, width, height)
digartImage.DrawCircle(*img, 350, 40, dim)
digartImage.DrawData(*img, parsedDigits, 350, dim)

err = png.Encode(out, img)
if err != nil {
panic(err)
}

fmt.Println("Image saved.")
}
}

0 comments on commit 95f6d02

Please sign in to comment.