Greyscale bars/Display: Difference between revisions

Content added Content deleted
No edit summary
(Added Go)
Line 576: Line 576:


'''[http://www.cogier.com/gambas/GreyScale.png Click here for image of the output]'''
'''[http://www.cogier.com/gambas/GreyScale.png Click here for image of the output]'''

=={{header|Go}}==
{{libheader|Go Graphics}}
{{trans|Java}}
<lang go>package main

import (
"github.com/fogleman/gg"
"math"
)

func greyBars(dc *gg.Context) {
run := 0
colorComp := 0.0 // component of the color
for colCount := 8; colCount < 128; colCount *= 2 {
// by this gap we change the background color
colorGap := 255.0 / float64(colCount-1)
colWidth := float64(dc.Width() / colCount)
colHeight := float64(dc.Height() / 4)
// switches color directions with each iteration of for loop
if run%2 == 0 {
colorComp = 0.0
} else {
colorComp = 255.0
colorGap = -colorGap
}
xstart, ystart := 0.0, colHeight*float64(run)
for i := 0; i < colCount; i++ {
icolor := int(math.Round(colorComp)) // round to nearer integer
dc.SetRGB255(icolor, icolor, icolor)
dc.DrawRectangle(xstart, ystart, colWidth, colHeight)
dc.Fill()
xstart += colWidth
colorComp += colorGap
}
run++
}
}

func main() {
dc := gg.NewContext(640, 320)
greyBars(dc)
dc.SavePNG("greybars.png")
}</lang>

{{out}}
<pre>
Image similar to R entry (first image)
</pre>


=={{header|Haskell}}==
=={{header|Haskell}}==