Last active
May 6, 2019 21:45
-
-
Save wybiral/a461698f073de93a60aaed0223baa54e to your computer and use it in GitHub Desktop.
noscript animation using streamed CSS
This file contains 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 ( | |
"encoding/hex" | |
"fmt" | |
"math/rand" | |
"net/http" | |
"time" | |
) | |
const delay = time.Second / 10 | |
func main() { | |
http.HandleFunc("/", handler) | |
http.ListenAndServe(":8080", nil) | |
} | |
func handler(w http.ResponseWriter, r *http.Request) { | |
w.Header().Set("Content-Type", "text/html; charset=utf-8") | |
flusher, ok := w.(http.Flusher) | |
if !ok { | |
return | |
} | |
w.Write([]byte(`<head> | |
<style> | |
*{margin:0;padding:0} | |
html,body{width:100%;height:100%} | |
p{width:20px;height:20px;display:inline-block} | |
</style> | |
</head> | |
<body> | |
`)) | |
for i := 0; i < 16; i++ { | |
w.Write([]byte("<div>")) | |
for j := 0; j < 16; j++ { | |
w.Write([]byte(fmt.Sprintf("<p id=\"c%d%d\"></p>", i, j))) | |
} | |
w.Write([]byte("</div>\n")) | |
} | |
w.Write([]byte("</body>\n")) | |
flusher.Flush() | |
b := make([]byte, 3) | |
for { | |
w.Write([]byte("<style>")) | |
for i := 0; i < 16; i++ { | |
for j := 0; j < 16; j++ { | |
rand.Read(b) | |
c := hex.EncodeToString(b) | |
s := fmt.Sprintf("#c%d%d{background:#%s}", i, j, c) | |
w.Write([]byte(s)) | |
} | |
} | |
_, err := w.Write([]byte("</style>\n")) | |
if err != nil { | |
return | |
} | |
flusher.Flush() | |
time.Sleep(delay) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment