BBC BASIC for Windows
« Optical illusion »

Welcome Guest. Please Login or Register.
Apr 6th, 2018, 12:25am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Optical illusion  (Read 2154 times)
David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Optical illusion
« Thread started on: Aug 7th, 2014, 4:16pm »

Discovered this by accident. If the illusion works for you, you should see dots at the intersections of the black grid lines. You may also find it irritating to look at. Click a mouse button or press a key to exit:

Code:
      REM +-------------------------------------+
      REM |                                     |
      REM |  "Imaginary Dots" optical illusion  |
      REM |                                     |
      REM +-------------------------------------+

      REM Disable the Escape key
      REM (or rather, prevent it from causing a trappable error if pressed)
      *ESC OFF

      ON ERROR PROCError : QUIT

      REM Setup a full screen display
      GWL_STYLE = -16
      HWND_TOPMOST = -1
      WS_VISIBLE = &10000000
      WS_CLIPCHILDREN = &2000000
      WS_CLIPSIBLINGS = &4000000
      SYS "GetSystemMetrics", 0 TO xscreen%
      SYS "GetSystemMetrics", 1 TO yscreen%
      SYS "SetWindowLong", @hwnd%, GWL_STYLE, WS_VISIBLE + \
      \                    WS_CLIPCHILDREN + WS_CLIPSIBLINGS
      SYS "SetWindowPos", @hwnd%, HWND_TOPMOST, 0, 0, xscreen%, yscreen%, 0
      VDU 26 : COLOUR 15,0,0,0 : CLS : OFF

      REM Get the window width and height
      REM (in this case, the variables xscreen% and yscreen% contain
      REM the width and height, respectively, of the full screen)
      WinW% = xscreen%
      WinH% = yscreen%

      REM Calculate some values
      k% = 12
      p = k%*PI
      q = p/(WinW%-1)

      REM Calculate the grid cell width and height
      CellW% = WinW%/k%
      CellH% = WinH%/k%

      REM Draw a single grid cell
      GCOL 1
      *REFRESH OFF

      FOR Y% = 0 TO CellH%-1
        u = p*Y%/(WinH%-1)
        FOR X% = 0 TO CellW%-1
          REM Calculate the greyscale intensity (in the range 0 to 255)
          I% = INT(255 * ABS(SINu * SIN(X%*q)))
          COLOUR 1, I%, I%, I%
          PLOT 2*X%, 2*Y%
        NEXT
      NEXT

      REM Copy the grid cell to fill the entire program window/screen
      FOR Y%=0 TO WinH% DIV CellH%
        FOR X%=0 TO WinW% DIV CellW%
          RECTANGLE 0, 0, 2*WinW%, 2*CellH% TO 2*X%*CellW%, 2*Y%*CellH%
        NEXT
      NEXT

      *REFRESH

      REM Exit when user presses Escape or some other key,
      REM or clicks a mouse button
      MOUSE OFF
      *REFRESH ON
      PROCWait
      QUIT

      DEF PROCWait
      LOCAL B%, X%, Y%, quit%
      REM Flush the keyboard buffer
      *FX 21,0
      quit% = FALSE
      REPEAT
        MOUSE X%, Y%, B%
        IF INKEY(0)<>-1 OR B%<>0 THEN quit% = TRUE
        WAIT 1 : REM A delay necessary to prevent 100% CPU usage :-)
      UNTIL quit%
      ENDPROC

      DEF PROCError
      *REFRESH ON
      MOUSE ON : CLS : ON : VDU 7 : COLOUR 7 : PRINT '" ";
      REPORT : PRINT " at line "; ERL
      PRINT ''" Press a key or click a mouse button to exit";
      PROCWait
      ENDPROC
 


For a possibly more powerful effect, change k% to 16.

A HD (720p) YouTube video (with music): https://www.youtube.com/watch?v=QeHHqXiLY1c


David.
« Last Edit: Aug 8th, 2014, 06:35am by David Williams » User IP Logged

rtr
Guest
xx Re: Optical illusion
« Reply #1 on: Aug 7th, 2014, 4:33pm »

on Aug 7th, 2014, 4:16pm, David Williams wrote:
If the illusion works for you, you should see dots at the intersections of the black grid lines.

It doesn't work for me.

Richard.
User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: Optical illusion
« Reply #2 on: Aug 7th, 2014, 6:53pm »

I don't know if this sort of thing should come with a health warning, but this next (and final) one I find quite unpleasant to look at:

Code:
      *ESC OFF
      MODE 10 : OFF
      COLOUR 7,148,148,148
      ScrW%=@vdu%!208
      ScrH%=@vdu%!212
      S%=80 : REM grid spacing
      T%=18 : REM grid line thickness
      O%=S%DIV2 : REM grid origin offset
      *REFRESH OFF
      GCOL 7
      FOR Y%=0 TO ScrH% STEP S%
        FOR X%=0 TO ScrW% STEP S%
          RECTANGLE FILL 2*(X%-O%), 0, 2*T%, 2*ScrH%
          RECTANGLE FILL 0, 2*(Y%-O%), 2*ScrW%, 2*T%
        NEXT
      NEXT
      GCOL 15
      FOR Y%=0 TO ScrH% STEP S%
        FOR X%=0 TO ScrW% STEP S%
          K% = O% - T%DIV2
          CIRCLE FILL 2*(X%-K%), 2*(Y%-K%), 2*0.8*T%
        NEXT
      NEXT
      *REFRESH
      *REFRESH ON
      REPEAT UNTIL INKEY(1)=0
 
User IP Logged

Edja
Developer

member is offline

Avatar




PM


Posts: 60
xx Re: Optical illusion
« Reply #3 on: Aug 8th, 2014, 09:09am »

Quote:
you should see dots at the intersections of the black grid lines. You may also find it irritating to look at.
I can't see any dots, but irritating it is !
Eddy
User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: Optical illusion
« Reply #4 on: Aug 8th, 2014, 12:29pm »

on Aug 8th, 2014, 09:09am, Edja wrote:
I can't see any dots, but irritating it is !
Eddy


Irritating, yes. I'd be worried if I were the only one who sees the dots (which are quite faint, admittedly). It might be indicative of some underlying pathology on my part. sad


David.
--
User IP Logged

DDRM
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 321
xx Re: Optical illusion
« Reply #5 on: Aug 11th, 2014, 2:28pm »

Hi David,

Nice to hear from you again!

I see the dots, so whatever you have, I presumably have too! wink

On the first one, I see dots in the areas where I am NOT focussed: they seem to flicker.

On the second one, the dots are really there, but look hollow where I'm not looking.

Impressive demo, too, by the way! I'll have a look at the library, just for fun....

Best wishes,

David
User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: Optical illusion
« Reply #6 on: Aug 11th, 2014, 10:23pm »

on Aug 11th, 2014, 2:28pm, DDRM wrote:
I see the dots, so whatever you have, I presumably have too! wink


That's quite a relief!


Quote:
On the first one, I see dots in the areas where I am NOT focussed: they seem to flicker./quote]

I find the dots disappear if I close one eye, so I think the effect is related to stereo vision. I find it very irritating to look at -- and yet, they're just graduated greyscale rectangles.


[quote]On the second one, the dots are really there, but look hollow where I'm not looking.


I recreated that from this image I found on Google Image:

http://hqwide.com/wallpapers/l/1280x800/31/patterns_textures_grid_illusions_grayscale_optical_illusion_1280x800_30074.jpg



Quote:
Impressive demo, too, by the way! I'll have a look at the library, just for fun....


It's just some bitmap plotters for 2D game-making, all squeezed into 8Kb (in stark contrast to the monstrous GFXLIB). I'm determined to make a Snapper/Pac-Man clone that runs on the demo version of BB4W, mostly for the (not so immense) challenge of it.

A DLL version of GLIB is perfectly possible, would free up a few Kb of precious BB4W demo version memory. The DLL version of the circle finder thing I recently posted about is some 4 to 5 times slower than the straight assembler code version (probably due to code inside the DLL having to be position independent), which was a bit disheartening and means I'll probably not bother with a GLIB dll. Or then perhaps, who knows...

The DLL version of the Wave Plasma demo wasn't noticeably slower (similar frame rate) -- hardly at all in fact. So, I'm not sure what's going on there.


David.
--

User IP Logged

Richey
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 35
xx Re: Optical illusion
« Reply #7 on: Aug 11th, 2014, 11:34pm »

on Aug 11th, 2014, 10:23pm, David Williams wrote:
That's quite a relief!


I see it too... smiley...It's very hard on the eyes...I think I need cool to look at it...

Look forward to the pacman... wink...and to see how much of the code I can decipher... laugh
User IP Logged

rtr
Guest
xx Re: Optical illusion
« Reply #8 on: Aug 12th, 2014, 11:54am »

on Aug 11th, 2014, 10:23pm, David Williams wrote:
A DLL version of GLIB is perfectly possible, would free up a few Kb of precious BB4W demo version memory.

Rather than a DLL (which I'm not very keen on, because the code is 'opaque' and not open to user study and modification) why not use the technique which I demonstrated to allow GDIPLIB to run with the (old) trial version of BB4W? This consists of a small 'wrapper' library which loads the 'real' library into memory allocated with API calls (therefore not consuming BB4W memory) and then links to it.

It's still to be found in the files area of the Yahoo group at Libraries... GDIPLIB_.BBC with the description "Proof of concept of library wrapper technique":

https://groups.yahoo.com/neo/groups/bb4w/files/Libraries/

Richard.
User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: Optical illusion
« Reply #9 on: Aug 12th, 2014, 6:47pm »

on Aug 12th, 2014, 11:54am, Richard Russell wrote:
Rather than a DLL (which I'm not very keen on, because the code is 'opaque' and not open to user study and modification)


Sorry but I'm keen on it. Releasing it with the source code would allow user study and modification (assuming one's willing to install a C/C++ compiler for the latter purpose). I'm especially keen on it because 1) I'm really not a competent assembler programmer, 2) I'm fed up with writing assembly language -- far too time consuming, 3) GCC tends to generate better quality (more efficient) code than I can, 4) I like the idea of making a DLL-based graphics library. No one has to use it, and let's be realistic about this: hardly anyone -- and probably no-one -- will use it. For me, it's just a matter of hobby fulfillment. Frankly I don't give a toss if anyone uses it or not. Since I only intend to write assembler code if my life depends on it, I'll code speed-critical routines in C and get the compiler to generate a DLL or an assembly language dump (that hardly anyone would be able or want to study, understand and modify anyway).

This C/DLL stuff is mostly about me avoiding ASM coding!


on Aug 12th, 2014, 11:54am, Richard Russell wrote:
why not use the technique which I demonstrated to allow GDIPLIB to run with the (old) trial version of BB4W?


I may take a look, thanks for the pointer (*).


David.
--
User IP Logged

rtr
Guest
xx Re: Optical illusion
« Reply #10 on: Aug 12th, 2014, 8:25pm »

on Aug 12th, 2014, 6:47pm, David Williams wrote:
I'm determined to make a Snapper/Pac-Man clone that runs on the demo version of BB4W, mostly for the (not so immense) challenge of it.

There is no challenge if you use a DLL - you simply move as much code into the DLL as is necessary to allow the remaining program to fit. smiley

There's a nice Liberty BASIC version of PacMan which has been translated into BBC BASIC using LBB, although it won't fit in the trial version. I'll take a look to see if it could be shrunk enough to do so (it doesn't use any of LB's native graphics - everything's done using GDI32 API calls - so it doesn't need the LBLIB library).

Quote:
Frankly I don't give a toss if anyone uses it or not.

Presumably any DLL you build could equally well be called from other programming languages - including Liberty BASIC and C itself. You might find a more receptive audience elsewhere.

Richard.
« Last Edit: Aug 12th, 2014, 8:33pm by rtr » User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: Optical illusion
« Reply #11 on: Aug 12th, 2014, 9:03pm »

on Aug 12th, 2014, 8:25pm, Richard Russell wrote:
There is no challenge if you use a DLL - you simply move as much code into the DLL as is necessary to allow the remaining program to fit. smiley


I was referring to only the graphics library, not game logic. smiley


Quote:
There's a nice Liberty BASIC version of PacMan which has been translated into BBC BASIC using LBB, although it won't fit in the trial version.


I like how clicking on the link sends you to Google instead (Alyce's doing, presumably).

Using LBB 2.53, the game translates and runs without complaint, except the window doesn't update. It's initially black (I can hear the sound effects), and it only updates after I've dragged the window around to force an update, but it still doesn't update automatically. I'm using Win7 / 64-bit.

Quote:
Presumably any DLL you build could equally well be called from other programming languages - including Liberty BASIC and C itself. You might find a more receptive audience elsewhere.


If I was concerned about having a receptive audience for my solitary, hobbyist coding activites, I'd be using Python, Java (which I'm learning), DarkBASIC, Raspberry Pi, etc. Huge communities.


David.
--
User IP Logged

rtr
Guest
xx Re: Optical illusion
« Reply #12 on: Aug 13th, 2014, 12:24am »

on Aug 12th, 2014, 9:03pm, David Williams wrote:
Using LBB 2.53, the game translates and runs without complaint, except the window doesn't update.

The program requires modification to be compatible with LBB (as many do). Run it in genuine Liberty BASIC if you want to try it.

Richard.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls