Highlighting an image (glass effect)
Posted: Sun May 10, 2009 5:21 pm
some days ago, netmaestro posted a nice alarm clock which had a superb white shining area which looked like a glass...
I tried to do something like that and after a while I had the first success - an elliptical segment which is bright white in the middle and gets darker and darker to its edges.
But on thenNext step, transferring the code to alpha transparency, everything went wrong and I did not find a clue how to get it running for now
Any idea how to get this stuff running?
Thanks,
Michael
I tried to do something like that and after a while I had the first success - an elliptical segment which is bright white in the middle and gets darker and darker to its edges.
But on thenNext step, transferring the code to alpha transparency, everything went wrong and I did not find a clue how to get it running for now

Code: Select all
Procedure.f QuickDistanz(x1.l,y1.l,x2.l)
x1-x2
x1*x1
ProcedureReturn Sqr(x1+y1)
EndProcedure
Procedure GlassEffect(Image)
Structure BGRA
blue.c
green.c
red.c
alpha.c
EndStructure
Protected bmp.BITMAP
Protected *bits.BGRA,*px.BGRA
Protected w.l,h.l
Protected scaler.f
Protected shifter.l
Protected b1x.l,bx2.l
Protected x.l,y.l,ys.l
Protected c.b
GetObject_(ImageID(image), SizeOf(BITMAP),bmp)
*bits=bmp\bmBits
; Breite und Höhe
w=bmp\bmWidthBytes
h=bmp\bmHeight
; Tricksen...
scaler=650/h
shifter=h-h>>2
; Brennpunkte
bx1=w>>3
b2x=w-b1x
For y=0 To h
ys=y*y*scaler
For x=0 To w>>1
c=(QuickDistanz(x,ys,b1x)+QuickDistanz(x,ys,b2x))-(b2x-b1x)
If c<0
c=0
Else
c*2
If c<0
c=0
ElseIf c>255
c=255
EndIf
EndIf
If y%3=0
If shifter+y/3<h
*px=*bits+bmp\bmWidthBytes*(y/3+shifter)+x
*px\alpha=c
*px=*bits+bmp\bmWidthBytes*(y/3+shifter)+w-x
*px\alpha=c
EndIf
EndIf
If shifter-y>0
*px=*bits+bmp\bmWidthBytes*(shifter-y)+x
*px\alpha=c
*px=*bits+bmp\bmWidthBytes*(shifter-y)+w-x
*px\alpha=c
EndIf
Next x
Next y
EndProcedure
w=200
h=100
CreateImage(0,200,100)
StartDrawing(ImageOutput(0))
Box(0,0,200,100,#Red)
DrawText(0,0,"Just a Test")
DrawText(50,30,"Just a Test")
DrawText(100,50,"Just a Test")
StopDrawing()
OpenWindow(0,0,0,w,h,"",$CF0001)
ImageGadget(0,0,0,w,h,ImageID(0))
#Glass=1
CreateImage(#Glass,200,100,32)
StartDrawing(ImageOutput(#Glass))
Box(0,0,150,100,#White)
StopDrawing()
GlassEffect(#Glass)
dc = StartDrawing(WindowOutput(0))
DrawAlphaImage(ImageID(#Glass),0,0)
StopDrawing()
Repeat:Until WaitWindowEvent()=#WM_CLOSE
Thanks,
Michael