locked
Challenge of the Month - October/November 2015 RRS feed

  • General discussion

  • These challenges are intended for people who are learning to program for the first time or for those returning to programming who want to start using Small Basic.  Some will be easy, some will be hard - but they will all make you think, and more importantly be GREAT FUN!

    Please post your solutions / partial solutions / questions / feedback etc. into this thread that will remain 'sticky' for the month.  The only rule is that your solution must use standard Small Basic methods (no extensions).

    It would be good if people could post their problems with these challenges so that a discussion can start so that everyone can learn from each other.

    Also post feedback on the kind of challenges that you want to see more of in the future.

    Graphics Challenge

    • Draw regular 5, 7 and 9 pointed stars.


    Physics Challenge

    • Cretae an animation of Newton's cradle.

    In a Newton's cradle, when the ball on the end strikes the others it ...

    Controls Challenge

    Create some additional controls in the GraphicsWindow without using extensions.

    • A read-only textbox
    • Radio buttons
    • A password entry textbox
    • Create your own button with mouse-over and button press events, not using the button control, this way your button can have fancy colour or other effects
    • Any other controls you fancy


    Text Challenge

    • Create a program to draw a histogram of the frequency of letters in a text file.


    Extension Challenge

    • Create your own extension in C# or VB to calculate the prime factors of a number.


    Game Challenge

    • Write a simple 'platform game', where a player jumps between platforms.

    Platform Game Tiles By combining groups of tiles

    Do you have an idea for a future challenge? Please post it here!

    • Edited by litdev Monday, October 12, 2015 7:38 PM
    Monday, October 12, 2015 5:55 PM

All replies

  • Mario SB :D

    Download: http://www.mediafire.com/download/15uk8edggsbqy1s/MarioSB.zip


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11


    • Edited by Zock77Editor Wednesday, October 14, 2015 4:24 AM
    Wednesday, October 14, 2015 4:23 AM
    Answerer
  • Nice game Zock.

    Wednesday, October 14, 2015 10:53 PM
  • Nice. You used pixel map.

    Hey I worked out a way in last months challenge to embed images into browser games. Maybe we could apply that to a simple Mario background.

    Wednesday, October 14, 2015 10:59 PM
  • Thanks!

    What exactly do you mean by embedding images? 



    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Wednesday, October 14, 2015 11:42 PM
    Answerer
  • Heh Heh!


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Thursday, October 15, 2015 12:01 AM
    Answerer
  • lol.

    Embed some drawing data in an sb file: here then it can be drawn in the browser.

    Is pretty much limited to solid colours (line draw co-ordinates) or sketch outline (pixel co-ordinates).

    To get the data you need to parse an image, write to file then paste this into the sb program as a long string. Then publish.

    Thursday, October 15, 2015 12:55 AM
  • Extension Challenge

    using System;
    using System.Linq;
    using System.Text;
    using Microsoft.SmallBasic.Library;

    namespace SB_Class
    {
        /// <summary>
        /// This is  to get factor numbers of a number
        /// </summary>
        [SmallBasicType]
        public class SBMath_Test
        {
            /// <summary>
            ///  gets  Factor numbers .
            /// </summary>
            /// <param name="NMB">
            /// a number  EX; 12345678
            /// </param>
            /// <returns name="Factors">
            /// returns factor numbers
            /// EX: in this case(NMB=12345678)  result="2*3*3*47*14593"
            /// </returns>

            public static Primitive Factor(Primitive NMB)
            {
              
                int NN = 1;
                string Factors = "";
                while (NN * NN <= NMB)
                {
                    NN += 1;
                    if (NMB % NN == 0)
                    {
                        Factors += NN.ToString() + "*";
                        NMB = NMB / NN;
                        NN = NN - 1;
                    }
                }
                Factors += NMB.ToString();
                return Factors;
            }
        }
    }

    TextWindow.Write("input number ")
    NMB=TextWindow.ReadNumber()
    result=SBMath_Test.Factor(NMB)
    TextWindow.WriteLine("Prime Factor For "+NMB+ " = "+result)

    Thursday, October 15, 2015 8:05 AM
    Answerer
  • Hi,

    I am overall happy with this outcome of the text histogram, Linked to a text file on my desktop it does a god job.

    Evaluating the"These challenges are intended for people who are learning to program for the first time or for those returning to programming who want to start using Small Basic.  Some will be easy, some will be hard - but they will all make you think, and more importantly be GREAT FUN!

    Please post your solutions / partial solutions / questions / feedback etc. into this thread that will remain 'sticky' for the month.  The only rule is that your solution must use standard Small Basic methods (no extensions).

    It would be good if people could post their problems with these challenges so that a discussion can start so that everyone can learn from each other.

    Also post feedback on the kind of challenges that you want to see more of in the future."

    Text I have generated this histogram.

    txt = File.ReadContents("C:\Users\Alex\Desktop\new.txt")
    len = Text.GetLength(txt)
    For i = 0 To len ' Work along length of text file
      chr = Text.GetSubText(txt,i,1)
      cnum[chr]=cnum[chr]+1 'Count characters
      If cnum[chr] = 1 Then
        string=string+chr 'Build a string of characters found
      EndIf
      If cnum[chr]>max Then
        max=cnum[chr] 'Find the highest most recurring character
        EndIf
      TextWindow.WriteLine(chr+" "+cnum[chr]+" "+string) ' Display gathered information in text window
    EndFor
    lens = Text.GetLength(string)
    height = 300
    barwidth = height/lens ' Set bar width to fill a maximum space of 300'
    corr = height/max 'Set highest value to meet the top of the graph
    For i = 0 To 10 ' Draw gridlines & Y axis
      GraphicsWindow.PenWidth=1
      GraphicsWindow.brushColor="black"
      GraphicsWindow.FontSize=8
      GraphicsWindow.DrawLine(0,i*(height/10),height+barwidth,i*(height/10))
      GraphicsWindow.DrawText(height+barwidth+5,i*(height/10),max-(i*(max/10)))
      EndFor
    For i = 0 To lens ' Work through string built
      chrs = Text.GetSubText(string,i,1)
        GraphicsWindow.PenColor="black"
      GraphicsWindow.BrushColor="red"
      GraphicsWindow.fillRectangle(barwidth*i,height-(cnum[chrs]*corr),barwidth,(cnum[chrs]*corr)) ' Draw bars, corrected to max height
      GraphicsWindow.drawRectangle(barwidth*i,height-(cnum[chrs]*corr),barwidth,(cnum[chrs]*corr)) ' Draw bars, corrected to max height
      GraphicsWindow.FontSize=8
      GraphicsWindow.BrushColor="black"
      GraphicsWindow.DrawText((barwidth*i)+2,height+4,chrs) 'Draw X axis characters
    EndFor


    Alex Warrington - alex.warrington@live.co.uk

    Thursday, October 15, 2015 9:06 AM
  • My Password Program: LXM256 (REVISED)

    I enjoyed making this password box. I did not use Textbox as I felt it did not require the functions. I don't use graphics window that often so enjoyed this.

    It's very primitive but it works to some extent.

    Edit: Included - Backspace functionality.
    Click OFF password box.
    Textwindow removed.
    Still does not accept special characters.


    Alex Warrington - alex.warrington@live.co.uk


    Thursday, October 15, 2015 10:52 AM
  • Some great answers so far.

    How about a read only textbox or fancy button control?

    Friday, October 16, 2015 7:00 PM
  • Controls Challenge   A read-only textbox

    Is this OK?

    Msg="This is read only"
    box= Controls.AddTextBox(20,20)
    Controls.SetTextBoxText(box,msg)
    Msg2="This is editable"
    box2= Controls.AddTextBox(20,50)
    Controls.SetTextBoxText(box2,msg2)
    GraphicsWindow.Keyup=Onkeyup

    Sub onkeyup
      txt= Controls.GetTextBoxText(box)
      If txt<>Msg Then
        GraphicsWindow.ShowMessage("Sorry, This is Read Only","error") 
        Controls.SetTextBoxText(box,msg)
      EndIf
    EndSub

    Saturday, October 17, 2015 1:46 AM
    Answerer
  • My Password Program: LXM256 (REVISED)

    I enjoyed making this password box. I did not use Textbox as I felt it did not require the functions. I don't use graphics window that often so enjoyed this.

    It's very primitive but it works to some extent.

    Edit: Included - Backspace functionality.
    Click OFF password box.
    Textwindow removed.
    Still does not accept special characters.


    Alex Warrington - alex.warrington@live.co.uk



    Alex, great job on your solutions!

    Ed Price, Azure & Power BI Customer Program Manager (Blog, Small Basic, Wiki Ninjas, Wiki)

    Answer an interesting question? Create a wiki article about it!

    Saturday, October 17, 2015 7:35 AM
  • Here is my password solution. After long search how to do specilal chars I found a solution. It wordks for all chars on MY keyboard. I had to translate all the strange strings my keys output to LastKey such as "oem1" , "oemquotes"  and so on. The program doesn't respond to the returnkey but shows the output directly on screen (testpurposes). The program number is CND797. Screenskot:


    Jan [ WhTurner ] The Netherlands


    Saturday, October 17, 2015 11:11 AM
    Answerer
  • Here's a go a the controls challenge, import GGL988. 

    It quite a lot of code for just a few buttons, but this is the case for non standard interfaces - it is a lot of work.

    You can always recreate the action of any control, but usually we just modify the default controls a bit or use (buy) a library of extended controls written by someone else.

    One trick to make controls inactive (not reacting to mouse events) would be to overlay them with a fully transparent rectangle.

    Maybe have a go at some other controls that are not available in Small Basic or extend the button methods here for your own design and behaviour.

    • Edited by litdev Saturday, October 17, 2015 6:18 PM
    Saturday, October 17, 2015 4:51 PM
  • Here's my solution to read only TextBoxes: WZH765-0

    It resolves the independence of KeyDown and TextTyped by explicating storing the value of read-only text.

    So the user keeps functionality of TextBoxes i.e. copy/paste and handles if the user holds the keydown in a read-only.

    Interesting challenge.

    btw the user will only get a Message when the key is released. I try to resolve this in the GUI design. Read-only text is coloured and the user will eventually release the key when they realise nothing is happening. 

    Main parts are:

    Initialise()
    
    GraphicsWindow.KeyDown = OnKeyDown  'rapid fire
    GraphicsWindow.KeyUp = OnKeyUp
    
    Sub OnKeyDown  
      For i = 1 To Array.GetItemCount(rOnly)
        Controls.SetTextBoxText(rOnly[i], rOnlyText[i])    
      EndFor   
    EndSub
    
    Sub OnKeyUp  
      GraphicsWindow.ShowMessage("-----")
    EndSub


    • Edited by Jibba j Saturday, October 17, 2015 11:52 PM
    Saturday, October 17, 2015 11:02 PM
  • I know my solution is really really long but here it is:

    text1 = "my name is john"
    text1 = Text.ConvertToLowerCase(text1)
    pos = Text.GetLength(text1)
    For num = 0 To pos step 1
      letter[i] = Text.GetSubText(text1, num,1)
      If letter[i] = "a" Then
        a= a + 1
      ElseIf letter[i] = "b" then
        b= b +1
      elseIf letter[i] = "c" Then
        c = c + 1
      ElseIf letter[i] = "d" then
        d= d +1
      elseIf letter[i] = "e" Then
        e= e + 1
      ElseIf letter[i] = "f" then
        f= f +1
      ElseIf letter[i] = "g" Then
        g= g + 1
      ElseIf letter[i] =  "h" then
        h= h +1
      ElseIf letter[i] = "i" Then
        i= i + 1
      ElseIf letter[i] = "j" then
        j= j +1
      ElseIf letter[i] = "k" Then
        k= k + 1
      ElseIf letter[i] = "l" then
        l= l +1
      ElseIf letter[i] = "m" Then
        m= m + 1
      ElseIf letter[i] = "n" then
        n= n +1
      ElseIf letter[i] = "o" Then
        o= o + 1
      ElseIf letter[i] = "p" then
        p= p +1
       ElseIf letter[i] = "q" Then
        q= q + 1
      ElseIf letter[i] = "r" then
        r= r +1
       ElseIf letter[i] = "s" Then
        s= s + 1
      ElseIf letter[i] = "t" then
        t= t +1
       ElseIf letter[i] = "u" Then
        u= u + 1
      ElseIf letter[i] = "v" then
        v= v +1
      
     ElseIf letter[i] = "w" Then
        w= w + 1
      ElseIf letter[i] = "x" then
        x= x +1
       ElseIf letter[i] = "y" Then
        y= y + 1
      ElseIf letter[i] = "z" then
        z= z +1
      endif  
    endfor 

    TextWindow.WriteLine("a=" + a)
    TextWindow.WriteLine("b=" +b)
    TextWindow.WriteLine("c=" +c)
    TextWindow.WriteLine("d=" +d)
    TextWindow.WriteLine("e=" +e)
    TextWindow.WriteLine("f=" +f)
    TextWindow.WriteLine("g=" +g)
    TextWindow.WriteLine("h=" +h)
    TextWindow.WriteLine("i=" +j)
    TextWindow.WriteLine("j=" +k)
    TextWindow.WriteLine("k=" +l)
    TextWindow.WriteLine("l=" +m)
    TextWindow.WriteLine("m=" +n)
    TextWindow.WriteLine("n=" +o)
    TextWindow.WriteLine("o=" +p)
    TextWindow.WriteLine("q=" +q)
    TextWindow.WriteLine("r=" +r)
    TextWindow.WriteLine("s=" +s)
    TextWindow.WriteLine("t=" +t)
    TextWindow.WriteLine("u=" +u)
    TextWindow.WriteLine("v=" +v)
    TextWindow.WriteLine("w=" +w)
    TextWindow.WriteLine("x=" +x)
    TextWindow.WriteLine("y=" +y)
    TextWindow.WriteLine("z=" +z)

    Monday, October 19, 2015 6:43 PM
  • on newtons cradle, is it ok if i use no physics, just events where if a object is at a certain positon the other ball moves? using circle program that is built in to my calculator. x^2+y^2=(radius)^2
    Monday, October 19, 2015 6:51 PM
  • Absolutely Jetfire

    Physics isn't a prerequisite to gaming or modelling.

    You might find over time that you pick some up though. I did but it's pretty much just simple motion with basic forces for me.

    Monday, October 19, 2015 8:43 PM
  • This is what i have so far.  I know it doesnt incorperate physics and gravity and velocity...who cares. now the gravity i can somewhat do with program.delay(xcoordinate*-20) comments, Questions, concerns?

     GraphicsWindow.height=400
    GraphicsWindow.width=400

    holder = Shapes.AddLine(0, 100, 300, 100)
    balls[1] = Shapes.AddEllipse(30, 30)
    ball[1]["x"] = 0
    ball[1]["y"] = 0


    Shapes.Move(balls[1], ball[1]["x"]+120, ball[1]["y"]+150) ' balls
    radius = 150 ' for circle formula puposes

    direction = -2 ' so the ball1 will move to the left for begnning
    While 1 = 1
    If direction = -2 Then
      ball1movingnegative()
      elseif direction = -1 then
      ball1movingpositive()
    endif
    Shapes.Move(balls[1], ball[1]["x"]+200, 150-ball[1]["y"])
    TextWindow.WriteLine(delay)
       Program.Delay(delay)

    endwhile
        
        sub ball1movingnegative

        ball[1]["x"] = ball[1]["x"] - 1
        ball[1]["y"] = Math.SquareRoot(22500-Math.Power(ball[1]["x"],2))
      
        ball[1]["y"] = math.Round(ball[1]["y"])
        ball[1]["y"] = ball[1]["y"]*-1
        
        Shapes.Remove(ballholder[1])
        ballholder[1]=Shapes.AddLine(215, 100, ball[1]["x"]+200+(15), 150 - ball[1]["y"]+(15))
        
        delay = (((ball[1]["x"]*20)/1000) + 50)
        
        If ball[1]["y"] >=0 Then
        direction = -1
        else
        
        EndIf
        endsub
        Sub ball1movingpositive
         
          ball[1]["x"] = ball[1]["x"] + 1
          ball[1]["y"] = Math.SquareRoot(22500-Math.Power(ball[1]["x"],2))
         
          ball[1]["y"] = math.round(ball[1]["y"])
          ball[1]["y"] = ball[1]["y"] * -1
        
          Shapes.Remove(ballholder[1])
          ballholder[1]=Shapes.AddLine(215, 100, ball[1]["x"]+200+(15), 150 - ball[1]["y"]+(15))
          delay = (((ball[1]["x"])*20)/1000) + 50
       
        If ball[1]["y"] <=-149 Then
        direction = -2
        else
        
        EndIf
      EndSub
      Sub ball2movingpositive
      EndSub
      Sub ball2movingnegative
        EndSub


    • Edited by JetFire3201 Tuesday, October 20, 2015 12:53 AM updated version
    Tuesday, October 20, 2015 12:50 AM
  • Here's my solution to the Text Challenge:  Runs in IE and Silverlight enabled Fire Fox or GNM423-0



    • Edited by Jibba j Friday, November 27, 2015 11:19 AM
    Tuesday, October 20, 2015 9:53 AM
  • @Jetfire,

    Your lettercounting program works, but ther are some little remarks:

    1. GetSubString counts from 1 not from 0  ( for num ...)

    2. You use an array for letter, with an index i. This is undefined at the start, and becomes 1 when the first i is counted. You can better use a normal variable "letter".


    Jan [ WhTurner ] The Netherlands

    Tuesday, October 20, 2015 10:35 AM
    Answerer
  • Here is a shortened version of jetfire's program:

    text1 = "my name is john"
    text1 = Text.ConvertToLowerCase(text1)
    pos = Text.GetLength(text1)
    
    For num = 0 To pos step 1
      letter = Text.GetSubText(text1, num,1)
      Array[letter] = Array[letter] +1
    EndFor
    
    For i = 97 To 122
      letternum = Array[Text.GetCharacter(i)]
      If letternum = "" Then
        letternum = 0
        EndIf
      TextWindow.WriteLine(Text.GetCharacter(i) + " = " + letternum)
      EndFor


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Thursday, October 22, 2015 12:23 AM
    Answerer
  • This is my combo box for Controls Challenge: KMG391-0.

    Screen shot of a program Combo Box Sample 0.1b


    Nonki Takahashi

    Saturday, October 24, 2015 9:43 AM
  • JJ,

    I like the colors and the text (Lorem ipsum).

    Thanks.


    Nonki Takahashi

    Saturday, October 24, 2015 9:53 AM
  • Hey thanks for your sample Naochan.

    I haven't done the prime factors yet. But I did an extension that lists all the primes in a given range.

    You can copy/paste the extension from here: http://smallbasic.com/program/?PXF746

    The browser will throw an exception, just click ok and the code will copy into VS with no worries.

    I tested writing to file all primes from 0 to 1,000,000. It completed in 4 minutes. What do you think, fast enough?

    Oh, probably a good idea to open the output file in wordpad (not notepad).

    start = Clock.ElapsedMilliseconds
    from = 0
    While 0=0
      till = from + 50000
      If till >= 1000000 Then
        till = 1000000    
        Goto break
      EndIf
      string = string + XMath.PrimeNumbers(from, till, "")
      from = till + 1
    EndWhile
    break:
    string = string + XMath.PrimeNumbers(from, till, "")
    
    duration =  (Clock.ElapsedMilliseconds - start) / 1000
    writeMe = duration + Text.GetCharacter(13) + string
    
    File.WriteContents(Program.Directory + "\One Million Prime Numbers.txt", writeMe)
    
    TextWindow.WriteLine(duration)
    Great idea for a challenge - thanks Litdev. Helpful.

    Sunday, October 25, 2015 1:44 AM
  • Is it possible to get live external links into the xml?
    Sunday, October 25, 2015 1:47 AM
  • Thanks Nonki

    I had to do a weird workaround for browser. I'll read that article you wrote on browser workarounds so I can setup for it better.

    I use "Lorem ipsum" a lot for designing websites. It can be handy for testing word processing programs as well because it's constant.
    • Edited by Jibba j Sunday, October 25, 2015 1:56 AM
    Sunday, October 25, 2015 1:52 AM
  • I hope the extension challenge becomes a regular feature.
    Sunday, October 25, 2015 2:04 AM
  • Alex, I liked your solution too.

    Using max to calibrate the graph is a good touch.

    Sunday, October 25, 2015 2:06 AM
  • Here's a simple slider control.  The program uses it to control the zoom level on a shape.

    Import DST499

    http://smallbasic.com/program/?DST499

    Not sure how it runs in the browser as I don't have Silverlight installed on this machine.


    Sunday, October 25, 2015 3:54 AM
  • OzJerry

    It works fine in the browser.

    Sunday, October 25, 2015 4:10 AM
  • Hey thanks for your sample Naochan.

    I haven't done the prime factors yet. But I did an extension that lists all the primes in a given range.


     My prime number  C# program.

    using System;
    using System.Linq;
    using System.Text;
    using Microsoft.SmallBasic.Library;

    namespace Math_Test
    {
        /// <summary>
        /// The XMath object provides extra mathematical tools
        /// </summary>
        [SmallBasicType]
      
        public static class XMath
        {
            /// <summary>
            /// Gets an ascending list of prime numbers for a given range
            /// </summary>
            /// <param name="from">The integer to start from</param>
            /// <param name="to">The integer to finish at</param>
            /// <returns>A CSV file of all primes in the range and counts.
            /// </returns>
            /// <example>XMath.PrimeNumbers(3, 1000000)</example>
           
            public static Primitive PrimeNumbers(Primitive from, Primitive to)
            {
             string Path= Program.Directory+"\\primenmb.txt"; // temporary file
             string prime="";
             int NN=0;
             for (int i=from; i <=to; i +=2)
              {
                 string tf="False";
                 int  j2= (int)System.Math.Sqrt(i);
                 for (int j=3;j<=j2;j+=2)
                  {
                    if(i%j==0)
                    {  tf = "True"; j = j2; }
                   }
                 if (tf=="False")
                  {   NN +=1;    prime +=i.ToString()+",";   } // list up prime number
                 if (NN%1000==0)
                  {
                     if(prime!="")
                     { File.AppendContents(Path,prime); }   // record prime numbers
                     prime = "";          //  to speed up  // too long strings requires too long time
                  }
              }
              File.AppendContents(Path,prime);
             return  File.ReadContents(Path)+" Counts= "+NN.ToString();
            }
       }
    }

    small basic program

    t0=Clock.ElapsedMilliseconds
     csv= XMath.PrimeNumbers(3,1000000)
     t1= Clock.ElapsedMilliseconds-t0
     TextWindow.WriteLine(csv)
    TextWindow.WriteLine(t1/1000+" sec")

    It shows about "3 sec"


    Sunday, October 25, 2015 6:47 AM
    Answerer
  • OzJerry

    It works fine in the browser.

    Thanks for the update jibba Jabba.

    Cheers

    Jerry

    Sunday, October 25, 2015 7:06 AM
  • Nice! That's like 80 times faster.

    I wont look at your code yet. I'll google some stuff and see how much faster I can get it.

    Sunday, October 25, 2015 7:47 AM
  • Ha. Back again. I see what I did wrong.

    Here's where I got the sieve logic from: http://mathforum.org/dr.math/faq/faq.prime.num.html

    I'll apply it properly and get back you.

    Thanks

    Sunday, October 25, 2015 7:52 AM
  • Here's a knob/rotary control, inspired by LitDev's SliderKnob in his Marionette. ID: HZV539

         (RotaryKnob.png)

    PS: Also added a LDSlider, but to use w/o extension, simply ignore/comment out all lines containing "slider"

    Monday, October 26, 2015 9:25 PM
    Answerer
  • This is my solution for graphics challenge: LWB173.

    Enter angle and push [Move] to draw a star.

    Screen shot of a program N Pointed Star 0.1

    This program can run properly with Small Basic 1.2.  Turtle will disappear with Small Basic 1.0.


    Nonki Takahashi


    Wednesday, October 28, 2015 5:01 PM
  • I wrote an another program for graphic challenge: SCL845.

    This program shows how to calculate the angle to draw n pointed star with following code.

    For i = 1 To n
      Turtle.Move(100)
      Turtle.Turn(angle)
    EndFor

    Screen shot of a program Calculate Angle C for a Star

    I solved equations with 5 unknowns.  The answer is angle C.


    Nonki Takahashi




    Friday, October 30, 2015 12:21 PM
  • Nonki,

    I didn't have time to analyze your program at the moment, but want to tell you that for n is even ( e.g. 8 or 12) the program draws a 2 * n pointed star (16 or 24)


    Jan [ WhTurner ] The Netherlands

    Friday, October 30, 2015 2:41 PM
    Answerer
  • I think the equations (with 5 unknowns) work well for only odd n pointed star. The same equations for even n result 2*n pointed star.

    Actually, we can't draw 6 pointed star, 10 pointed star and so on.

    You can check the equation when n is even with SCL845.

    Screen shot of a program Calculate Angle C for N Pointed Star


    Nonki Takahashi



    • Edited by Nonki Takahashi Saturday, October 31, 2015 10:31 AM added image
    Saturday, October 31, 2015 10:10 AM
  • This is my another solution for controls challenge: XZB099. (scroll bar)

    Screen shot of a program Scroll Bar Sample

    This scroll bar can be controlled by mouse only (not by keyboard).


    Nonki Takahashi

    Saturday, November 7, 2015 1:24 PM
  • Here's my solution to extension challenge: Click Me

    Both XMath operations work but need optimising. This is me picking up some Math as I go. I'll come back to them.

    I'll take my time with this extension but if anyone wants to contribute - I'm game.

    Suggestion for next extension challenge: Would like to see if I can build a custom Dialogue Extension.

    Perhaps not just standard dialogues but a form that can have some controls added and some properties set. Maybe.

    Saturday, November 7, 2015 11:10 PM
  • This is my first step for the game challenge: NWP151-0.

    Screen shot of a program Collision Sample

    This program will be a physics engine for the game.  I used a subroutine CollisionCheck written by litdev in a TechNet Wiki article Small Basic: Dynamic Graphics.


    Nonki Takahashi



    Sunday, November 8, 2015 12:24 AM
  • Here's 2 proofs of concept for Custom Controls (I did months ago):

    1. QMD177 Selecting from Multiline Textboxes
    2. SXD381-0 Multi feature Dialogue Boxes

    Atm they don't look so pretty but they're not meant to yet. They just prove that the 2 concepts are reliable.

    So what I'm thinking as next steps before deploying them would be:

    1. Identify the properties that you would want to be gettable and settable in terms appearance, behaviour and value
    2. Then simplify them as much as you can whilst maintaining extensibility.

    Once this is done you can commit them to your custom library.

    As far as I can see the 2 concepts could well cover any dialogue scenario that could possibly arise, including checkbox, radiobutton and so on.

    I've used Buttons as the means of Control. Their opacity can be set to zero and shapes could be slipped underneath them to give a slicker look and feel.

    Next I might check out LD extension to see if I can call the control code from their own SB files, that way they wont clutter up the main program with code.

    Sunday, November 8, 2015 9:05 PM
  • I've used Buttons as the means of Control. Their opacity can be set to zero and shapes could be slipped underneath them to give a slicker look and feel.
    This is a great idea
    Sunday, November 8, 2015 9:29 PM
  • Doh - Nearly forgot.

    Here's my final submission for custom controls: Drop Down Menu:

    • BGF911-1
    • Sort of runs in browser (there's a bit of latency issue in the browser if the mouse moves too quickly) possibly resolvable

    Another proof concept. The code is verbose and contains test code. This could be another candidate for custom library which could then use an extension that calls the code from another SB file (so as not to clutter up the main program).

    I wrote this years ago so it's up for a good revision and simplification and check for extensibility (I think there's 1 error).

    I'd also change the Zoom method so that it always Zooms Down, that way you'll never get fuzzy edges on textures. Yes it uses Shapes so it's texture friendly.

    It has been tested by application in a game. Works reliably with no significant load on a game loop.

    The settable and gettable properties for deployment are isolated as:

    Sub MenuDataTable   'USE THIS SUB TO CUSTOMISE MENU
      'MENU   
      'Data Table
      menu = "1=View Screen;2=Program;3=Help;4=Test This"  'ADD DATA
      menuWidth = "1=105;2=85;3=55;4=85"  'MATCH WIDTH WITH DATA
      subMenu[1] = "1=Home;2=Small;3=Leaders Board;4=Extra for one;5=Another Extra for testing submenu one" 
      subMenu[2] = "1=Debug;2=Close;3=test submenu two;4=more again" 
      subMenu[3] = "1=How;2=About Match Picture;3=Again test me" 
      subMenu[4] = "1=Test One;2=Test Sub Menu two"
      subMenuWidth = "1=285;2=145;3=165;4=155"   'MATCH WIDTH WITH DATA
    EndSub
    I reckon SB is pretty powerful from a high level (interesting, it's like the step before natural programming languages come into being).



    • Edited by Jibba j Saturday, November 14, 2015 4:16 AM removed browser link
    Sunday, November 8, 2015 10:56 PM
  • Thanks for the feedback Litdev.

    Sunday, November 8, 2015 11:15 PM
  • This is my second step for the game challenge: NWP151-1.

    Screen shot of a program Platform Game Sample 0.3a

    • I'm trying to use Small Block Builder for creating map.
    • So Small Block Builder is required to run this program.
    • Known issue: a character sometimes disappears at right edge of an obstacle.
    • You can move "1" with up, left and right arrow keys.  

    Nonki Takahashi


    Tuesday, November 10, 2015 1:40 PM
  • Could we do a stickman running animation challenge?
    Tuesday, November 10, 2015 5:28 PM
  • Remembered a nice Expander Control, once saw on Customizing WPF Expander with ControlTemplate.

    Here is a port for SB ID: WMK208-0 (2 variants: with and without animation)

    Textshapes in SB have a transparent background, which delievers not a very exciting view. For a better look, activate the 2 lines with LDShapes.BrushColour (currently commented out)


    • Edited by Pappa LapubEditor Wednesday, November 11, 2015 4:12 PM mark on right shape
    Wednesday, November 11, 2015 1:10 PM
    Answerer
  • PL > very nice.
    Wednesday, November 11, 2015 2:13 PM
  • Hi JJ. Thx.  I knew, i'd forgotten something, then saw what

    Wednesday, November 11, 2015 4:11 PM
    Answerer
  • Pappa Lapub, this rotary control is cool!
    I modified your program not to use LitDev Extension: HZV539-0.

    Nonki Takahashi

    Friday, November 13, 2015 11:49 AM
  • Oh, i see, great Nonki and glad u like it. Now fully challenge compatible.

    I'll add the 'RotaryKnob.png' that i use and another one, if one has a use for it.  

    Friday, November 13, 2015 8:58 PM
    Answerer
  • All these special SB controls are fantastic - pretty much anything you can imagine can be done - they are a great way to learn GraphicsWindow and Events as well as make your programs individual and really stand out :)
    Friday, November 13, 2015 10:31 PM
  • There's 2 other scenarios that come up on the forum for TextBoxes:

    1. clear textbox on click/select, and
    2. caret position

    Here's a solution for clearing on TextBox selected: BMF105

    So far I haven't seen a solution for caret position without using an extension.

    Saturday, November 14, 2015 11:03 PM
  • I just tried my hand at turning Public Profile pictures into sketches, then embedding them for the browser.

    My 1st subject was:  Ed Price [browser portrait]. Ed will only appear in Silverlight enabled Browsers


    • Edited by Jibba j Friday, November 27, 2015 11:26 AM
    Thursday, November 19, 2015 2:53 AM
  • i dont quite understand how u go from  a picture to strings to make the picture. Could u plz explain how u would start?
    Thursday, November 19, 2015 4:38 AM
  • Hi jetfire

    It's a process of photo editing, scanning, parsing then copying the data from the txt files to the program that uses them to draw the finished product.

    1. copied Ed's photo to Paint.Net and turned it into a sketch of 2 colors, (dark gray & light gray). I made the black parts transparent.
    2. created 2 paint files and removed darkgray from one and lightgray from the other.
    3. then I scanned these 2 files to get the pixel coordinates separately. Using  GZF424
    4. then parsed the created txt files into linedraw coordinates separately using FQR389
    5. then copy this data to the final drawing program as string[1] and string[2]. As in above  Drawing Program

    Points of care:

    • there's a file size limit that can be published (can overcome by using Network.GetWebPageContents())
    • keep paint images the same size when isolating the colors

    I did this mainly for browser.

    Also I might change the program in step 3, so that it scans out the background instead of scanning in the foreground. Because most times the foreground might look like 1 color but it contains different shades.

     



    • Edited by Jibba j Thursday, November 19, 2015 5:50 AM
    Thursday, November 19, 2015 5:30 AM
  • Check this out! It is so cool!

    Maybe for a challenge:

    https://www.youtube.com/watch?v=qv6UVOQ0F44


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Thursday, November 19, 2015 9:33 PM
    Answerer
  • Yeah, I like this Zock. Thanks for sharing.

    Just put it on my to-do list.

    Friday, November 20, 2015 12:18 PM
  • This is my solution to physics challenge: TWL321-0.

    Screen shot of a program Newton's Cradle


    Nonki Takahashi

    Sunday, November 22, 2015 8:55 AM
  • Suggestions for next month's challenges:

    Use a Main loop for these and try nuzzling them into game loop structure.

    Basic Motion

    1. Make a square shape move from left to right of screen at a constant speed.
    2. Using arrays, place 2 more shapes on top of this shape and have them move in tandem.

    1. Make a circular shape move from the top to bottom of the GW at a constant speed.
    2. Now make this shape move on the same path from a standing start under the influence of gravity
    3. Now add friction/drag to this.

    1. Make a shape move horizontally across the screen bouncing off the edges with constant speed.
    2. Make a shape bounce from top to bottom from a standing start under the influence of gravity.
    3. Now add friction to this. Eventually the shape should stop.

    1. Make a shape move randomly all over the screen at a constant speed.
    2. Maybe apply some acceleration to this.

    1. Make a shape move in a circular path around a stationary shape placed in the centre.
    2. Add a satellite to this orbiting body.
    3. Have a go at changing the orbit to an elliptical path
    4. Add a continuous random barrage of asteroids that respond to any collisions

    ---------------------------------------------------------------------------------------------

    • Make a step up game where a ball bounces up a set of steps. User can move the ball left and right.
    • Make a calculator. For a nice GUI check out Nonki's website.
    • Make some interesting Backgrounds. There was a recent blog on this by Nonki.
    • Also make some interesting gradient backgrounds, can use RGB, random or constant fills for this. The backgrounds don't have to be full window. If you make them extensible they can become part of your own code library.

      -----------------------------------------------------------------------------------------------------

    For advanced collision model some random balls colliding into each other.


    • Edited by Jibba j Friday, November 27, 2015 10:41 AM
    Friday, November 27, 2015 10:33 AM
  • Love your cradle Nonki. Amazing.

    btw I chose to run it locally only, as edge and Silverlight don't like each other.

    I wonder if we'll get an edge compatible browser sharing platform for SB. Would be good if it was all HTML I reckon, if doable.

    Friday, November 27, 2015 11:08 AM
  • Actually I just copy/pasted it to FireFox. Very nice.

    The copy/paste to FireFox is same effort as running it from the IDE.

    Friday, November 27, 2015 11:14 AM

  • Just came across a link (via CP) i thought, to share: Controls images (Leslie Sanford) if usefull for anyone.There a a lot of Knob images (and other Controls). The .knob files in downloadable zips are mostly pure png files, others have additional layers which can be opened in Knobman and exported to multi image stripes (s.LDShapes.AnimationXXX;  further Controls images in Knobman.zip\Samples  sub folder).




    Friday, November 27, 2015 9:14 PM
    Answerer
  • This is my second step for the game challenge: NWP151-1.

    Screen shot of a program Platform Game Sample 0.3a

    • I'm trying to use Small Block Builder for creating map.
    • So Small Block Builder is required to run this program.
    • Known issue: a character sometimes disappears at right edge of an obstacle.
    • You can move "1" with up, left and right arrow keys.  

    Nonki Takahashi


    Hey Nonki! Hows the sidescroller coming? It looks really interesting.


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Saturday, November 28, 2015 6:29 AM
    Answerer
  • Litdev

    I just downloaded v1.2 of your extension and can't get it to show up in intellisense.

    Also there's a small typo in the readme file: "xlm" should be "xml".

    Sunday, November 29, 2015 11:41 AM
  • Litdev

    I just downloaded v1.2 of your extension and can't get it to show up in intellisense.

    Also there's a small typo in the readme file: "xlm" should be "xml".

    You may need to unblock downloaded dlls - see here.

    If the extension commands fail to appear in Small Basic (type LD and no options appear) then you may need to unblock the downloaded dll.  Right click LitDev.dll and select Properties and clear the block if present.  If it fails to unblock, then copy LitDev.dll to a folder where you have write access (e.g. Documents), unblock it there and then move back to the Small Basic lib folder.  Alternatively, unblock the downloaded zip file before unzipping the content.

    Sunday, November 29, 2015 11:50 AM
  • Yeah unblock.

    All good now. Thanks.

    Sunday, November 29, 2015 11:56 AM
  • Love your cradle Nonki. Amazing.

    btw I chose to run it locally only, as edge and Silverlight don't like each other.

    I wonder if we'll get an edge compatible browser sharing platform for SB. Would be good if it was all HTML I reckon, if doable.

    My recommendation is to select [...] > [Open with Internet Explorer] menu in Edge.


    Nonki Takahashi

    Monday, November 30, 2015 1:58 AM
  • Thanks, Zock77.
    I'm planning the same way of Small Block Builder - just draw the next page - for scroll. 

    Nonki Takahashi

    Monday, November 30, 2015 2:27 AM
  • This is my third step for the game challenge: NWP151-2.

    Screen shot of a program Platform Game Sample 0.4b

    • I created a 60 x 60 image player_r60.png for Textures\player_r60.png .
    • I created scene maps here.  Extract these files into Scenery folder.
    • You need to remove comments from lines with File object in the program.
    • Other Textures are from Small Block Builder.

    Nonki Takahashi


    Monday, November 30, 2015 8:53 AM
  • Nice Nonki!!

    Ideas for future challenges:

    Find the square root without using Math.SquareRoot

    Draw an ellipse using lines. (easy)

    Write a program to find the GCF of two numbers.


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Monday, November 30, 2015 9:42 PM
    Answerer
  • Or for something more challenging: Make a filled ellipse.

    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Tuesday, December 1, 2015 12:00 AM
    Answerer
  • This is my third step for the game challenge: NWP151-2.

    Screen shot of a program Platform Game Sample 0.4b

    • I created a 60 x 60 image player_r60.png for Textures\player_r60.png .
    • I created scene maps here.  Extract these files into Scenery folder.
    • You need to remove comments from lines with File object in the program.
    • Other Textures are from Small Block Builder.

    Nonki Takahashi


    Very nice Nonki!!

    I put the 60x60 player_r60.png image into Small Block Builder download folder now. I also added a player_l60.png image because I'll probably change the player_l image to 40x40 in the next version.

    Tuesday, December 1, 2015 8:41 PM
  • Here's my attempt at the physics challenge.  it's not as comprehensive as Nonki's, as I'm cheating a little on the physics and skipping the centre balls.

    

    http://smallbasic.com/program/?NRC612

    Runs a little erratic in the browser so better to import: NRC612

    Edit: I should credit Khan Academy for the pendulum algorythm.  It's part of their computer programming course in the Natural Simulations section.  
    • Edited by OzJerry Wednesday, December 2, 2015 12:37 PM
    Wednesday, December 2, 2015 12:32 PM