Minor script improvements
// Downloading and displaying the palettes
// from web-site https://lospec.com
// if you liked the displayed palette, you can stop the display using Ctrl+C
// and copy the array of colors displayed on the screen
import "json"
// DON'T change this values
// lospec.com API constants
ColorNumberFilterType = {}
ColorNumberFilterType.any = "any"
ColorNumberFilterType.max = "max"
ColorNumberFilterType.min = "min"
ColorNumberFilterType.exact = "exact"
SortingType = {}
SortingType.default = "default"
SortingType.alphabetical = "alphabetical"
SortingType.downloads = "downloads"
SortingType.newest = "newest"
// as a rule, in most cases, just changing this parameter
// to search for different palettes
colorNum = 16
// you can change these values for different searches
colorType = ColorNumberFilterType.exact
page = 0
tag = ""
sortingType = SortingType.downloads
// you can change these values for different views
boxSize = 100
// get ninimal size for boxes
if colorNum > 8 then boxSize = 900 / colorNum
startPosX = 480 - (colorNum / 2) * boxSize
startPosY = 400
border = 10
// DON'T change this values
imagesHost = "https://lospec.com/images/palette-list/"
request = "https://lospec.com/palette-list/load?" +
"colorNumberFilterType=" + colorType +
"&colorNumber=" + colorNum +
"&page=" + page +
"&tag=" + tag +
"&sortingType=" + sortingType
// get request
result=http.get(request)
// trick for fixing bug in MiniMicro v.0.91
if result isa RawData then result = result.utf8
// parse result
js=json.parse(result)
// all finded palettes
palettes=js["palettes"]
// here is a display of the found palettes
for pal in palettes
clear
// draw colors back
gfx.color = color.gray
gfx.fillRect startPosX - border, startPosY - border, (boxSize * colorNum) + border * 2, boxSize + border * 2
// printing name of palette
print pal["title"]
// printing author name
if pal.hasIndex("user") == 1 then
if pal["user"].hasIndex("name") == 1 then
print "Author: " + pal["user"]["name"]
end if
end if
// drawing colors
colors = pal["colorsArray"]
msg = "["
for i in range(0, colors.len-1)
gfx.color = colors[i]
msg = msg + """" + colors[i] + """" + " ,"
gfx.fillRect startPosX + (i * boxSize), startPosY, boxSize, boxSize
end for
msg = msg - " ,"
print msg + "]"
// printing example
if pal.hasIndex("examples") == 1 then
examples = pal["examples"]
if (examples.len > 0) then
s = new Sprite
url = imagesHost + examples[0]["filename"]
img = http.get(url)
s.image = img
s.x = 480
s.y = 200
s.scale = 2
display(4).sprites.push s
end if
end if
wait 3
end for