Microsoft Small Basic

Program Listing: PWW374-3
' Flickr Sample
' Version 0.5
' Copyright © 2015-2018 Nonki Takahashi. The MIT License.
' Last update 2018-01-21
' Program ID PWW374-3
'
title = "Flickr Sample 0.5"
GraphicsWindow.Title = title
Not = "True=False;False=True;"
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
GraphicsWindow.BackgroundColor = "#333333"
GraphicsWindow.FontName = "Trebuchet MS"
GraphicsWindow.MouseDown = OnMouseDown
n = 0
While "True"
GraphicsWindow.Clear()
GraphicsWindow.Title = title
GraphicsWindow.BrushColor = "White"
GraphicsWindow.DrawText(260, 200, "Loading...")
iw = 0
url = ""
While (iw < 1) Or (ih < 1) Or Array.ContainsValue(list, url)
url = Flickr.GetRandomPicture("origami")
img = ImageList.LoadImage(url)
iw = ImageList.GetWidthOfImage(img)
ih = ImageList.GetHeightOfImage(img)
EndWhile
n = n + 1
list[n] = url
GraphicsWindow.BrushColor = "Black"
tbox = Controls.AddTextBox(10, 370)
Controls.SetSize(tbox, gw - 20, 22)
Shapes.SetOpacity(tbox, 50)
Controls.SetTextBoxText(tbox, url)
Url2Id()
tbox = Controls.AddTextBox(10, 400)
Controls.SetSize(tbox, gw - 20, 22)
Shapes.SetOpacity(tbox, 50)
Controls.SetTextBoxText(tbox, "http://flickr.com/photo.gne?id=" + id)
gwph = gw / gh
iwph = iw / ih
If gwph < iwph Then
scale = gw / iw
x = 0
y = Math.Floor((gh - ih * scale) / 2)
Else
scale = gh / ih
x = Math.Floor((gw - iw * scale) / 2)
y = 0
EndIf
GraphicsWindow.DrawResizedImage(img, x, y, iw * scale, ih * scale)
mouseDown = "False"
While Not[mouseDown]
Program.Delay(300)
EndWhile
EndWhile

Sub Url2Id
' param url
' return id - photo id
p = Text.GetIndexOf(url, "_") - 1
id = ""
c = Text.GetSubText(url, p, 1)
While c <> "/"
id = Text.Append(c, id)
p = p - 1
c = Text.GetSubText(url, p, 1)
EndWhile
EndSub

Sub OnMouseDown
mouseDown = "True"
EndSub