Skip to content

Instantly share code, notes, and snippets.

@AntonioCiolino
Created April 11, 2013 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AntonioCiolino/5367189 to your computer and use it in GitHub Desktop.
Save AntonioCiolino/5367189 to your computer and use it in GitHub Desktop.
Simple interface to create glossy buttons. uses primitives and clip() to an image - no mesh code.
-- Glossy
-- Use this function to perform your initial setup
function setup()
ellipseMode(CENTER)
rectMode(CORNER)
parameter.text("myText")
parameter.number("bluroffset", -10,25,1.5)
parameter.integer("glossintensity", 1,24,8)
parameter.integer("blursize", -10, 10, 0)
parameter.integer("iter", 1, 10, 5)
parameter.integer("iw", 1, 500, 120)
parameter.integer("ih", 1, 250,40)
parameter.integer("edge", 3,20,8)
parameter.color("forecolor")
parameter.color("highlight")
parameter.integer("fontsize", 8,64, 12)
forecolor = color(166, 124, 78, 255)
highlight = color(166, 75, 173, 255)
btncol = forecolor
myText = "1"
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(40, 40, 50)
img = image(iw, ih)
setContext (img)
font("HelveticaNeue-Bold")
fontSize(fontsize)
clip(img.width, img.height)
--draw base object
fill(btncol)
roundRect(0,0,iw,ih, edge)
--create iterative brightening
for x = 1,iter do
strokeWidth(1)
blendMode(ADDITIVE)
stroke(0, 0, 0, 127)
x = glossintensity
fill(x,x,x, 255)
ellipse(iw/2,ih,iw*1.5-(x*blursize),ih-bluroffset)
end
--blur under the text itself --unused!
-- blendMode(MULTIPLY)
-- stroke(255,255,255, 255)
-- fill(bl,bl,bl,254)
-- w,h=textSize(myText)
--ellipse(40,20, w*1.5,h*1.5)
--dropshadow text
blendMode(NORMAL)
textMode(CENTER)
fill(46, 44, 44, 127)
text(myText, iw/2,ih/2+1)
--full-on text
fill(255, 255, 255, 255)
text(myText, iw/2,ih/2)
setContext()
clip()
--show it
screenpos = vec2(WIDTH/2, HEIGHT/2)
sprite(img, screenpos.x, screenpos.y)
img=nil
end
function touched(touch)
if touch.state == ENDED then
btncol = forecolor
else
btncol = highlight
end
end
--borrowed to get the rounded rect!
function roundRect(x,y,w,h,r)
pushStyle()
insetPos = vec2(x + r,y + r)
insetSize = vec2(w - 2 * r,h - 2 * r)
blendMode(NORMAL) -- solved the balls and lines showing through!
local red, green, blue, a = fill()
stroke(red, green, blue, a)
noSmooth()
rectMode(CORNER)
rect(insetPos.x, insetPos.y, insetSize.x, insetSize.y)
if r > 0 then
smooth()
lineCapMode(ROUND)
strokeWidth(r * 2)
line(insetPos.x, insetPos.y,
insetPos.x + insetSize.x, insetPos.y)
line(insetPos.x, insetPos.y,
insetPos.x, insetPos.y + insetSize.y)
line(insetPos.x, insetPos.y + insetSize.y,
insetPos.x + insetSize.x, insetPos.y + insetSize.y)
line(insetPos.x + insetSize.x, insetPos.y,
insetPos.x + insetSize.x, insetPos.y + insetSize.y)
end
popStyle()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment