Programming Challenge

Post Reply
User avatar
rbytes
Posts: 1087
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 6
iPad 2
Dell Inspiron laptop
Location: Canada
Flag: Canada
Contact:

Programming Challenge

Post by rbytes » Thu Jun 15, 2017 2:56 am

We haven't seen these on the Forum since the Rosetta Code craze. Can you believe that was months ago?

I am posting the code for a very small program called Seamless that takes a small image of a seamless background pattern and repeats it to fill the screen. It lets me collect all the free backgrounds I want, but only expand them to screen size when I intend to use them. This is my first version, which used a PAUSE command to keep the program running long enough for me to take a screen shot of it.

THE CHALLENGE
Add some code to create a loop that keeps the full-screen image showing indefinitely, but still lets the user end the program when they want to. The technique must be invisible on the pattern.

Hint: I found a way to do this, but not by using GET TOUCH. It would not detect a screen touch because of the full-screen browser that is displaying the image. You may have a better technique than mine.

The attachments are two: a 225 x 225 pixel seamless image of a circuit board, and the 2048 x 1536 image displayed by Seamless.

Code: Select all

/*
/*
Seamless by rbytes
June 2017
creates a screen-filling texture 
background from a small texture image.
Hundreds of free seamless textures
are available on the web.
*/

' Turn off the top toolbar, since we want to show as much of our image as possible
SET TOOLBAR OFF


' Check the size of the screen. This way the browser window can be defined to exactly fit
' the screen.

GET SCREEN SIZE sw,sh


' The browser must have a name given to it

N$="seamless"


' Next we create a full-screen browser window. It does not have any interface,
' so it just displays whatever HTML text is given to it.

BROWSER N$ URL "" AT 0,0 SIZE sw,sh


' Next we define the HTML text. In the body tag, the background is defined as an image
' to be shown. Notice that wherever I need to insert quote characters, I insert three quotes
' in a row. To make net$ work properly, all sections that contain three quotes
' must be joined to the rest of the string with the & character.

net$="<!DOCTYPE HTML><head></head><body background="&"""circuit.jpg"""&"></body></html>"


' Below, we put the HTML string into the browser. Because of the way I defined the
' background image, the browser repeats it horizontally and vertically to fill its
' window. There are other ways to define an image to show it only once, to repeat it
' only horizontally or repeat only vertically. A good site to learn these techniques is
' w3schools.com

BROWSER N$ TEXT net$


' this pause keeps the image on screen just long enough to do a screen capture of it

PAUSE 5
Attachments
IMG_2010.PNG
This is the full-screen image created by Seamless
IMG_2010.PNG (1.63 MiB) Viewed 215 times
IMG_2009.JPG
This is the small image that is repeated to create the large one.
IMG_2009.JPG (49.65 KiB) Viewed 215 times
####### Living the colorful life #######

User avatar
rbytes
Posts: 1087
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 6
iPad 2
Dell Inspiron laptop
Location: Canada
Flag: Canada
Contact:

Re: Programming Challenge

Post by rbytes » Thu Jun 15, 2017 5:29 pm

I just realized that I have been a bit lazy lately about commenting my code. I have changed the code above to add comments.

I am also going to go back to my last few programs and make sure that they are properly commented to explain how they work. :)
####### Living the colorful life #######

User avatar
Henko
Posts: 604
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone 5S, iPad air 2, Windows PC's
Location: Netherlands
Flag: Netherlands

Re: Programming Challenge

Post by Henko » Thu Jun 15, 2017 7:56 pm

Use the accell() function(s) and shake the device

User avatar
rbytes
Posts: 1087
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 6
iPad 2
Dell Inspiron laptop
Location: Canada
Flag: Canada
Contact:

Re: Programming Challenge

Post by rbytes » Thu Jun 15, 2017 9:29 pm

I like that idea, Henk. Will you post the code to do that? It may take a little refining to get the sensitivity just right, so the program doesn't quit before the user can press the screen capture buttons.
####### Living the colorful life #######

User avatar
GeorgeMcGinn
Posts: 250
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Air 2
IMac
Location: Venice, FL
Flag: United States of America
Contact:

Re: Programming Challenge

Post by GeorgeMcGinn » Fri Jun 16, 2017 3:43 pm

Actually, i like the coding challenges, and I have entered some on the SmartBASIC page of the Rosetta Code site, but that page was not set up correctly as my code does not show up on it.

I know that because I copied the techBASIC page after the SB page, and the moderator of the Rosetta site actually corrected the errors in the techBASIC page. Again, none of my code was being listing on the techBASIC page.

I am trying to get the SmartBASIC page fixed so everyone's code is listed, as I know there are more solutions not listed.

Also, since I am looking for something to use my webserver for, I can create a site just for SmartBASIC code challenges, unless there is a way to do this with the current product MR. K uses for these forums.

Just an idea.

George.

User avatar
rbytes
Posts: 1087
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 6
iPad 2
Dell Inspiron laptop
Location: Canada
Flag: Canada
Contact:

Re: Programming Challenge

Post by rbytes » Fri Jun 16, 2017 4:00 pm

That sounds good. But how about my specific challenge? Do you have a solution?
####### Living the colorful life #######

User avatar
GeorgeMcGinn
Posts: 250
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Air 2
IMac
Location: Venice, FL
Flag: United States of America
Contact:

Re: Programming Challenge

Post by GeorgeMcGinn » Fri Jun 16, 2017 9:20 pm

I'll look at it, but I have a challenge out of my own - the Lissajous Knots!
rbytes wrote:
Fri Jun 16, 2017 4:00 pm
That sounds good. But how about my specific challenge? Do you have a solution?

User avatar
rbytes
Posts: 1087
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 6
iPad 2
Dell Inspiron laptop
Location: Canada
Flag: Canada
Contact:

Re: Programming Challenge

Post by rbytes » Sat Jun 17, 2017 2:40 am

Yes, I am looking forward to that.
####### Living the colorful life #######

User avatar
gerry
Posts: 7
Joined: Sun Jun 18, 2017 4:50 pm
My devices: iPhone and ipad
Location: Sarnia ON
Flag: Canada

Re: Programming Challenge

Post by gerry » Sun Jun 18, 2017 5:22 pm

How about this?
to quit-
tap at the upper right corner, you'll see the cursor
And the keybord will popup
press any key to quit

See 6 lines of code added at end

Code: Select all

/*
Seamless by rbytes
June 2017
creates a screen-filling texture 
background from a small texture image.
Hundreds of free seamless textures
are available on the web.
*/

' Turn off the top toolbar, since we want to show as much of our image as possible
SET TOOLBAR OFF


' Check the size of the screen. This way the browser window can be defined to exactly fit
' the screen.

GET SCREEN SIZE sw,sh

' The browser must have a name given to it

N$="seamless"


' Next we create a full-screen browser window. It does not have any interface,
' so it just displays whatever HTML text is given to it.

BROWSER N$ URL "" AT 0,0 SIZE sw,sh


' Next we define the HTML text. In the body tag, the background is defined as an image
' to be shown. Notice that wherever I need to insert quote characters, I insert three quotes
' in a row. To make net$ work properly, all sections that contain three quotes
' must be joined to the rest of the string with the & character.

net$="<!DOCTYPE HTML><head></head><body background="&"""circuit.jpg"""&"></body></html>"


' Below, we put the HTML string into the browser. Because of the way I defined the
' background image, the browser repeats it horizontally and vertically to fill its
' window. There are other ways to define an image to show it only once, to repeat it
' only horizontally or repeat only vertically. A good site to learn these techniques is
' w3schools.com

BROWSER N$ TEXT net$


' instead of the pause ---

FIELD "1" TEXT "" AT sw-100,0 SIZE 100,100 ML
FIELD "1" BACK ALPHA 0
LOOP:
IF FIELD_TEXT$("1")<>"" THEN END
SLOWDOWN
GOTO LOOP
  

User avatar
rbytes
Posts: 1087
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 6
iPad 2
Dell Inspiron laptop
Location: Canada
Flag: Canada
Contact:

Re: Programming Challenge

Post by rbytes » Mon Jun 19, 2017 3:30 am

That works pretty well. Nothing shows until I tap in the top right corner. Good solution!
####### Living the colorful life #######

Post Reply