View Full Version : contrast (color) illusion
Lionheart008
25-06-2010, 21:09
hi all.
somebody who likes black/white/grey contrast illusions here a little example from my side. there's only a little mistake in first optical line to show the right column size of black rectangles. perhaps anybody can give a little tip where to fix it.
look at the white circles and the black boxes (switch between them). so you're eyes will get after some seconds a grey or black flash for the white circles:) the example I have modified and translated from an old powerbasic example.
' Empty GUI script created on 06-25-2010 19:07:31 by franko lionheart (ThinAIR)
Uses "ui","console"
Begin Const
%close = %WM_USER + 500
%canv
%spread = 4
End Const
Function TBMain() As Long
Local xsize,ysize As Long
Local hdlg As Long
Local mygraf As Long
Local lenx,leny,proport,zx,zy,i,j As Long
xsize = 800
ysize = 600
Dialog New Pixels,0,"Contrast Illusion 1c",-1,-1,xsize,ysize,%WS_SYSMENU Or %WS_MINIMIZEBOX Or %WS_CAPTION To hDlg
Control Add Button, hDlg, %Close, "closeMe", 100, 556, 80, 24 Call close() 'Escape, closebutton not visible ;)
Control Add Canvas, hDlg, %canv, "", 0, 0, xsize, ysize, %SS_NOTIFY
Control Handle hDlg,%canv To mygraf
Canvas_Attach mygraf, 0
proport = 10 '20
lenx = (xsize - proport*7)/8
leny = (ysize - proport*5)/6.2
Canvas_Clear(Rgb(100,100,100))
Canvas_Scale Pixels
zx = 10
zy = 10
For i = 1 To 6
For j = 1 To 8
If j < 8 And i < 6 Then
Canvas_Ellipse (zx+lenx-%spread,zy+leny-%spread, zx+lenx+proport+%spread,zy+leny+proport+%spread,%WHITE,%WHITE) '%YELLOW,%YELLOW)
End If
Canvas_Box (zx,zy, zx+lenx,zy+leny,20,0,0)
zx = zx + lenx + proport
Next
zx = 0
zy = zy + leny + proport
Next
Canvas_Redraw
Dialog Show Modal hDlg Call showme()
End Function
'------------------------------------------------------------------------------
CallBack Function showme() As Long
Select Case CBMSG
Case %WM_INITDIALOG
Canvas_Attach(CBHNDL, %canv, %FALSE)
'---
Canvas_Redraw
Case %WM_COMMAND
Select Case CBCTL
Case %IDCANCEL
Dialog End CBHNDL '
End Select
End Select
End Function
'------------------------------------------------------------------------------
CallBack Function close() As Long
Select Case CBMSG
Case %WM_COMMAND
If CBWPARAM = %Close Then
Dialog End CBHNDL
End If
Case %WM_DESTROY
MsgBox 0, "close and end dialog"
End Select
End Function
edit: fixed height of rectangles. "leny = (ysize - proport*5)/6.2"
best regards, frank
Lionheart008
25-06-2010, 21:56
problem solved :)
' Empty GUI script created on 06-25-2010 19:07:31 by franko lionheart (ThinAIR)
Uses "ui" ',"console"
Begin Const
%close = %WM_USER + 500
%canv
%spread = 4
End Const
Function TBMain() As Long
Local xsize,ysize As Long
Local hdlg As Long
Local mygraf As Long
Local lenx,leny,proport,zx,zy,i,j As Long
xsize = 800
ysize = 600
Dialog New Pixels,0,"Contrast Illusion 1d",-1,-1,xsize,ysize,%WS_SYSMENU Or %WS_MINIMIZEBOX Or %WS_CAPTION To hDlg
Control Add Button, hDlg, %Close, "closeMe", 100, 556, 80, 24 Call close() 'Escape, closebutton not visible ;)
Control Add Canvas, hDlg, %canv, "", 0, 0, xsize, ysize, %SS_NOTIFY
Control Handle hDlg,%canv To mygraf
Canvas_Attach mygraf, 0
proport = 10 '20
lenx = (xsize - proport*7)/8
leny = (ysize - proport*5)/6.2
Canvas_Clear(Rgb(100,100,100))
Canvas_Scale Pixels
zx = 1
zy = 10
For i = 1 To 6
For j = 1 To 8
If j < 8 And i < 6 Then
Canvas_Ellipse (zx+lenx-%spread,zy+leny-%spread, zx+lenx+proport+%spread,zy+leny+proport+%spread,%WHITE,%WHITE) '%YELLOW,%YELLOW)
End If
Canvas_Box (zx,zy, zx+lenx,zy+leny,20,0,0)
zx = zx + lenx + proport
Next
zx = 0
zy = zy + leny + proport
Next
Canvas_Redraw
Dialog Show Modal hDlg Call showme()
End Function
'------------------------------------------------------------------------------
CallBack Function showme() As Long
Select Case CBMSG
Case %WM_INITDIALOG
Canvas_Attach(CBHNDL, %canv, %FALSE)
'---
Canvas_Redraw
Case %WM_COMMAND
Select Case CBCTL
Case %IDCANCEL
Dialog End CBHNDL '
End Select
End Select
End Function
'------------------------------------------------------------------------------
CallBack Function close() As Long
Select Case CBMSG
Case %WM_COMMAND
If CBWPARAM = %Close Then
Dialog End CBHNDL
End If
Case %WM_DESTROY
MsgBox 0, "close and end dialog"
End Select
End Function
fixed width correction of rectangles/circles with zx = 1
zx = 1
zy = 10
now you find the right size for rectangles, circles and rows and columns.
servus, regards, frank
danbaron
26-06-2010, 07:35
[font=courier new][size=8pt]I am able to get the entire image, to appear to sink into the screen.
When I was a boy, I did something similar when sitting on the toilet, and staring at the bathroom tiles. Only then, the image seemed to rise above the floor (maybe because the tiles were white?).
Dan :twisted:
thanks for this ,
i see some black hollow circles in place of some of the white circles, it is moving when i move my eyes.
Lionheart008
26-06-2010, 08:59
thanks zak, dan, yes, the effect is known since many years. I have noticed and learned first time as child from school. We have some exercises with art science and optical illusions. My head and my eyes has (after moving head to white papers and this patterns) a lot of difficult to see again with plain view ;)
here a little but more precious example with blocks (boxes) and lines. have a short look at this picture, that's really incredible! :D
' Empty GUI script created on 06-26-2010 8:45:22 by franko lionheart (ThinAIR)
Uses "ui" ',"console"
Begin Const
%close = %WM_USER + 500
%canv
%spread = 4
End Const
Function TBMain() As Long
Local xsize,ysize As Long
Local hdlg As Long
Local mygraf As Long
Local lenx,leny,proport,zx,zy,i,j As Long
xsize = 800
ysize = 600
Dialog New Pixels,0,"Line/Block Illusion 2a",-1,-1,xsize,ysize,%WS_SYSMENU Or %WS_MINIMIZEBOX Or %WS_CAPTION To hDlg
Control Add Button, hDlg, %Close, "closeMe", 100, 556, 80, 24 Call close() 'Escape, closebutton not visible ;)
Control Add Canvas, hDlg, %canv, "", 0, 0, xsize, ysize, %SS_NOTIFY
Control Handle hDlg,%canv To mygraf
Canvas_Attach mygraf, 0
lenx = xsize/14
leny = ysize/8
Canvas_Clear(Rgb(255,255,255))
Canvas_Scale Pixels
zx = 0
zy = 0
For i = 1 To 8
For j = 1 To 8
Canvas_Box (zx,zy, zx+lenx,zy+leny, 0,Rgb(50,50,50),0)
zx = zx + lenx*2
Next
zy = zy + leny
Select Case i
Case 1,3,5,7
zx = 1*lenx/3
Case 2,6
zx = 2*lenx/3
Case 4
zx = 0
End Select
Next
For i=1 To 8
Canvas_Line ((0,i*leny), (xsize,i*leny),Rgb(100,200,100))
Next
Canvas_Redraw
Dialog Show Modal hDlg Call showme()
End Function
'------------------------------------------------------------------------------
CallBack Function showme() As Long
Select Case CBMSG
Case %WM_INITDIALOG
Canvas_Attach(CBHNDL, %canv, %FALSE)
'---
Canvas_Redraw
Case %WM_COMMAND
Select Case CBCTL
Case %IDCANCEL
Dialog End CBHNDL '
End Select
End Select
End Function
'------------------------------------------------------------------------------
CallBack Function close() As Long
Select Case CBMSG
Case %WM_COMMAND
If CBWPARAM = %Close Then
Dialog End CBHNDL
End If
Case %WM_DESTROY
MsgBox 0, "close and end dialog"
End Select
End Function
by the way, a little question:
does something like Canvas_Line width 1 exists for thicker lines/circles?
servus, best regards, frank
Lionheart008
26-06-2010, 09:24
part three: circle-rectangle illusion :)
' Empty GUI script created on 06-26-2010 9:17:45 by franko lionheart (ThinAIR)
Uses "ui" ',"console"
Begin Const
%close = %WM_USER + 500
%canv
%spread = 4
End Const
Function TBMain() As Long
Local xsize,ysize As Long
Local hdlg As Long
Local mygraf As Long
Local lenx,leny,proport,zx,zy,i,j As Long
xsize = 800
ysize = 600
Dialog New Pixels,0,"Circle Rectangle Illusion 3a",-1,-1,xsize,ysize,%WS_SYSMENU Or %WS_MINIMIZEBOX Or %WS_CAPTION To hDlg
Control Add Button, hDlg, %Close, "closeMe", 100, 556, 80, 24 Call close() 'Escape, closebutton not visible ;)
Control Add Canvas, hDlg, %canv, "", 0, 0, xsize, ysize, %SS_NOTIFY
Control Handle hDlg,%canv To mygraf
Canvas_Attach mygraf, 0
lenx = xsize/4
zx = xsize/2
zy = ysize/2
Canvas_Clear(Rgb(255,255,255))
Canvas_Scale Pixels
For j = ysize/2 To 1 Step -10
Canvas_Ellipse (zx-j,zy-j, zx+j,zy+j,0) 'rgb(0,200,250)
Next
Canvas_Box (zx-lenx,zy-lenx, zx+lenx,zy+lenx,0,0)
Canvas_Redraw
Dialog Show Modal hDlg Call showme()
End Function
'------------------------------------------------------------------------------
CallBack Function showme() As Long
Select Case CBMSG
Case %WM_INITDIALOG
Canvas_Attach(CBHNDL, %canv, %FALSE)
'---
Canvas_Redraw
Case %WM_COMMAND
Select Case CBCTL
Case %IDCANCEL
Dialog End CBHNDL '
End Select
End Select
End Function
'------------------------------------------------------------------------------
CallBack Function close() As Long
Select Case CBMSG
Case %WM_COMMAND
If CBWPARAM = %Close Then
Dialog End CBHNDL
End If
Case %WM_DESTROY
MsgBox 0, "close and end dialog"
End Select
End Function
frank
ErosOlmi
26-06-2010, 09:26
Nice illusions.
Impressive how our brain makes some "speculations" on reality
does something like Canvas_Line width 1 exists ?
No, but I will add for next release.
Petr Schreiber
26-06-2010, 09:59
Hi Frank,
very nice illusions, thanks for the code :)
Petr
Lionheart008
26-06-2010, 10:24
thanks eros, petr, you are welcome.
here a little question about "%WM_Timer" and "Dialog Set Timer" for my next example. It doesn't work clear, because there should be a short moving into two half circles away from centre point. I've tried to do it with a loop (incr counter), but that's nonsense. I have had a look at the buffer example from canvas folder, but this doesn't work here.
circles-anima-example (just with this little problem):
' Empty GUI script created on 06-26-2010 9:17:45 by franko lionheart (ThinAIR)
Uses "ui" ',"console"
Begin Const
%close = %WM_USER + 500
%canv
%spread = 4
%IDC_TIMER = 100
%TIMER_DELAY = 15
End Const
Function TBMain() As Long
Local xsize,ysize As Long
Local hdlg As Long
Local mygraf As Long
Local lenx,leny,proport,zx,zy,i,j,v1,v2,v3 As Long
Static deltas As Long
Local tx, ty As Long
Local counter As Long
xsize = 800
ysize = 600
Dialog New Pixels,0,"Circle+Rectangle Anima moves apart - Illusion 4a",-1,-1,xsize,ysize,%WS_SYSMENU Or %WS_MINIMIZEBOX Or %WS_CAPTION To hDlg
Control Add Button, hDlg, %Close, "closeMe", 100, 556, 80, 24 Call close()
Control Add Canvas, hDlg, %canv, "", 0, 0, xsize, ysize, %SS_NOTIFY
Control Handle hDlg,%canv To mygraf
Canvas_Attach mygraf, 0
lenx = xsize/4
leny = ysize/2
zx = lenx - deltas
zy = leny/2
v1 = Rgb(150,150,150)
v2 = Rgb(235,235,235)
v3 = Rgb(215,215,215)
Canvas_Clear(Rgb(255,255,255))
Canvas_Scale Pixels
Canvas_Box (zx,zy, zx+lenx,zy+leny,0,v1,v1 )
Canvas_Ellipse (zx+lenx-100,ysize/2-100, zx+lenx+100,ysize/2+100)
Canvas_Ellipse (zx+lenx-50,ysize/2-50, zx+lenx+50,ysize/2+50)
zx = zx +lenx + deltas*2
Canvas_Box (zx,zy, zx+lenx,zy+leny,0,v2,v2)
Canvas_Ellipse (zx-100,ysize/2-100, zx+100,ysize/2+100)
Canvas_Ellipse (zx-50,ysize/2-50, zx+50,ysize/2+50)
Canvas_Redraw
If deltas<= 0 Then
Sleep 500
End If
If deltas<= 0 Then
i=1
End If
zx = lenx - deltas
deltas = deltas +.5*i
If deltas > 100 Then i = -1 End If
deltas = 100
deltas = deltas +.5*i
Canvas_Redraw
Dialog Show Modal hDlg Call showme()
End Function
'------------------------------------------------------------------------------
CallBack Function showme() As Long
Select Case CBMSG
Case %WM_INITDIALOG
Canvas_Attach(CBHNDL, %canv, %FALSE)
Dialog Set Timer CBHNDL, %IDC_TIMER, %TIMER_DELAY
Canvas_Redraw
Case %WM_TIMER
'If CBWPARAM = 1 Then
'Canvas_Attach(CBHNDL, %canv, %FALSE)
'Canvas_Redraw
'End If
Case %WM_DESTROY
Dialog Kill Timer CBHNDL, %IDC_TIMER
Case %WM_COMMAND
Select Case CBCTL
Case %IDCANCEL
Dialog End CBHNDL '
End Select
End Select
End Function
'------------------------------------------------------------------------------
CallBack Function close() As Long
Select Case CBMSG
Case %WM_COMMAND
If CBWPARAM = %Close Then
Dialog End CBHNDL
End If
Case %WM_DESTROY
MsgBox 0, "close and end dialog"
End Select
End Function
perhaps anybody can help to solve this %WM_Timer problem in callback function.
best regards, frank
Petr Schreiber
26-06-2010, 11:15
Hi Frank,
I am not sure what do you want to do with the code manipulating deltas (it ends on value 100),
but as seen on attached code, you can do dynamic animation easily.
The problem in your code was that you rendered once after dialog creation and not later.
Petr
' Empty GUI script created on 06-26-2010 9:17:45 by franko lionheart (ThinAIR)
Uses "ui"
Begin Const
%close = %WM_USER + 500
%canv
%spread = 4
%IDC_TIMER = 100
%TIMER_DELAY = 15
End Const
Global xSize, ySize As Long
Function TBMain() As Long
Local hdlg As Long
xsize = 800
ysize = 600
Dialog New Pixels,0,"Circle+Rectangle Anima moves apart - Illusion 4a",-1,-1,xsize,ysize+35,%WS_SYSMENU Or %WS_MINIMIZEBOX Or %WS_CAPTION To hDlg
Control Add Canvas, hDlg, %canv, "", 0, 0, xsize, ysize, %SS_NOTIFY
Control Add Button, hDlg, %Close, "closeMe", xsize-85, ysize+5, 80, 24 Call close()
DrawImage(hDlg, %canv)
Dialog Show Modal hDlg Call showme()
End Function
'------------------------------------------------------------------------------
CallBack Function showme() As Long
Select Case CBMSG
Case %WM_INITDIALOG
' -- Create timer
Dialog Set Timer CBHNDL, %IDC_TIMER, %TIMER_DELAY
Case %WM_TIMER
DrawImage(CBHNDL, %canv)
Case %WM_CLOSE
' -- Destroy timer
Dialog Kill Timer CBHNDL, %IDC_TIMER
End Select
End Function
'------------------------------------------------------------------------------
CallBack Function close() As Long
If CBMSG = %WM_COMMAND And CBCTLMSG = %BN_CLICKED Then
Dialog End CBHNDL
End If
End Function
'------------------------------------------------------------------------------
Sub DrawImage( hDlg As DWord, cCanvas As Long )
Local lenx, leny, proport, zx, zy, i, j, v1, v2, v3 As Long
Static deltas As Long
' -- Rendering
Canvas_Attach(hDlg, cCanvas, %TRUE)
lenx = xsize/4
leny = ysize/2
zx = lenx - deltas
zy = leny/2
v1 = Rgb(150,150,150)
v2 = Rgb(235,235,235)
v3 = Rgb(215,215,215)
Canvas_Clear(%WHITE)
Canvas_Scale Pixels
Canvas_Box (zx, zy, zx+lenx, zy+leny, 0, v1, v1)
Canvas_Ellipse (zx+lenx-100, ysize/2-100, zx+lenx+100, ysize/2+100)
Canvas_Ellipse (zx+lenx-50, ysize/2-50, zx+lenx+50, ysize/2+50)
zx = zx +lenx + deltas*2
Canvas_Box (zx, zy, zx+lenx,zy+leny, 0, v2, v2)
Canvas_Ellipse (zx-100, ysize/2-100, zx+100, ysize/2+100)
Canvas_Ellipse (zx-50, ysize/2-50, zx+50, ysize/2+50)
Canvas_Redraw
' -- Logic --------------------------------------------------------------------- CHANGE THE LOGIC OF DELTAS
deltas = Sin(GetTickCount/1000)*40
' If deltas<= 0 Then
' Sleep 500
' End If
'
' If deltas <= 0 Then
' i=1
' End If
'
' zx = lenx - deltas
' deltas = deltas +0.5*i
'
' If deltas => 100 Then
' i = -1
' End If
'
' deltas = 100
' deltas = deltas +0.5*i
End Sub
Nice examples of illusions Frank, thanks.
Lionheart008
28-06-2010, 09:01
short: thanks kent, thanks petr for your help. My idea was to split the two circles (cut into two parts) and move them apart. But I wanted to have something like a "donut" or a "wheel" of two parts with different grey color shapes. I will check my last example again this week, it's not ready ;)
thanks, nice week, here's a very hot sommer these days in germany and
by the way: WE WILL WIN THE SOCCER WORDL CUP ! :D
http://de.fifa.com/
servus, best regards, frank
ErosOlmi
28-06-2010, 12:02
thanks, nice week, here's a very hot sommer these days in germany and
by the way: WE WILL WIN THE SOCCER WORDL CUP ! :D
Do you know the Magic Number theory on Soccer World Cup:
http://fourfourtwo.com/blogs/championsleague/archive/2010/02/09/magic-numbers-bubbly-amp-brandreth.aspx
Based on that theory this is the year of ... Germany :D
Lionheart008
29-06-2010, 14:06
Based on that theory this is the year of ... Germany Very Happy
thanks for the link eros, yes, that would be great for 110 per Cent ! :)
here I add the fixed example of circle moving apart anima (two posts before). there are two issues, one with grey and other with grey-black circle center. if you are trying these examples you'll see the different. last black-grey example is my personal favourite.
' Empty GUI script created on 06-26-2010 9:17:45 by franko lionheart (ThinAIR)
' add: grey colors for ellipse and sleep function
Uses "ui"
Begin Const
%close = %WM_USER + 500
%canv
%spread = 4
%IDC_TIMER = 100
%TIMER_DELAY = 15
%stops
End Const
Global xSize, ySize As Long
Function TBMain() As Long
Local hdlg As Long
xsize = 800
ysize = 600
Dialog New Pixels,0,"Circle+Rectangle Anima moves apart - Illusion 4bb_greyBlack",-1,-1,xsize,ysize+35,%WS_SYSMENU Or %WS_MINIMIZEBOX Or %WS_CAPTION To hDlg
Control Add Canvas, hDlg, %canv, "", 0, 0, xsize, ysize, %SS_NOTIFY
Control Add Button, hDlg, %Close, "closeMe", xsize-85, ysize+5, 80, 24 Call close()
Control Add Button, hDlg, %stops, "sleep", xsize-185, ysize+5, 80, 24
DrawImage(hDlg, %canv)
Dialog Show Modal hDlg Call showme()
End Function
'------------------------------------------------------------------------------
CallBack Function showme() As Long
Select Case CBMSG
Case %WM_INITDIALOG
' -- Create timer
Dialog Set Timer CBHNDL, %IDC_TIMER, %TIMER_DELAY
Case %WM_COMMAND
If CBWPARAM = %stops Then
Sleep 5500
DrawImage(CBHNDL, %canv)
End If
Case %WM_TIMER
DrawImage(CBHNDL, %canv)
Case %WM_CLOSE
' -- Destroy timer
Dialog Kill Timer CBHNDL, %IDC_TIMER
End Select
End Function
'------------------------------------------------------------------------------
CallBack Function close() As Long
If CBMSG = %WM_COMMAND And CBCTLMSG = %BN_CLICKED Then
Dialog End CBHNDL
End If
End Function
'------------------------------------------------------------------------------
Sub DrawImage(ByVal hDlg As DWord, ByVal cCanvas As Long )
Local lenx, leny, proport, zx, zy, i, j, v1, v2, v3 As Long
Static deltas As Long
' -- Rendering
Canvas_Attach(hDlg, cCanvas, %TRUE)
lenx = xsize/4
leny = ysize/2
zx = lenx - deltas
zy = leny/2
v1 = Rgb(150,150,150)
v2 = Rgb(235,235,235)
v3 = Rgb(215,215,215)
Canvas_Clear(%WHITE)
Canvas_Scale Pixels
Canvas_Box (zx, zy, zx+lenx, zy+leny, 0, v1, v1)
Canvas_Ellipse (zx+lenx-100, ysize/2-100, zx+lenx+100, ysize/2+100, Rgb(235,235,235), -1)
Canvas_Ellipse (zx+lenx-50, ysize/2-50, zx+lenx+50, ysize/2+50,Rgb(5,5,5), -1)
zx = zx +lenx + deltas*1.15
Canvas_Box (zx, zy, zx+lenx,zy+leny, 0, v2, v2)
Canvas_Ellipse (zx-100, ysize/2-100, zx+100, ysize/2+100, Rgb(150,150,150), -1)
Canvas_Ellipse (zx-50, ysize/2-50, zx+50, ysize/2+50, Rgb(255,255,255), -1)
Canvas_Redraw
Sleep 10
deltas = Sin(GetTickCount/1500)*54
End Sub
both examples added.
best regards, frank