why couldnt it get the accurate value of w to show str normally?
--# Main
displayMode(STANDARD)
function setup()
local bounds = vec2(600, 300)
logoImg = nil
fontSize(96)
local generate = function()
logoImg = genLogo(bounds)
end
parameter.text("NAME", "Title Here", generate)
parameter.integer("FONT", 1, 9, 1, generate)
parameter.action("Regenerate", generate)
end
function genLogo(bounds)
local pal = {
palettes.winter,
}
local fonts = {
("AmericanTypewriter-Bold"),
("ArialRoundedMTBold"),
("Futura-Medium"),
("Futura-CondensedExtraBold"),
("Courier-Bold"),
("HelveticaNeue-Light"),
("Noteworthy-Bold"),
("SourceSansPro-Bold"),
("Vegur-Bold"),
}
local pidx = 1
local fidx = FONT or 1
local img = image(bounds:unpack())
font(fonts[fidx])
setContext(img)
renderString(NAME, bounds, pal[pidx])
setContext()
return img
end
function draw()
-- This sets a dark background color
background(85, 85, 108, 255)
-- This sets the line thickness
strokeWidth(5)
-- Do your drawing here
sprite(logoImg, WIDTH/2, HEIGHT/2)
end
function renderString(str, bounds, scheme)
pushStyle()
textAlign(CENTER)
local w,h = textSize(str)
local xoffset = bounds.x/2 - w/3
local ycenter = bounds.y/2
str:gsub(".", function(c)
w = textSize(c)
local pos = vec2(xoffset, ycenter)
pushMatrix()
translate(pos:unpack())
--translate(-pos:unpack())
blendMode(NORMAL)
fill(scheme[2])
text(c, 0, 0)
popMatrix()
xoffset = xoffset + w
end)
popStyle()
end
--# Palettes
palettes = {}
palettes.winter = {
color(241, 243, 243, 255),
color(169, 219, 223, 255),
color(59, 130, 169, 255),
color(38, 80, 83, 255),
}