From 548e52b2e4dc0d4193cb39b9c11b87fe6086ecb3 Mon Sep 17 00:00:00 2001 From: Jan Bessler Date: Tue, 24 Feb 2026 18:20:30 +0100 Subject: [PATCH] feat: cleaned up code --- main.go | 45 ++++++++++++++++++++++++++------------------- out.png | Bin 3829 -> 3805 bytes 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/main.go b/main.go index 7449887..f17b54a 100644 --- a/main.go +++ b/main.go @@ -8,24 +8,41 @@ import ( "github.com/fogleman/gg" ) -// 8x8 square of 100x100 px squares +/* +8x8 square of 100x100 px squares + +First 6 characters of the hash are the color +For the next 8 characters each character +represents 4 bits of a row being on or off. +The image is then mirrored to the right side. + +9d26bf3cf1fb2b2f02d4a2013333f4fcd551cb2e +9d26bf -> color + 3 -> row1 + c -> row2 + ... + b -> row8 +3 = 0 0 1 1 +c = 1 1 0 0 +... +b = 1 0 1 1 +*/ func main() { dc := gg.NewContext(800, 800) - hash := hash("InsightForgeOrg") + hash := hash("Jaybee18") colorString := hash[0:6] r, g, b := rgbFromHex(colorString) dc.SetRGB255(r, g, b) for i, character := range hash[6:14] { - tmp, _ := strconv.ParseUint(string(character), 16, 8) - n := int(tmp) - for _, v := range []uint{0, 1, 2, 3} { - on := hasBit(n, v) + integer, _ := strconv.ParseUint(string(character), 16, 4) + for j := range 4 { + on := hasBit(integer, j) - dc.DrawRectangle(float64(v * 100), float64(i * 100), 100, 100) - dc.DrawRectangle(700 - float64(v * 100), float64(i * 100), 100, 100) + dc.DrawRectangle(float64(j * 100), float64(i * 100), 100, 100) + dc.DrawRectangle(700 - float64(j * 100), float64(i * 100), 100, 100) if !on { dc.SetRGB255(r, g, b) } else { @@ -52,17 +69,7 @@ func hash(str string) string { return fmt.Sprintf("%x", res) } -func hasBit(n int, pos uint) bool { +func hasBit(n uint64, pos int) bool { val := n & (1 << pos) return (val > 0) } - -// 9d26bf3cf1fb2b2f02d4a2013333f4fcd551cb2e -// 9d26bf -> color -// 3 -> row1 -// c -> row2 -// ... -// b -> row8 - -// 3 = 0 0 1 1 -// diff --git a/out.png b/out.png index cca0fc2baf888664d21de25b67f567ed45be6286..fb653f67e446d937d76d0d8b48b599eba3ad589b 100644 GIT binary patch delta 304 zcmew=dslXXiqjHL7srr_Id5(__RdHUal7c(ES|G~H8JBLThl%MQlL3s_jVzZKvA{)LU9!N2g}=8v3CARSf0x|f;nJ&8E~l9Rz8ZU45H zoa-MpZERf1IProw*YBP0tE-q94lLiXc_FVA&U=>2bxbCC zrP}-V@2~skm}`CgqVTef`o~{z+Dwq%bDsAT=YMy828If$%@0`@F-~F=li&FL1*7rJ zbERKeGT)pwtU6?}N89co@4e@2??115_qlnqB3lwrT@-h9ZT;V#dkhR8H0m}x@-{I} zUch86_x>Vt+NQa$UvOT&F+CY*LPdB@6Udr-&tvaCXWwkdw3m_R9?)zyh6JWr5AEzX zGqN=SO|#jBVI||7&9a0#8>zmvv4FO#rY~ BktF~C