Liberty BASIC Community Forum
Liberty BASIC Programming Discussions >> Liberty BASIC Code >> 'Magic Eye' 3D images
http://libertybasic.conforums.com/index.cgi?board=LB3&action=display&num=1454613942

'Magic Eye' 3D images
Post by tenochtitlanuk on Feb 4th, 2016, 1:25pm

The person named in my previous post has not replied, so presumably couldn't see their name in the image. Can you?
View the image at full size, and try to look THROUGH your screen, allowing your eyes to de-focus.
User Image
I wonder how many can see the depth in THIS image- you'll see my favourite dog at a new level..
User Image
Re: 'Magic Eye' 3D images
Post by Chris Iverson on Feb 4th, 2016, 1:30pm

I can see them both. I think he's been busy lately.
Re: 'Magic Eye' 3D images
Post by Rod on Feb 4th, 2016, 1:52pm

I can clearly see CARL and I can see great depth of focus in the second image but it is just straight bands, not sure if I am missing anything.
Re: 'Magic Eye' 3D images
Post by tenochtitlanuk on Feb 4th, 2016, 3:17pm

Well done, both! Surprising (?) how frustrated those who don't see the depth get, to the extent of insisting it doesn't exist and is just a mass hypnosis or mass hysteria conspiracy!
Yup, Rod, the dogs come in rows at different depths. Some people find this easier to see. And it distinguishes 'cross-eyed' viewers from 'normal'- they disagree on which rows are nearest/furthest.
I'll add the dog code to my site soon. At present I resize the dogs manually ( in GIMP) but will probably add ImageMagick code to do it automatically....

I for one have been glad to see Carl around more, recently!
Re: 'Magic Eye' 3D images
Post by bluatigro on Feb 5th, 2016, 06:49am


due to my albinism
i m unable to see 3d

but i m intersested how to create this
and maybe even animation ?
or is the last not visable ?


Re: 'Magic Eye' 3D images
Post by tenochtitlanuk on Feb 5th, 2016, 1:36pm

There's a zip file which includes code and three images to play with. Random Dot ( SIRDS) stereograms are on my site already. I particularly enjoyed using the image of 'our' Queen...

Thanks to RR for pointing out the scaling can be done without calling an external program.

Bluatigro- I hadn't thought of trying animation. May have a play sometime. I knew about your vision problems- you are a great example of what can be achieved by determination against handicaps.
Re: 'Magic Eye' 3D images
Post by tenochtitlanuk on Feb 6th, 2016, 06:48am

There's an excellent tutorial at Wikipedia
It includes an animated example, but I find it tiring and rather difficult to watch.
Re: 'Magic Eye' 3D images
Post by tenochtitlanuk on Feb 6th, 2016, 3:50pm

Plato's Cave roof with added LB flares... easiest viewed at full size.
User Image
Re: 'Magic Eye' 3D images
Post by bluatigro on Feb 7th, 2016, 08:07am

first try at magic eye 3d

Code:
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy , mmx , eye , you
winx = WindowWidth
winy = WindowHeight
mmx = 925
you = 1000
eye = 70 ''eyedistance
dim dx( winy )
for i = 0 to winy
  dx( i ) = rnd(0) * eye
next i
nomainwin
in$ = str$( mmx )
prompt "Screen size X in mm =" ; in$
mmx = val( in$ )
in$ = str$( you )
prompt "Screen - you distance in mm =" ; in$
you = val( in$ )
open "3d eye test" for graphics as #m
  #m "trapclose [quit]"
  for y = 0 to winy
    x = dx( y )
    while x < winx
      #m "goto ";x;" ";y
      #m "down"
      #m "set ";x;" ";y
      #m "up"
      x = x + fx( fz( x , y ) )
    wend
  next y
wait
[quit]
  close #m
end
function fx( z )
''calculate offset of next point
''if z = 0 then point is on screen
  fx = ( you - z ) * eye * mmx / winx / you
end function
function fz( x , y )
  x = x - winx / 2
  y = y - winy / 2
  uit = 0
  if sqr( x^2 + y^2 ) < 300 then
    uit = -200
  end if
  fz = uit
end function
 

Re: 'Magic Eye' 3D images
Post by bluatigro on Feb 7th, 2016, 09:08am

update :
- now whit colors
Code:
WindowWidth = DisplayWidth / 2
WindowHeight = DisplayHeight / 2
global winx , winy , mmx , eye , you , pi
pi = atn( 1 ) * 4
winx = WindowWidth
winy = WindowHeight
mmx = 925
you = 1000
eye = 70 ''eyedistance
dim dx( winy )
for i = 0 to winy
  dx( i ) = rnd(0) * 360
next i
nomainwin
in$ = str$( mmx )
prompt "Screen size X in mm =" ; in$
mmx = val( in$ )
in$ = str$( you )
prompt "Screen - you distance in mm =" ; in$
you = val( in$ )
open "3d eye test" for graphics as #m
  #m "trapclose [quit]"
  for y = 0 to winy
    hoek = dx( y )
    for x = 0 to winx
      scan
      #m "color ";rainbow$(hoek)
      #m "goto ";x;" ";y
      #m "down"
      #m "set ";x;" ";y
      #m "up"
      hoek = hoek + 360 / fx( fz( x , y ) )
    next x
  next y
wait
[quit]
  close #m
end
function fx( z )
''calculate offset of next point
''if z = 0 then point is on screen
  fx = ( you - z ) * eye * mmx / winx / you
end function
function fz( x , y )
  x = x - winx / 2
  y = y - winy / 2
  uit = 0
  if sqr( x^2 + y^2 ) < winy / 4 then
    uit = -200
  end if
  fz = uit
end function
function rad( deg )
  rad = deg * pi / 180
end function
function rainbow$( deg )
  r = sin( rad( deg ) ) * 127 + 128
  g = sin( rad( deg + 120 ) ) * 127 + 128
  b = sin( rad( deg - 120 ) ) * 127 + 128
  rainbow$ = rgb$( r , g , b )
end function
function rgb$( r , g , b )
  r = int( r ) and 255
  g = int( g ) and 255
  b = int( b ) and 255
  rgb$ = str$( r ) ; " " ; g ; " " ; b
end function
 

Re: 'Magic Eye' 3D images
Post by Rod on Feb 7th, 2016, 09:31am

I can clearly see the big circular hole in the middle of the first image but I am not getting anything from the color image, what am I supposed to see?
Re: 'Magic Eye' 3D images
Post by bluatigro on Feb 9th, 2016, 06:14am



@rod :
- both images are the same

i was aming at a floting filledcircle , not a hole
in both pictures
so aparently i did somthing wrong

update :
- i think i fond the error in point version
Code:
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy , mmx , eye , you
winx = WindowWidth
winy = WindowHeight
mmx = 350
you = 500
eye = 70 ''eyedistance
dim dx( winy )
for i = 0 to winy
  dx( i ) = rnd(0) * eye / mmx * winx
next i
nomainwin
in$ = str$( mmx )
prompt "Screen size X in mm =" ; in$
mmx = val( in$ )
in$ = str$( you )
prompt "Screen - you distance in mm =" ; in$
you = val( in$ )
open "3d eye test" for graphics as #m
  #m "trapclose [quit]"
  for y = 0 to winy
    x = dx( y )
    while x < winx
      #m "goto ";x;" ";y
      #m "down"
      #m "set ";x;" ";y
      #m "up"
      x = x + fx( fz( x , y ) )
    wend
  next y
wait
[quit]
  close #m
end
function fx( z )
''calculate offset of next point
''if z = 0 then point is on screen
  fx = ( you - z ) * eye * mmx / winx / you
end function
function fz( x , y )
  x = x - winx / 2
  y = y - winy / 2
  uit = 0
  if sqr( x^2 + y^2 ) < 300 then
    uit = -100
  end if
  fz = uit
end function
 

Re: 'Magic Eye' 3D images
Post by Rod on Feb 9th, 2016, 06:19am

Your first try was better a very clear sunken circle. The latest code is very vague, there is a hint of a central circle but it does not look like a floating plate.
Re: 'Magic Eye' 3D images
Post by cundo on Feb 12th, 2016, 10:04am

I have tried to see something, but no luck for me. ;( I think I don't have my eyes perfectly aligned.