Created
August 22, 2018 11:09
-
-
Save codecakes/86e55b1941c23fba79691da7230ba1e7 to your computer and use it in GitHub Desktop.
a golang exercise to render a blue pixel image of dimensions dx, dy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "golang.org/x/tour/pic" | |
type funcIntType func(int) | |
func DivideFn(lo, hi int, fn funcIntType) { | |
if mid := int((hi - lo)/2 + lo); lo < hi { | |
DivideFn(lo, mid, fn) | |
DivideFn(mid+1, hi, fn) | |
} else { | |
fn(lo) | |
} | |
} | |
func RecurseDn(dx, dy int, array [][]uint8) funcIntType { | |
return func (idy int) { | |
uint8_array := make([]uint8, dx, dx) | |
for j := 0; j < dx; j++ { | |
uint8_array[j] = uint8(dy^dx) << uint8(j) | |
} | |
array[idy] = uint8_array | |
} | |
} | |
func Pic(dx, dy int) [][]uint8 { | |
var array = make([][]uint8, dy, dy) | |
DivideFn(0, dy-1, RecurseDn(dx, dy, array)) | |
return array | |
} | |
func main() { | |
pic.Show(Pic) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
so a loop at L:28 but using a divide and conquer where a generic function needs to be used, I enforced a type. a dynamic function in a scripted language would be easy. enforcing a new typedef like function construct was explicit. Good!
learnt: