Microsoft Small Basic

Program Listing: VCZ347
' Monochrome
' Version 0.1
' Copyright © 2016 Nonki Takahashi. The MIT License.

Init()

While "True"
tag = tags[Math.GetRandomNumber(5)]
url = Flickr.GetRandomPicture(tag)
img = ImageList.LoadImage(url)
iw = ImageList.GetWidthOfImage(img)
ih = ImageList.GetHeightOfImage(img)
If gw < iw Then
iw = gw - 20
ih = ih * (gw - 20) / iw
EndIf
If gh < ih Then
ih = gh - 20
iw = iw * (gh - 20) / ih
EndIf
x = Math.Floor((gw - iw) / 2)
y = Math.Floor((gh - ih) / 2)
GraphicsWindow.Clear()
GraphicsWindow.DrawResizedImage(img, x, y, iw, ih)
GraphicsWindow.Title = url
Process()
Program.Delay(2000)
EndWhile

Sub Process
For _y = y To y + ih - 1
n = 0
line[n] = "l=-1;"
For i = 1 To iw
p = GraphicsWindow.GetPixel(x + (i - 1), _y)
hex = Text.GetSubText(p, 2, 2)
Hex2Dec()
r = dec
hex = Text.GetSubText(p, 4, 2)
Hex2Dec()
g = dec
hex = Text.GetSubText(p, 6, 2)
Hex2Dec()
b = dec
min = Math.Min(Math.Min(r, g), b)
l = min + Math.Round(((r - min) * 2 + (g - min) * 4 + (b - min)) / 7)
If 153 < l Then
c = 2
ElseIf 102 < l Then
c = 1
Else
c = 0
EndIf
If c <> line[n]["c"] Then
n = n + 1
line[n]["c"] = c
line[n]["n"] = 1
Else
line[n]["n"] = line[n]["n"] + 1
EndIf
EndFor
_x = x
For i = 1 To n
c = line[i]["c"]
GraphicsWindow.BrushColor = color[c]
'GraphicsWindow.BrushColor = GraphicsWindow.GetColorFromRGB(l, l, l)
GraphicsWindow.FillRectangle(_x, _y, line[i]["n"], 1)
_x = _x + line[i]["n"]
EndFor
EndFor
EndSub

Sub Init
debug = "False"
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
GraphicsWindow.BackgroundColor = "Black"
GraphicsWindow.PenWidth = 1
tags = "1=toy;2=building;3=house;4=bird;5=flower;"
color = "0=#222222;1=#CCCCCC;2=#EEEEEE;"
EndSub

Sub Hex2Dec
' param hex
' return dec
len = Text.GetLength(hex)
dec = 0
For k = 1 To len
h = Text.ConvertToUpperCase(Text.GetSubText(hex, k, 1))
d = Text.GetIndexOf("123456789ABCDEF", h)
dec = dec * 16 + d
EndFor
EndSub