Created
March 31, 2014 03:54
A CoffeeScript answer for http://codegolf.stackexchange.com/questions/19214/render-a-version-of-the-bbc-micro-owl-logo
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
<!DOCTYPE html> | |
<body> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/coffee-script/1.7.1/coffee-script.min.js"></script> | |
<script src="owl.coffee" type="text/coffeescript"></script> |
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
canvas = document.createElement 'canvas' | |
canvas.style.backgroundColor = '#240202' | |
canvas.style.transform = 'scale(0.5) translate(-480px,-570px)' | |
W = canvas.width = 960 | |
H = canvas.height = 1140 | |
D = 50 | |
R = D / 2 | |
ctx = canvas.getContext '2d' | |
imageData = ctx.getImageData 0, 0, W, H | |
data = imageData.data | |
owl = ''' | |
\ * * * * * * * * * | |
\ * * * * | |
\ * * * * * | |
\ * * * * | |
\ * * * * | |
\ * * * * | |
\ * * * * * | |
\ * * * | |
\ * * * * * * * * | |
\ * * * * | |
\ * * * * * * | |
\ * * * * | |
\ * * * * * | |
\ * * * * | |
\ * * * * * | |
\ * * * * | |
\ * * * * * | |
\ * * * | |
\ * * * * | |
\ * * * * * * * | |
\ * | |
'''.split '\n' | |
insideDot = (x, y) -> | |
w = 0 | |
for du in [-1..1] then for dv in [-1..1] | |
u = x // D + du | |
v = y // D + dv | |
continue unless owl[v]?[u] is '*' | |
dx = x - (u * D + R) | |
dy = y - (v * D + R) | |
d = dx * dx + dy * dy | |
w += 1 / (d * d) | |
return yes if w > 0.0000008 | |
no | |
for y in [0...H] then for x in [0...W] when insideDot x, y | |
i = (y * W + x) * 4 | |
data[i] = data[i+1] = data[i+3] = 255 | |
data[i+2] = 214 | |
ctx.putImageData imageData, 0, 0 | |
document.body.appendChild canvas |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://bl.ocks.org/9884954