Just Code Challenge Week 13 Projects

Post your Just Code Challenge Week 13 Projects in this conversation! The blog post with my project will be published on Friday and I’ll update this conversation when this it is published.

So whenever you finish your week 13 project, go ahead and post it here. Have fun and be sure to download other projects and discuss! Only 1 more week after this!

This week’s submission is a 3D graph plotter.
Enter a math formula as a function of x and y.
Enter the range of the variables.
Click plot. Voila!

The 3D plot is simply an oblique cabinet projection, with the perspective slightly adjustable with the “Oblique Ratio” slider. The shading routine is a down and dirty algorithm that I threw together in a hurry, but works far better than I expected.

I’ll point out that in the example formula shown in the picture, there is a singularity when either x or y is exactly equal to zero (divide by zero error). So, I set the increment values in the example so that x and y will never be exactly zero.

This was written and tested on a Mac using 2016r3, which remains my go to version for development. I also confirmed that it works with 2018r1.1 although graphics appear to be about 2-3 times slower. Not tested on Windows.

BTW, Thanks to Jeff Tullin for his suggestion of using a timer to solve a live scroll issue with the colour slider.

The formula to be plotted is evaluated using my ExpressionEvaluator class which I posted about in the distant past. It is included in the project file, but can be downloaded separately (with detailed documentation) here: Expression Evaluator Class

The project file is here: GraphIt Project File

Ah… I see what you are doing with the slider.
To be honest, you didnt need the slider.
The user could click on the color bar, and redraw in response. :slight_smile:

I run it in 2015r1: nice.

I tried Graph It on Windows with Xojo 2018r2 but when I press ‘Plot’ it’s saying:

Improperly formed expression. Invalid symbol "*" " sin ( x ) * sin ( y ) / ( x * y ) "

A very simple interface to make use of the ‘OMDBAPI’, a free (or paid for) API to recall details of movies along the lines of the Internet Movie Database. A precursor for this project is to get a free API key at http://www.omdbapi.com/apikey.aspx.

Type your key into the Action event of the Search button on line 11 and all should work. Type a film name in the title text field and get the plot and JSON string returned.

There is a fairly comprehensive return of information in the API but I have just chosen to show the ‘plot’. Your are limited to 1,000 searches a day with the free key. The project is certainly open for updating and modification as there is a lot more information than the plot available. I use this code as part of my ‘media library web application’ so that I can search my collection when out shopping ensuring I don’t buy films I already have. I have over 1,000 so its easy done!

Link to xojo binary file

The code is one very simple button action event.

if txtTitle.text<>"" then //we need something to search for so ensure you enter a title
  
  //lookup plot from omdb
  
  Dim http As New HTTPSocket
  dim t, plot as text
  dim plotjs as new JSONItem
  dim title as string=EncodeURLComponent(txtTitle.text)
  dim s as string
  //enter your own API key at the end of the the next line within the quotes
  dim apikey as string=""
  
  //http://www.omdbapi.com/?t=star+wars
  //http://www.omdbapi.com/?apikey=[yourkey]&
  
  s=http.Get("http://www.omdbapi.com/?apikey="+apikey+"&t="+title+"&plot=full", 30)
  s=s.DefineEncoding(Encodings.UTF8)
  t=s.ToText
  
  plotjs.load(t)
  
  if plotjs.value("Response")<>"False" then
    
    txtPlot.text=plotjs.value("Plot")
    txtJSON.text=t
  else
    txtPlot.text="Plot not found"
  end if
  
else
  
  msgbox("Enter a title to search for the plot.")
  
end if

My project this week is Xojo Speed, an iOS app that can function as a speedometer in your vehicle.

https://blog.xojo.com/2018/09/14/justcode-challenge-week-13-xojo-speed/

My contribution for week 13 is a Xojo Module providing additional string functionality. Since I started doing development with Xojo last year I was often looking for string methods like Contains(), StartsWith() or the very powerfull string.Format() method known from .net/C#. So, therefore I started to implement a Module providing Contains(), StartsWith(), EndsWith() and a Format2() method which can be used standalone or as string extension. Below are some examples.

Dim s1, s2 As String 
s1 = "Hello {0} of {1}, color is {2}, today is {4:ddd d. MMM yyyy - hh:mm:ss}, amount: {3:0.00}"
s2 = s1.Format2("World", 23, Color.Black, 1.2345, Xojo.Core.Date.Now)

Print(s2)
// Result: Hello World of 23, color is &h00000000, today is Friday 14. September 2018 - 15:07:55, amount: 1,23

Print(Format2("Starts with 'hell': {0}", s2.StartsWith("hell")))
// Result: Starts with 'hell': True

Print(Format2("Ends with 'the end': {0}", s2.EndsWith("the end")))
// Result: Ends with 'the end': False

Print(Format2("Contains 'Sept': {0}", s2.Contains("Sept")))
// Result: Contains 'Sept': True

Format2() expects as first parameter a string containing any text and placeholders in the form of {0} {1} {2}. Second parameter is a ParamArray of type Variant, containing the variables that will be replacing the placholders. The number between the curly bracket refects the order of the parameter. Format2() also understands format masks (right to the colon) for some data-types, like Double and Date.

Dates can be formatted using patterns like dd-MM-yyyy, where single characters will become single numbers (d -> 1), double characters will become two digits (dd -> 01) and tripple characters for day or month will become names (ddd -> Monday, MMM -> September). Uppercase M is treated as month and lowercase m as minutes.

I’ve put the Module into a Console project, please dowload here:

[quote=405560:@Stefan Watermann]I tried Graph It on Windows with Xojo 2018r2 but when I press ‘Plot’ it’s saying:

Improperly formed expression. Invalid symbol "*" " sin ( x ) * sin ( y ) / ( x * y ) " [/quote]
I just tried it on my Mac with 2018r2, and I get the same error. So, it doesn’t appear to be specifically Windows related. It’s something that’s changed between 2018r1 and 2018r2. I’ll have to dig into it further, and report back.

Contains() ? What about InStr and InStrB ?
StartsWith() ? What about Left() ?
(Nota: Mid() and Right() also exists).

Unless they are different.

[quote=405574:@Emile Schwarz]Contains() ? What about InStr and InStrB ?
StartsWith() ? What about Left() ?
(Nota: Mid() and Right() also exists).

Unless they are different.[/quote]
programs are easier to read with such methods. I did it also in a module I use in all programs.
even if it’s just a placeholder.
for startswith, instead of left, you have to calculate each time the length of the string, so it’s not just a simple replacement.

There are two such extension modules already available - have a look at Joe Strouts StingUtilities and Kem’s (I think) Mstring module.

One can also learn by studying good code, and it doesn’t get much better than these guys:

StringUtils http://www.strout.net/info/coding/rb/intro.html

M String MacTechnologies Consulting (914) 500-8878

[quote=405630:@Markus Winter]There are two such extension modules already available - have a look at Joe Strouts StingUtilities and Kem’s (I think) Mstring module.

One can also learn by studying good code, and it doesn’t get much better than these guys:

StringUtils http://www.strout.net/info/coding/rb/intro.html

M String http://www.mactechnologies.com/index.php?page=downloads[/quote]

Thanks, good hints, but from my understanding JustCode challange means that you do your own coding, right? It’s not about doing something better than others. Most of the programs people did for the challange do exist already. And the main method I wanted to do is the Format2(), the others are only there because it was handy to have them.

Sure. It’s also about learning, so I pointed to two other modules. That way you can compare your solution with what two experts came up with:

This week, I propose an application full of controls and timing: a virtual keyboard for transmitting Morse messages. A classic, but that can be adapted to other encoding systems.

Source and win32 exe are here:
https://www.ascinfo.fr/fichiers/justcodechallenge2018/MorsePlay.zip

This week I wrote a little game. You have to catch the falling pears. This can be done with the mouse.

Sourcecode Download

[quote=405560:@Stefan Watermann]I tried Graph It on Windows with Xojo 2018r2 but when I press ‘Plot’ it’s saying:

Improperly formed expression. Invalid symbol "*" " sin ( x ) * sin ( y ) / ( x * y ) " [/quote]
It turns out that there is a bug in XOJO 2018r2 which corrupts numeric attributes when it opens project files saved by earlier versions. I’ve filed a bug report. <https://xojo.com/issue/53343>
It appears that if you repair the damage using the 2018r2 IDE and resave the project file, then the attributes will be saved as quoted text values which seem to work correctly. I’ve uploaded a revised version of the project which works under 2018r2: GraphIt revised project file

Last week I was on a ship, and this week I forgot to upload on Friday! Argh! So either count this as a late entry for this week, or an early entry for next week!

Number Shuffler

This little utility was created to be used in conjunction with the Lo Shu Numerology app I made a few weeks ago.

To do a numerology reading you need to ask someone for their birthdate, cell phone number, and other numbers with significance to them — all data that identity thieves would have a ball with!

In order to make people more comfortable in handing that info over, I made the Number Shuffler. The intention is to create it into an iOS app so I can hand them my iPhone or iPad and have them enter the numbers, hit the “Shuffle” button, and then hand it back to me. I’ll have all the digits I need to give them a reading, but now there’s no security risk.

(No video preview this week.)

Here’s where you can grab the project:
http://jayjennings.com/justcode/NumberShuffler.zip

PS - The typo in the screenshot above is fixed in the downloadable project! :wink:

I added an option to move alt_MsgBox relative to its centred position.
Boolean: alt_MsgBox_Relative_Position

[code]Position alt_MsgBox

If alt_MsgBox_Relative_Position = False then
alt_MsgBox_Top - Top position of alt_MsgBox in relation to the available top position of the main screen
alt_MsgBox_Left - Left position of alt_MsgBox in relation to the available left position of the main screen

If alt_MsgBox_Relative_Position = True then
alt_MsgBox_Top - Top position of alt_MsgBox relative to current top position
alt_MsgBox_Left - Left position of alt_MsgBox relative to current left position

Negative value is up / left
Positive value is down / right

Usage:
alt_MsgBox_Top =
alt_MsgBox_Left =

When alt_MsgBox is closed, the top and left positions of the Window are reset to default (-1)
alt_MsgBox_Relative_Position is reset to default too (False)
[/code]

Project
alt_MsgBox.zip
(Contains all the pictures used in project. You have add them again after opening the project for the first time)