Asked by:
Post your sample source code here and get featured on our blogs! (Part II)

General discussion
-
Good work, litdev. Nice going!
========
(This thread is a continuation from http://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/eaacf826-9d12-4e3c-aa10-1b2788f160a6)- Split by Vijaye Raji Wednesday, July 1, 2009 9:03 PM Thread too big.
- Edited by Vijaye Raji Wednesday, July 1, 2009 9:05 PM Adding reasoning for split
Wednesday, July 1, 2009 1:18 AM
All replies
-
Two projects I played with a while back updated for v0.5 - lots of arrays, events, graphics etc.
1] Driving game with nice graphics and rubbish gameplay BCK921.
2] Bouncing balls with collision physics, gravity, attraction etc. PMT149.
Wednesday, July 1, 2009 6:22 PM -
Wow those are great! Do you lose speed while making turns? Maybe with just a couple tweaks on the keys it's control will be perfect. I see your track is a sum of 3 sinusoids, pretty cool. Maybe if you "spawn" the trees/centerline a little lower on the display and find a better background, and even a distant horizon background that slides a bit left/right with the road, it'll really look cool.
I like to mess with gravity between lots of masses, your physics program goes way deeper than anything i've done. It looks like your propagating backward to the point of the collison between objects because of the discrete time steps, then figuring out where things should go, really cool. I tried to manipulate your initial variables to give the appearance of stars in orbit around each other, but I think the bouncing off the walls makes things difficult for that. Calculating the system's energy is great, lets you see if simulation errors build up into unstable energy. Really nice stuff.Wednesday, July 1, 2009 8:18 PM -
Wow, litdev. That is amazing...
Wednesday, July 1, 2009 8:28 PM -
The driving was mainly about learning how to use the events to update graphics smoothly - the actual game part could be rewritten to be much better.
The energy is just kinetic so it changes with gravity, attraction etc. If you forget collisions, a galaxy type gravity system should be not too hard to write. I was playing with 3D gravity (QND161), use mouse left to rotate. I also tried 3D Red/green stereo (QMF510) but not to much effect and other basic 3D stuff (JWV631 , LHJ742). None of these work that great, but it was fun playing.Wednesday, July 1, 2009 8:54 PM -
it would be nice if when authoring a reply like this one could use some tag like download:ID or [download]ID[/download] to mark a download. New users don't know what to do with "QND161" say number
Microsoft MVP J# 2004-2009, Borland Spirit of Delphi 2001Wednesday, July 1, 2009 8:56 PM -
2] Bouncing balls with collision physics, gravity, attraction etc. PMT149.
It's absolutely impressive!
Only thing I can complain about is detecting collisions of squares. They collides as balls, using radius instead of real square borders. From my own point of view, removing "square" option is good solution.
GrzesioThursday, July 2, 2009 5:50 AM -
Looking at what he's been able to do implementing physics, I would imagine he could model squares hitting corners & torquing each other around, would look funny.Thursday, July 2, 2009 6:35 AM
-
Not comparable to litdev works but if you like Worm game you can play the simplest one: XKT407
Have fun! :)
GrzesioThursday, July 2, 2009 6:13 PM -
I have been working on a simple statistics program as a result of an Introduction to Statistics course
in my BS/IT program.
It seems that while I uploaded the program the write to file lines have been commented out. These
write the programs computations to a text file so you can use them to plot your statistics in excel.
(it also seems that some of the spacing in my program was changed during upload?)
The program ID is KXV220
Here is a link: http://smallbasic.com/program/?KXV220- Edited by Ron Hudson Friday, July 3, 2009 8:57 AM
Friday, July 3, 2009 8:54 AM -
Nice worm game, Grzegorz.Friday, July 3, 2009 8:58 AM
-
Two projects I played with a while back updated for v0.5 - lots of arrays, events, graphics etc.
Impressive !
1] Driving game with nice graphics and rubbish gameplay BCK921.
2] Bouncing balls with collision physics, gravity, attraction etc. PMT149.
Fremy - Developer in VB.NET, C# and JScript ... - Feel free to try my extensionFriday, July 3, 2009 7:42 PM -
Here's two versions of a cellular automaton I've made: Easy code and Clean code .
The program uses simple rules to create complex figures. Like this one:
It takes about five minutes to render these 300 lines. I guess speed is not one of SmallBasic's strengths. :)
For more info about cellular automata see: http://mathworld.wolfram.com/CellularAutomaton.html- Edited by RarelyEvil Saturday, July 4, 2009 3:33 PM Links weren't working.
Saturday, July 4, 2009 3:31 PM -
PGG665 just a sumSunday, July 5, 2009 6:15 PM
-
You use For i = 1 To i+1 to do an infinite loop. This works fine and shows creative thinking, the more usual would be While ("True") .
To manipulate a single pixel try GraphicsWindow.SetPixel(x,y,GraphicsWindow.GetRandomColor()) , you will find it is faster than drawing an ellipse of size 1, also drawing an ellipse includes the pen coloured border as well the brush coloured interior.
The sum is bigger - import HWF459.- Edited by litdev Sunday, July 5, 2009 7:03 PM added ref to import
Sunday, July 5, 2009 6:28 PM -
GraphicsWindow.BackgroundColor = "midnight"
gw = GraphicsWindow.Width
gh = GraphicsWindow.Height
GraphicsWindow.FontSize = 100
Turtle.Move (100)
Turtle.Turn (1*1)
While ("True")
For i = 1 To 100 ' Do 100 of these for every update of the black text to speed it up
GraphicsWindow.SetPixel(Math.GetRandomNumber(gw),Math.GetRandomNumber(gh),GraphicsWindow.GetRandomColor())
EndFor
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.DrawBoundText(260,110,gw-20,"TY")
EndWhileSunday, July 5, 2009 10:30 PM -
I made a program that randomly shows astronomy pictures of the day from a NASA website. Import BQJ912
Enjoy!Friday, July 10, 2009 2:12 AM -
Has anyone thought about writing a program that does something like internet research?Friday, July 10, 2009 11:58 PM
-
what happens when i overflows?
for i = 0 to 1
i = 0
.....
if iamdone=1 then
i = 1
endif
...
endfor
of course you could use a while....
Saturday, July 11, 2009 12:13 AM -
Hello,
I just recently wrote my first program in Small Basic to convert numbers into Roman Numerals.
My programming experience is from many years back... Mainframe basic in High School in the 70's, Fortran77 in College, and writing batch files when I worked on a help desk.
I would like to know how my program could be streamlined.
The program is located at SFP007
Thanks ;
GlennTuesday, July 14, 2009 6:43 PM -
Hi, looks pretty efficient to me. Here's another using text manipulations rather than maths to get the digits and does more manipulation of the characters in the code without GoTo's and uses a smaller database of Roman characters entered in the code - much the same though. Import VGR369.Tuesday, July 14, 2009 7:46 PM
-
Thanks litdev,
The program you showed is more compact, and looks more efficient.
I wrote my program to make a Roman Digital Clock.
Here is my Clock RJP086
Later on I might integrate that other program.
The next 2 things I want to do for my clock is to get rid of the window border, and to get rid of the button in the Start/Task Bar.
Any ideas on how to go about this?
Thanks;
Glenn- Edited by Glennium Tuesday, July 14, 2009 11:06 PM
Tuesday, July 14, 2009 11:02 PM -
Nice clock Glennium, it's helping me brush up on roman numerals, didn't know what an L (50?) before.
How about a binary clock?? That'll drive people nuts. Or hexadecimal, octal, analog? A funny clock I've seen is a real analog that spins counterclockwise, to keep you on your toes.
How about 3 hourglasses pouring sand, one each for hour/minute/second?Wednesday, July 15, 2009 5:18 AM -
It's funny that you said you would like to see an analog clock running backwards.I met Admiral Grace Hopper back in '82 (when she was still a Captain), and on herdesk she had a ship's clock that she had rigged to run backwards. She also inventedthe first compiler, and worked on COBOL.Anyway, here is my "Regular" analog clock TKV488, which all you have to do is changethe direction and it will run backwards.Here are the hands I used to make it run...
[img]http://img.smakkie.com/SH.png[/img]
[img]http://img.smakkie.com/MH.png[/img]
[img]http://img.smakkie.com/HH.png[/img]Glenn- Edited by Glennium Thursday, July 16, 2009 4:29 PM
Thursday, July 16, 2009 1:52 PM -
Glennium, maybe it's better to take hands directly from your website?
Iter = "http://img.smakkie.com" DrawTicks() SecondHand = Shapes.AddImage(Iter + "/SH.png") MinuteHand = Shapes.AddImage(Iter + "/MH.png") HourHand = Shapes.AddImage(Iter + "/HH.png")
BTW there is an error in SB if backslash is used in URLs. I report this issue in appropriate thread.
GrzesioThursday, July 16, 2009 4:21 PM -
You are correct, I could have done that, but different forums have different styles of trying to insert pictures.I just thought it could be easier to cut and paste from here...GlennThursday, July 16, 2009 4:27 PM
-
Maybe it's good idea? I personally like when code does everything including pictures download :)
Now people may choose.
GrzesioThursday, July 16, 2009 4:31 PM -
I made an extremely basic dictionary lookup app (note: this app requires the Speech and Music extension to function properly, downloadable at http://smallbasic.com/smallbasic.com/wiki/speech_music_extension.ashx):
http://smallbasic.com/program/?LPF760UPDATE:
An updated version of the above program is available at:The update contains the def cleaner written by LitDev and a "Please wait..." prompt after the user enters the word to be defined. Thanks, LitDev!- Edited by iUberGeek Thursday, July 23, 2009 11:15 PM Updated the program
Wednesday, July 22, 2009 4:23 AM -
Good program,
It seems that TextWindow.WriteLine(def) is printing some characters that are sounded as beeps. You can remove these, I think they are unicode 7 and possibly some < 0 or > 255? Here is a sub to clean the def before writing it.
Sub clean
cleandef = ""
For i = 1 To Text.GetLength(def)
char = Text.GetSubText(def,i,1)
code = Text.GetCharacterCode(char)
If ( code >= 0 And code <> 7 And code < 256) Then
cleandef = cleandef+char
EndIf
EndFor
def = cleandef
EndSubWednesday, July 22, 2009 7:08 PM -
Thanks, LitDev! See my edited post above...Thursday, July 23, 2009 11:16 PM
-
I wrote a text program. It writes its own directory so it works with anything. I'll make the directories changeable later on.Import JGH297Note I'm fairly new to SB. If anyone has any suggestions for improvement I'm happy to recieve.
- Edited by abish Tuesday, August 4, 2009 6:26 PM I want to improve
Tuesday, August 4, 2009 6:18 PM -
Have created an application for so-called vocabulary test, which also give an example of the usage of external files.
In the program you can enter pairs of words (e.g. from english to german, you ca also add these lists directly in a text file) and be asked to guess (at least in Norway, children often have to learn vocabulary in a foreign language by learning a set of words). The program can be extended relatively simply to support any Q&A (e.g. capitals of countries etc.)
Since it depends on that the vocabulary pairs are in an external file in a particular directory, in is provided as a zip-file at http://www.idi.ntnu.no/~krogstie/smallbasic/vocabulary.zip
The program code is also provided below (made for 0.5 not yet tested for 0.6) (but note you have to create a directory where the vocabulary files should reside, see rootfile)
'Made for SmallBasic version 0.5, English language version TextWindow.Title = "Vocabulary test" 'Directory where vocabulary files resides, expected to be on a 'vocabulary'-catalogue 'beneath the program rootfile = Program.Directory + "\vocabulary\" 'get the available files on the directory provideusername () filearray = File.GetFiles(rootfile) numfiles = Array.GetItemCount(filearray) choosenfile = 0 While choosenfile = 0 choosedictionary() endwhile 'Settings 'illustration from flickr, NB take time, only relevant if one of the languages is english not checked picture = "off" 'sound-effects sounds = "off" 'main loop While choice <> 9 choice = 0 mainmenu () If choice = 1 then clear() guess () endif If choice = 2 then clear() competition () endif If choice = 3 then list() endif If choice = 4 then add() endif If choice = 5 then update() endif If choice = 6 then choosedictionary() endif If choice = 7 then newlist() endif If choice = 8 then admin() endif EndWhile TextWindow.WriteLine ("Goodbye "+username) Program.Delay(1300) Program.End() 'main menu Sub mainmenu TextWindow.WriteLine("Press enter") Dummy = TextWindow.Read() TextWindow.Clear() While choice < 1 or choice > 9 TextWindow.WriteLine ("") TextWindow.WriteLine ("Main menu") TextWindow.WriteLine ("") TextWindow.WriteLine ("1 - Guess one word ("+direction+")") TextWindow.WriteLine ("2 - Guess several words ("+direction+")") TextWindow.WriteLine ("3 - List words") TextWindow.WriteLine ("4 - Enter new vocabulary pair") TextWindow.WriteLine ("5 - Update vocabulary pair") TextWindow.WriteLine ("6 - Change vocabulary list") TextWindow.WriteLine ("7 - Create new vocabulary list") TextWindow.WriteLine ("8 - Change settings") TextWindow.WriteLine ("9 - End") TextWindow.WriteLine ("") TextWindow.Write ("Choose function (1-9): ") choice = TextWindow.ReadNumber() EndWhile EndSub Sub choosedictionary TextWindow.WriteLine ("") TextWindow.WriteLine ("Choose vocabulary list") TextWindow.WriteLine ("") For i = 1 To numfiles vocabularyfile = filearray [i] lang1= File.ReadLine (vocabularyfile, 1) lang2= File.ReadLine (vocabularyfile, 2) TextWindow.WriteLine (i+" "+lang1+" to "+lang2) EndFor TextWindow.WriteLine ("") TextWindow.Write("Make a choice (1-"+numfiles+"): ") filechoice = TextWindow.ReadNumber() If filechoice = choosenfile then TextWindow.WriteLine ("You are already using this list") else If filechoice > 0 and filechoice <= numfiles Then choosenfile = filechoice vocabularyfile = filearray [choosenfile] readfile() Else TextWindow.WriteLine ("Illegal choice") EndIf Endif EndSub Sub readfile 'read contents from file, first two lines indicate the name of the pair (from to) lang1= File.ReadLine (vocabularyfile, 1) lang2= File.ReadLine (vocabularyfile, 2) If lang1 ="English" or lang2 = "English" then englishrelevance = "on" else englishrelevance = "off" endif wordpair="dummy" numwords = 1 fromlang = lang1 tolang = lang2 direction =tolang+" to "+ fromlang default = direction opposite = fromlang+" to "+ tolang 'Read data to end of file While wordpair <> "" wordpair = File.ReadLine (vocabularyfile, numwords+2) If wordpair <> "" Then length = Text.GetLength(wordpair) found = 0 pos = 0 While found = 0 pos = pos + 1 If Text.GetSubText(wordpair,pos,1) = ";" Then found = 1 EndIf EndWhile word1 = Text.GetSubText (wordpair,1,pos-1) word2 = Text.GetSubText (wordpair, pos+1, length-pos) lang1[numwords] = word1 lang2[numwords] = word2 numwords=numwords+1 EndIf Endwhile numwords = numwords-1 EndSub Sub list 'add stops for long lists TextWindow.WriteLine ("") TextWindow.WriteLine (" "+fromlang+" "+tolang) TextWindow.WriteLine ("") For i = 1 To numwords word1 = lang1[i] word2 = lang2[i] lengde = 15 - Text.GetLength(word1) padding = " " For j = 1 To lengde padding = padding + " " endfor If i < 10 Then TextWindow.WriteLine (" "+i+ " " + word1+padding+word2) else TextWindow.WriteLine (i+ " " + word1+padding+word2) endif EndFor TextWindow.WriteLine ("") EndSub 'Guess single word Sub guess new = 0 while new = 0 i = Math.GetRandomNumber(numwords) if pick[i] = 0 Then new = 1 pick [i] = 1 EndIf EndWhile word1= lang1[i] word2= lang2[i] If picture = "on" Then TextWindow.WriteLine ("Getting illustration from flickr ") If fromlang = "English" then pic = Flickr.GetRandomPicture(word1) else pic = Flickr.GetRandomPicture(word2) endif GraphicsWindow.DrawResizedImage(pic,0,0,640,480) EndIf If direction = default then fromword = word2 toword = word1 tolanghere = fromlang Else fromword = word1 toword = word2 tolanghere = tolang endif TextWindow.Write ("What is '" + fromword + "' in "+ tolanghere + "? ") guess = TextWindow.Read() lowcaseguess= Text.ConvertToLowerCase (guess) If lowcaseguess <> toword then TextWindow.WriteLine ("Wrong, correct answer is " + toword) if sounds = "on" then Sound.PlayBellRing () endif Else TextWindow.WriteLine ("") TextWindow.WriteLine ("Correct ") numcorrect = numcorrect + 1 if sounds= "on" then Sound.PlayChime () endif endif TextWindow.WriteLine("") EndSub 'Competition, one try for each, add high-score list Sub competition numcorrect = 0 TextWindow.Write ("How many times do you want to guess (1 - "+numwords+")? " ) times = TextWindow.ReadNumber () If times > numwords then times = numwords TextWindow.Writeline ("There is only "+ numwords + " words in the current list" ) endif If times > 0 then For j = 1 To times guess () EndFor TextWindow.WriteLine("") TextWindow.WriteLine ("You got "+numcorrect+" of "+times+" correct") endif endsub Sub clear 'clear array to test if the same word is not choosen twice For i = 1 to numwords pick [i] = 0 EndFor Endsub 'Add new word Sub add TextWindow.Write ("Enter " + fromlang +" word: ") word1 = TextWindow.Read () TextWindow.Write ("Enter matching word in "+ tolang +" ") word2 = TextWindow.Read () 'check if exist wordexist () If existing = 0 then 'should also check the second word, in case of homonyms numwords = numwords + 1 lowcaseword1 = Text.ConvertToLowerCase (word1) lowcaseword2 = Text.ConvertToLowerCase (word2) lang1[numwords] = lowcaseword1 lang2[numwords] = lowcaseword2 wordpair = lowcaseword1+";"+lowcaseword2 File.AppendContents(vocabularyfile,wordpair) else TextWindow.WriteLine("") TextWindow.WriteLine (word1+ " or "+word2+" is already in the list") endif EndSub Sub update 'placeholder to change an entry (e.g. if a mistake has been made) list () TextWindow.Write("Choose the number of the word to change (1-"+numwords+"): ") choice = TextWindow.ReadNumber() If choice >0 and choice < numwords + 1 then lang1[choice] = "xxx" lang2[choice] = "xxx" TextWindow.Write ("Enter " + fromlang +" word: ") word1 = TextWindow.Read () TextWindow.Write ("Enter matching word in "+ tolang +" ") word2 = TextWindow.Read () 'check if exist wordexist () If existing = 0 then lowcaseword1 = Text.ConvertToLowerCase (word1) lowcaseword2 = Text.ConvertToLowerCase (word2) lang1[choice] = lowcaseword1 lang2[choice] = lowcaseword2 wordpair = lowcaseword1+";"+lowcaseword2 File.WriteLine (vocabularyfile,choice+2,wordpair) else TextWindow.WriteLine("") TextWindow.WriteLine (word1+ " or "+word2+" is already in the list") endif Else TextWindow.WriteLine("Make a choice between (1-"+numwords+")!") endif endsub Sub newlist 'enter filename TextWindow.Write("Enter filename: ") newfile = TextWindow.Read() 'sjekk at filnavn ikke finnes newpath = rootfile + newfile +".txt" found = 0 For i = 1 to numfiles If newpath = filearray[i] Then found = 1 EndIf endfor If found = 1 then TextWindow.WriteLine("The file "+newfile+" already exists") else TextWindow.Write("Enter the first language: ") tempfromlang = TextWindow.Read() TextWindow.Write("Enter the second language: ") temptolang = TextWindow.Read() If tempfromlang = temptolang then TextWindow.WriteLine (tempfromlang+ " should be different than "+ temptolang) else fromlang = tempfromlang tolang = temptolang vocabularyfile=newpath File.WriteLine(vocabularyfile,1,fromlang) File.WriteLine(vocabularyfile,2,tolang) lang1=fromlang lang2=tolang If fromlang ="English" or tolang = "English" then englishrelevance = "on" else englishrelevance = "off" endif 'enter vocabulary pairs (at least one pair) numwords = 0 addpair = 1 while addpair = 1 add() TextWindow.Write("Enter 1 to add more vocabulary pairs: ") addpair = TextWindow.ReadNumber() endwhile direction = tolang+" to "+ fromlang default = direction opposite = fromlang+" to "+ tolang numfiles = numfiles + 1 filearray[numfiles] = vocabularyfile choosenfile = numfiles endif endif endsub Sub wordexist 'check if word already in list existing = 0 counter = 1 While counter <= numwords and existing = 0 If word1 = lang1[counter] or word2 = lang2[counter] then existing = 1 EndIf counter = counter + 1 endwhile endsub Sub provideusername TextWindow.Write ("Enter your name ") username =TextWindow.Read () endsub Sub admin ' Make this as a menu 'Different users 'sound on and off 'High-score (vs each vocabulary file ?) TextWindow.Write ("From " + direction +", do you want to change (Y/N)? ") valg = TextWindow.Read () If text.ConvertToUpperCase(valg) = "Y" Then if direction = default then direction=opposite Else direction = default endif EndIf If englishrelevance = "on" then TextWindow.Write("Flickr-pictures are "+ picture +", change (Y/N)? ") valg = TextWindow.Read () If text.ConvertToUpperCase(valg) = "Y" Then If picture = "off" Then picture = "on" Else picture = "off" EndIf EndIf EndIf EndSub
Friday, August 21, 2009 6:23 PM -
I just started using small basic a couple days ago and I'm really enjoying it. This code is the beginning of a ship game - not much is done yet except for the initial setup of the ship for the player. The speed of the ship is controlled by the wind direction.
Up arrow: Lift the anchor.
Left arrow: Turn Port.
Right Arrow: Turn Starboard.
Down Arrow: Drop the anchor.
The program ID is: SGN809
Download at: http://smallbasic.com/program/?SGN809Thursday, September 17, 2009 1:36 PM -
Phidisher,
Really nice code structure and helpful comments - very easy to follow.
Comments:
1] Calls to SmallBasic functions can be slow if done often, so limit these calls, especially in loops. For example in getcommand , you could use key = GraphicsWindow.LastKey , then check the variable key rather than calling GraphicsWindow.LastKey repeatedly. This is of very little importance here, but good to remember.
2] Shapes are drawn from the top left corner of the shape. Often the game coordinates are easiest using the shape centre (e.g. to interact with mouse position or for collision detection), hence we often draw the shape at (x-width/2,y-height/2), where (x,y) is the centre of the shape and width,height are for the shape. Again of no impact here, but could be useful later.
3] You could use a Timer event to change the wind direction.
Nice work, look forward to more of the game.
Thursday, September 17, 2009 6:58 PM -
This could be alot of fun with another player and you have your cannons going! You might try this code change to make heading not jump sometimes, also I noticed there's no East heading check:
If(GraphicsWindow.LastKey = "Left") Then 'heading = math.Abs(Math.Remainder(heading + .9, 360)) heading = Math.Remainder(heading + .9, 360) vhead = heading * -1 Shapes.Rotate(myship, vhead) endif If(GraphicsWindow.LastKey = "Right") Then If heading = 0 Then heading = 360 EndIf heading = Math.Remainder(heading - .9, 360) If heading < 0 then heading = heading + 360 EndIf vhead = heading * -1 Shapes.Rotate(myship, vhead) endif
Friday, September 18, 2009 8:30 PM -
Demo code for times table calculation using two loops:
http://smallbasic.com/program/?CFV877Friday, September 18, 2009 10:59 PM -
Hello everyone!
This is my little contribution with an example (http://smallbasic.com/program/?BPB749) that, i suppose, might be instructive for the implementation of passing parameters, return values from procedures, analysis of recursion, conservation of local variables and a correct use of Stack in an enviroment as Small Basic that behaves a bit like the assembly language.
The program is fully commented for easy understanding!
The program implement the recursive function to calculate the factorial and the recursive function of Fibonacci.
I translated "introducing Small Basic" in Italian. May be useful?
Thanks to allTuesday, October 13, 2009 12:00 AM -
CiccioIT, if you want to publish the Italian version of the "Introducing Small Basic" document, please contact me at: vijayegatmicrosoftdotcom. I'll hook you up with our Localization expert.Tuesday, October 13, 2009 12:16 AM
-
The Turtle draws the logarithmic and Archimede's Spiral.
The drawing is totally customizable.
Attention! (Bug) Program Listing remove some code line. Use the import command in the Small Basic Enviroment to get the program with code
NNR245
http://smallbasic.com/program/?NNR245Wednesday, October 14, 2009 9:57 PM -
Well im a beginner so I dont have much. I just started yesterday night. So far I have1.A turtle program that makes three squares- Import # FPJ0312.A turtle program that makes a hexagon and also has a repeat function- Import # NFG8433.A program that grabs images off of flickr depending on the query you type in the TextWindow- Import # NNL559 (Was gonna make it set as desktop background on request)4.A cacluator (Was helped with a youtube tutorial)5.A button game (Same as above)I know it dosent seem much but for me it makes very good progress for me.4 and 5 is not my code so I wont post it in respect of the maker2 questions1.Is there any good tutorials for SmallBasic I already read the PDF that came with it2.Is there a way to visually see the cordinates (X and Y) for GraphicsWindow I am only 13 (Dont think im not good at computers becuase of my age I do a lot of things) So i havent taken a course yet in math to figure that out and it would really help if i didnt have to plugin numbers and take a guess (Maybe a grid would help)Wednesday, October 21, 2009 1:49 AM
-
Here's a simple chat/IM client.
KLG986
Uses a ColdFusion web application server to process the requests and maintain session data.
NOTE: You'll have to un-comment the line starting with: "checkDir = File." as it is automatically commented out when publishingSunday, November 1, 2009 8:05 AM -
Hi,
I wrote a small clock program, my first attempt using Small Basic, I've commented the source, hope it's useful to somebody :-)
P.S. I am pretty sure it could be made smaller, however, that was not my goal, I was just exploring the languadge.
'Open a graphis Window for the Clock GraphicsWindow.Width = 850 GraphicsWindow.Height = 200 ' Set colors ' Background color BackColor="Black" ' Foreground color (digits & dots) ForeColor="White" 'Set initial color GraphicsWindow.BackgroundColor = BackColor GraphicsWindow.BrushColor = ForeColor ' Variables used ' Seconds (latest / Last used) sec = 8 oldsec = -1 ' Minutes (latest / Last used) min = 8 oldmin = 0 ' Hours (latest / Last used) hrs = 8 oldhrs = 0 ' Start loop While sec < 60 'Get current time (Sec, Min, and hrs) sec = Clock.Second min = Clock.Minute hrs = Clock.Hour ' if the clock has changed since the last loop (takes less than 1 second per loop) if oldsec<>sec Then ' Update flashing dots dodots() ' redraw the Seconds comp = sec breakdown() offset = 750 num = units draw_segs() offset = 600 num = tens draw_segs() If min<>oldmin then ' Check if the Minutes have changed, redraw if yes. comp = min breakdown() offset = 450 num = units draw_segs() offset = 300 num = tens draw_segs() EndIf If hrs<>oldhrs then ' Check if the Hours have changed, redraw if yes. comp = hrs breakdown() offset = 150 num = units draw_segs() offset = 0 num = tens draw_segs() EndIf 'Save current time information for next pass oldsec = sec oldhrs = hrs oldmin = min EndIf ' end of loop, start again EndWhile Sub dodots 'If even seconds: Dot is ON, if Odd seconds: Dot is OFF (Change color) If sec/2 = Math.Ceiling(sec/2) then GraphicsWindow.BrushColor = ForeColor Else GraphicsWindow.BrushColor = BackColor endIf ' Draw dots (two triangles) ' Right Bottom GraphicsWindow.FillTriangle (570,140,580,140,575,135) GraphicsWindow.FillTriangle (570,140,580,140,575,145) ' Right Top GraphicsWindow.FillTriangle (570,50,580,50,575,45) GraphicsWindow.FillTriangle (570,50,580,50,575,55) 'Left Bottom GraphicsWindow.FillTriangle (270,140,280,140,275,135) GraphicsWindow.FillTriangle (270,140,280,140,275,145) ' Left Top GraphicsWindow.FillTriangle (270,50,280,50,275,45) GraphicsWindow.FillTriangle (270,50,280,50,275,55) endsub sub breakdown ' take a number "00" to "59" and turn it into Tens and Units ' Much easier with 'Int' function ' tens = int (comp/10) 'units = comp - tens ' Oh well..... If comp < 10 Then tens = 0 units = comp ElseIf comp <20 then tens = 1 units = comp - 10 ElseIf comp <30 then tens = 2 units = comp - 20 ElseIf comp <40 then tens = 3 units = comp - 30 ElseIf comp <50 then tens = 4 units = comp - 40 ElseIf comp <60 then tens = 5 units = comp - 50 EndIf endsub Sub draw_segs ' Decide what number to draw 0 .. 9 ' Select case would have been nice I guess If num=1 then draw_1() elseIf num=2 then draw_2() elseIf num=3 then draw_3() elseIf num=4 then draw_4() elseif num=5 then draw_5() elseif num=6 then draw_6() elseif num=7 then draw_7() elseif num=8 then draw_8() elseif num=9 then draw_9() elseIf num=0 then draw_0() EndIf endsub sub draw_0 ' Draw a number 0 GraphicsWindow.BrushColor = ForeColor Horiz_top() Vert_TL() Vert_TR() Vert_BL() Vert_BR() Horiz_bot() GraphicsWindow.BrushColor = BackColor Horiz_mid() endsub sub draw_1 ' Draw a number 1 GraphicsWindow.BrushColor = ForeColor Vert_TR() Vert_BR() GraphicsWindow.BrushColor = BackColor Horiz_top() Vert_TL() Horiz_mid() Vert_BL() Horiz_bot() endsub sub draw_2 ' Draw a number 2 GraphicsWindow.BrushColor = ForeColor Horiz_top() Vert_TR() Horiz_mid() Vert_BL() Horiz_bot() GraphicsWindow.BrushColor = BackColor Vert_TL() Vert_BR() endsub sub draw_3 ' Draw a number 3 GraphicsWindow.BrushColor = ForeColor Horiz_top() Vert_TR() Horiz_mid() Vert_BR() Horiz_bot() GraphicsWindow.BrushColor = BackColor Vert_TL() Vert_BL() endsub sub draw_4 ' Draw a number 4 GraphicsWindow.BrushColor = ForeColor Vert_TL() Vert_TR() Horiz_mid() Vert_BR() GraphicsWindow.BrushColor = BackColor Horiz_top() Vert_BL() Horiz_bot() endsub sub draw_5 ' Draw a number 5 GraphicsWindow.BrushColor = ForeColor Horiz_top() Vert_TL() Horiz_mid() Vert_BR() Horiz_bot() GraphicsWindow.BrushColor = BackColor Vert_TR() Vert_BL() endsub sub draw_6 ' Draw a number 6 GraphicsWindow.BrushColor = ForeColor Horiz_top() Vert_TL() Horiz_mid() Vert_BL() Vert_BR() Horiz_bot() GraphicsWindow.BrushColor = BackColor Vert_TR() endsub sub draw_7 ' Draw a number 7 GraphicsWindow.BrushColor = ForeColor Horiz_top() Vert_TR() Vert_BR() GraphicsWindow.BrushColor = BackColor Vert_TL() Horiz_mid() Vert_BL() Horiz_bot() endsub sub draw_8 ' Draw a number 8 GraphicsWindow.BrushColor = ForeColor Horiz_top() Vert_TL() Vert_TR() Horiz_mid() Vert_BL() Vert_BR() Horiz_bot() endsub sub draw_9 ' Draw a number 9 GraphicsWindow.BrushColor = ForeColor Horiz_top() Vert_TL() Vert_TR() Horiz_mid() Vert_BR() Horiz_bot() GraphicsWindow.BrushColor = BackColor Vert_BL() endsub sub Horiz_top 'Select offset for horizontal segment, TOP X=10 y=10 Horiz_Seg() endsub sub Horiz_mid 'Select offset for horizontal segment, MIDDLE X=10 y=94 Horiz_Seg() endsub sub Horiz_bot 'Select offset for horizontal segment, BOTTOM X=10 y=178 Horiz_Seg() endsub Sub Vert_TL 'Select offset for Vertical segment, TOP LEFT X=8 y=12 Vert_Seg() endsub Sub Vert_TR 'Select offset for Vertical segment, TOP RIGHT X=92 y=12 Vert_Seg() endsub Sub Vert_BL 'Select offset for Vertical segment, BOTTOM LEFT X=8 y=96 Vert_Seg() endsub Sub Vert_BR 'Select offset for Vertical segment, BOTTOM RIGHT X=92 y=96 Vert_Seg() endsub Sub Horiz_Seg ' Draw the Horizontal Segment ' Offset gives the location; i.e. "Hours, Minutes, or Seconds" and then "Tens or Units" ' x is the position "Top, Middle, or Bottom" x=x+offset 'draw two triangles (Top and Bottom) GraphicsWindow.FillTriangle (X+0,Y+0,X+10,Y+10,X+10,Y-10) GraphicsWindow.FillTriangle (X+80,Y+0,X+70,Y+10,X+70,Y-10) 'draw one rectangle (middle portion) GraphicsWindow.FillRectangle (x+10,y-10,60,20) EndSub Sub Vert_Seg ' Draw the Horizontal Segment ' Offset gives the location; i.e. "Hours, Minutes, or Seconds" and then "Tens or Units" ' x is the position "Top Left, Top Right, Bottom Left, or Bottom Right" x=x+offset 'draw two triangles (each end) GraphicsWindow.FillTriangle (X+0,Y+0,X+10,Y+10,X-10,Y+10) GraphicsWindow.FillTriangle (X+0,Y+80,X+10,Y+70,X-10,Y+70) 'draw one rectangle (middle portion) GraphicsWindow.FillRectangle (x-10,y+10,20,60) EndSub
Thursday, November 5, 2009 10:34 AM -
PinaPete: Really nice piece of app! Especially if you are beginner.
Remember you can export your source using toolbar button in SB and give us only the code. It may be useful when posting large amount of lines.
GrzesioThursday, November 5, 2009 12:24 PM -
Not an absolute beginner, I have dabled with various basic variations, I must say I like this one it makes you think a little about what you are doing.
And yes I did try the "Publish" button but it did not function, maybe it's the companies firewall (not that I would do anything like this during working hours).Thursday, November 5, 2009 2:29 PM -
I had a moment of thought, rare but does happen, the code below replaces the "Breakdown" sub routine, it's not a pretty solution but cuts down the process some what, I love short solutions:
sub breakdown ' Take the value as a two letter word then use ' GetSubText to get the 1st and second characters
If Text.GetLength(comp) = 1 then tens = "0" units = Text.GetSubText(comp,1,1) else tens = Text.GetSubText(comp,1,1) units = Text.GetSubText(comp,2,1) endif endsubFriday, November 6, 2009 10:46 AM -
This is probably a little closer to the code you initially had in mind:Sub breakdown' Calculate tens and units for comptens = Math.Floor(comp/10)units = Math.Remainder(comp, 10)EndSubInteger devision in other languages is synonymous with the result from Math.Floor() in Small Basic.Rather than calculating the units = comp - (tens * 10) you can Math.Remainder() which allows you to calculate the remainder of a division.Hope this helps,Jason.Friday, November 6, 2009 1:45 PM
-
Here's my Example Project Compilation!
SSG215
have fun!
Live for nothing, OR CODE FOR SOMETHING!Saturday, November 7, 2009 3:07 PM -
Finding problems running old example code in v.0.7 I decided to write a debugger to see what was going on. Might be useful to others...The Import code is: KGH734Just paste this entire code into the end of your own program and use it as necessary.
' =============================================================== ' ==== DEBUGGER v1 ======= ' =============================================================== ' (c) davey-wavey 2009 ' ' To 'watch' a variable, use: dbug["description"]=variable ' ' where 'description' is a text string - usually just the name of the variable again ' and 'variable' is the variable value to show ' e.g. dbug["score"]=score ' ' To show the debug textWindow, put this at the end of your main loop: debug() ' ' NOTE: This will only really work with graphics programs as it will wipe out textWindow ones! ' Sub Debug nl=Text.GetCharacter(10) ' define the newline character tmpdbug=dbug ' get copy of dbug values ' convert all semicolon separators to newlines While (Text.GetIndexOf(tmpdbug,";") > 0) tmpdbug = Text.GetSubText(tmpdbug,1,text.GetIndexOf(tmpdbug,";")-1) + nl + Text.GetSubTextToEnd(tmpdbug,text.GetIndexOf(tmpdbug,";")+1) EndWhile ' clear textwindow and output debug text TextWindow.Clear() TextWindow.WriteLine ("==== DEBUG START ====" + nl) TextWindow.WriteLine (tmpdbug) TextWindow.WriteLine ("==== DEBUG END ====" +nl) EndSub
Sunday, November 8, 2009 6:22 PM -
Small Basic Windows (sbWin) - import code: SKD503I've been playing with creating a mini windows environment within SB. I've given up on it now as SB is too basic to handle the graphics, and you can only write text to the background, not onto shapes.Anyway, I'm posting it here in case any of it is useful as an example to someone.Wednesday, November 11, 2009 4:01 PM
-
KWD243 its a picture bridge building mind game i think.
have fun
Me heads a shed and me lifes a dream, Its all for fun and mostley free.Wednesday, November 18, 2009 4:29 AM -
Here's my Example Project Compilation!
kewl, thanks, had to take 2 lines out though :)>
SSG215
have fun!
Live for nothing, OR CODE FOR SOMETHING!
Me heads a shed and me lifes a dream, Its all for fun and mostley free.Wednesday, November 18, 2009 4:46 AM -
It's taken me 10 years, but I've finally done it!SNAKEBITE - SBThe full program excluding images/sound: KTN094You can download the full game here: snakeBite.zipAn early concept version with vector graphics: VHG623Thursday, November 26, 2009 9:18 PM
-
Here is my second ever Small Basic program. A analog desktop clock.
Code ID: HFR208
http://taylorza.blogspot.comSunday, December 6, 2009 6:39 PM -
It's taken me 10 years, but I've finally done it!
SNAKEBITE - SBThe full program excluding images/sound: KTN094You can download the full game here: snakeBite.zipAn early concept version with vector graphics: VHG623
Very nice, Davey-Wavey.Sunday, December 6, 2009 9:25 PM -
Nice job Chris! I hope you don't mind but I tweaked a few things on your clock and made it a bit more analog-like: HFR208-0
http://smallbasic.com/program/?HFR208-0Monday, December 7, 2009 7:54 AM -
Hi Brain,
I dont mind at all. Amongst other things, I like the improvement in readability of the angle calculation in the DrawHand routine.
Cheers
Chris
http://taylorza.blogspot.comMonday, December 7, 2009 6:09 PM -
Published SnakeBite with resources (FWB006).Monday, December 7, 2009 6:42 PM
-
Hey, guys. I downloaded SB a few days ago and have had a lot of fun with it, so kudos to everyone involved in making it. :)
Anyway, my first sample is a simple rotation matrix subroutine. It's made to work with the coordinate system used by the graphics window (i.e. a positive angle value will rotate the vector clockwise).
I thought it might be useful to people who are not math geeks like some of us. :P
Import: HRG076Tuesday, December 8, 2009 9:46 PM -
uh.. sorry, but what does it actually do? i dont get it...
Live for nothing, OR CODE FOR SOMETHING!Wednesday, December 9, 2009 5:38 PM -
Published SnakeBite with resources (FWB006).
Awesome, thanks Vijaye!Wednesday, December 9, 2009 9:24 PM -
uh.. sorry, but what does it actually do? i dont get it...
A vector has direction and length. In games they are typically used to move objects. E.g. the Paddle Game in the intro pdf uses the vector (deltaX,deltaY) to move the ball. My rotation matrix subroutine will take a vector and rotate it a given number of radians.
Live for nothing, OR CODE FOR SOMETHING!
If you wanted the ball to move in a direction based on where it hits the paddle you could do something like this:
' Get the position where the ball hit the paddle.
ballOffset = (ballX - paddleX) * 2 / paddleWidth
' Get the angle by multiplying the largest desired angle with the offset.
' If the ball hits at the edge of the paddle it will fly off at a 80 degrees angle. If it hits in the middle it will fly straight up.
angle = Math.GetRadians(80) * ballOffset
' Rotate the up vector with the angle. In the Small Basic graphics window up is represented by (0, -1).
Stack.PushValue(params, 0)
Stack.PushValue(params, -1)
Stack.PushValue(params, angle)
RotationMatrix()
deltaX = Stack.PopValue(return)
deltaY = Stack.PopValue(return)
Modified paddle game: XKC688Sunday, December 13, 2009 9:13 AM -
Speaking of paddle games.
Import: TCT438
Level Editor: KCT242
Not done yet, but I thought I might as well get some feedback.
Credit goes to my friend Lasse for the awesome graphics.Sunday, December 13, 2009 9:38 AM -
do you mean something like this?:
VNX111
Live for nothing, OR CODE FOR SOMETHING!Sunday, December 13, 2009 1:19 PM -
do you mean something like this?:
VNX111
Live for nothing, OR CODE FOR SOMETHING!
Not quite. You use trigonometry to find a point on the circumference of the unit circle, while I use a matrix to rotate any given vector. Both approaches could be used for the example I posted, but the matrix is more versatile and I find it to be more intuitive to use.Monday, December 14, 2009 1:00 AM -
Not quite. You use trigonometry to find a point on the circumference of the unit circle, while I use a matrix to rotate any given vector. Both approaches could be used for the example I posted, but the matrix is more versatile and I find it to be more intuitive to use.
Can you explain this a bit more for us non-maths geeks please? At the moment it's neither versatile nor intuitive to me.What is the matrix that you use, and how does it affect the x,y,angle values in your first example? In your example, if I enter 1,0,45 respectively, I get a result of 0.707106781186548 for both x and y. Why hasn't my x coord moved 1 unit as I wanted it to?I guess, more importantly, what would be a real-world example where this would be useful in coding a game feature?Thanks.Tuesday, December 15, 2009 1:31 AM -
Not quite. You use trigonometry to find a point on the circumference of the unit circle, while I use a matrix to rotate any given vector. Both approaches could be used for the example I posted, but the matrix is more versatile and I find it to be more intuitive to use.
Can you explain this a bit more for us non-maths geeks please? At the moment it's neither versatile nor intuitive to me.What is the matrix that you use, and how does it affect the x,y,angle values in your first example? In your example, if I enter 1,0,45 respectively, I get a result of 0.707106781186548 for both x and y. Why hasn't my x coord moved 1 unit as I wanted it to?I guess, more importantly, what would be a real-world example where this would be useful in coding a game feature?Thanks.
I use a rotation matrix, which rotates a vector by the specified angle. To understand this you really only need to understand vectors, so let's take it from the bottom.
I will assume that you already have a good understanding of coordinate systems, since that is required to use the SB graphics window. A vector describes a direction and distance from an origin. Say you have the vector (1, 2). If you add this vector to the point (5, 7), it will move that point in the vector's direction by the vector's length, which gives you (1 + 5, 2 + 7) = (6, 9). This is what the Paddle Game does with deltaX and deltaY. Now, what if you want the ball to go in a direction 90 degrees from its current course? That is where the rotation matrix comes in handy. You just give it the numbers and it will return the vector (-2, 1), which is at a 90 degrees angle from (1, 2).
To show your own example of rotating the vector (1, 0) by 45 degrees I made this:
I hope that clears it up a bit.
As for your final question, rotation matrices are typically used for the camera in 3D games. In 2D games it could for example be used to change the direction an object is headed based on user input or you could rotate the gameworld around the player character. You could also use it to realistically change the direction of an object when it collides with another object. The Turtle in SB probably uses vectors and matrices internally. In general there are a shitload of applications for vectors and matrices, as you will see if you look it up on Wikipedia. E.g. I used 4D rotation matrices for this .
In general I would say that if using trigonometry results in too complicated code you should look into using a matrix instead. I don't know how useful it is in the rather restricted environment of SB, but I thought I'd just throw it out there.Tuesday, December 15, 2009 3:38 AM -
Here's an analog clock: XFR839
I use my rotation matrix to draw the dots and position the shapes.
By the way, while making this I noticed that Shapes.Rotate takes degrees while Math.Sin, Math.Cos, et.c. take radians. It threw me off for a bit and seems like bad design.Tuesday, December 15, 2009 5:52 AM -
Speaking of paddle games.
Import: TCT438
Level Editor: KCT242
Not done yet, but I thought I might as well get some feedback.
Credit goes to my friend Lasse for the awesome graphics.
Wow!!! Can't wait to see the finished one.Tuesday, December 15, 2009 8:59 PM -
Rotation Matrix: HRG076-0
I've played around with method overloading, error handling and a naming scheme. In the more useful end I've told it to draw the vector before and after it's rotated.
-
Dot, GetVectorLength and Split: CPP775
Dot: Returns the dot product of two vectors.
GetVectorLength: Returns the length of a vector.
Split: Uses the specified separator to split a string and returns it as an array.Wednesday, December 16, 2009 3:54 AM -
I Made A Program That Can Define Words Like A Dictionary, Link http://smallbasic.com/program/?Define Code:
TextWindow.Title = ("Dictionary") TextWindow.Write("Enter a word: ") word = TextWindow.Read() TextWindow.Hide() GraphicsWindow.Title = ("Definition of "+word+"") GraphicsWindow.FontBold = "False" GraphicsWindow.FontName = "Verdana" GraphicsWindow.FontSize = 24 GraphicsWindow.BrushColor = "DarkGreen" GraphicsWindow.DrawText(10, 10, word) definition = Dictionary.GetDefinition(word) GraphicsWindow.FontSize = 12 GraphicsWindow.BrushColor = "Black" GraphicsWindow.DrawText(10, 60, definition)
Sunday, December 20, 2009 7:21 PM -
I Edited The Sample PaintProgram.sb And I Made It Include Custom Colors. To Change The Color ,Type The First Letter Of The Color You Want While The Program Is Running. You Can Choose From 7 Colors. Link: http://smallbasic.com/smallbasic.com/program/?PWG193 Code:
'This was made from the example "Paint Prgram" 'You can use custom colors 'Just press the first letter of the color 'There are 7 colors GraphicsWindow.BackgroundColor = "Black" GraphicsWindow.PenColor = "White" GraphicsWindow.MouseDown = OnMouseDown GraphicsWindow.MouseMove = OnMouseMove GraphicsWindow.KeyDown = OnKeyDown Sub OnKeyDown If (GraphicsWindow.LastKey = "R") Then GraphicsWindow.PenColor = "Red" EndIf If (GraphicsWindow.LastKey = "W") Then GraphicsWindow.PenColor = "White" endif If (GraphicsWindow.LastKey = "B") Then GraphicsWindow.PenColor = "Blue" endif If (GraphicsWindow.LastKey = "G") Then GraphicsWindow.PenColor = "Green" endif If (GraphicsWindow.LastKey = "P") Then GraphicsWindow.PenColor = "Purple" endif If (GraphicsWindow.LastKey = "Y") Then GraphicsWindow.PenColor = "Yellow" endif If (GraphicsWindow.LastKey = "O") Then GraphicsWindow.PenColor = "Orange" endif If (GraphicsWindow.LastKey = "R") Then GraphicsWindow.PenColor = "Red" EndIf If (GraphicsWindow.LastKey = "W") Then GraphicsWindow.PenColor = "White" endif If (GraphicsWindow.LastKey = "B") Then GraphicsWindow.PenColor = "Blue" endif If (GraphicsWindow.LastKey = "G") Then GraphicsWindow.PenColor = "Green" endif If (GraphicsWindow.LastKey = "P") Then GraphicsWindow.PenColor = "Purple" endif If (GraphicsWindow.LastKey = "Y") Then GraphicsWindow.PenColor = "Yellow" endif If (GraphicsWindow.LastKey = "O") Then GraphicsWindow.PenColor = "Orange" endif EndSub Sub OnMouseDown prevX = GraphicsWindow.MouseX prevY = GraphicsWindow.MouseY EndSub Sub OnMouseMove x = GraphicsWindow.MouseX y = GraphicsWindow.MouseY If (Mouse.IsLeftButtonDown) then GraphicsWindow.DrawLine(prevX, prevY, x, y) endif prevX = x prevY = y EndSub
Sunday, December 20, 2009 7:57 PM -
I Edited The Sample PaintProgram.sb And I Made It Include Custom Colors. To Change The Color ,Type The First Letter Of The Color You Want While The Program Is Running. You Can Choose From 7 Colors. Link: http://smallbasic.com/smallbasic.com/program/?PWG193 Code:
'This was made from the example "Paint Prgram" 'You can use custom colors 'Just press the first letter of the color 'There are 7 colors GraphicsWindow.BackgroundColor = "Black" GraphicsWindow.PenColor = "White" GraphicsWindow.MouseDown = OnMouseDown GraphicsWindow.MouseMove = OnMouseMove GraphicsWindow.KeyDown = OnKeyDown Sub OnKeyDown If (GraphicsWindow.LastKey = "R") Then GraphicsWindow.PenColor = "Red" EndIf If (GraphicsWindow.LastKey = "W") Then GraphicsWindow.PenColor = "White" endif If (GraphicsWindow.LastKey = "B") Then GraphicsWindow.PenColor = "Blue" endif If (GraphicsWindow.LastKey = "G") Then GraphicsWindow.PenColor = "Green" endif If (GraphicsWindow.LastKey = "P") Then GraphicsWindow.PenColor = "Purple" endif If (GraphicsWindow.LastKey = "Y") Then GraphicsWindow.PenColor = "Yellow" endif If (GraphicsWindow.LastKey = "O") Then GraphicsWindow.PenColor = "Orange" endif If (GraphicsWindow.LastKey = "R") Then GraphicsWindow.PenColor = "Red" EndIf If (GraphicsWindow.LastKey = "W") Then GraphicsWindow.PenColor = "White" endif If (GraphicsWindow.LastKey = "B") Then GraphicsWindow.PenColor = "Blue" endif If (GraphicsWindow.LastKey = "G") Then GraphicsWindow.PenColor = "Green" endif If (GraphicsWindow.LastKey = "P") Then GraphicsWindow.PenColor = "Purple" endif If (GraphicsWindow.LastKey = "Y") Then GraphicsWindow.PenColor = "Yellow" endif If (GraphicsWindow.LastKey = "O") Then GraphicsWindow.PenColor = "Orange" endif EndSub Sub OnMouseDown prevX = GraphicsWindow.MouseX prevY = GraphicsWindow.MouseY EndSub Sub OnMouseMove x = GraphicsWindow.MouseX y = GraphicsWindow.MouseY If (Mouse.IsLeftButtonDown) then GraphicsWindow.DrawLine(prevX, prevY, x, y) endif prevX = x prevY = y EndSub
Sunday, December 20, 2009 8:02 PM -
Hi Phillips101,That's a good start on your way to mastering SmallBasic.Let me throw you a challenge... see if you can rewrite your colour changing section (OnKeyDown) using an array.Hint: check out array.containsindex ;-) and it should save you a lot of typing
Monday, December 21, 2009 12:58 AM -
wow! thx davey! i didnt even know you can call arrays with characters!
i redid phillips paint tool: XMX600
changes:
- Change the Penwith with the up and down keys.
- Now you can just add more colors to the color array, witout needing to modify anything else.
- Added a color palette.
- Added edge-smoothing to the drawn line.
- When you press the right mouse button, you should be able to choose the pen color by putting your mouse over the color palette and releasing it. Who
wants to add that feature? something like this: SGS247
- You can easily set the amount of rectangles in the color palette by changing the values of Box_Amount_Horizontal and Box_Amount_Vertical.
it would be really awesome if we all would improve this paint tool, so you can do really much with it. then we could make a thread, where we show off the drawings of each other made in it. (of course by saving and loading them somehow^^)
Enjoy guys!
Live for nothing, OR CODE FOR SOMETHING!Monday, December 21, 2009 5:37 PM -
Update!
i added a brush size changing system. LSK042
i dont have time to perfect it atm...
just press left shift and drag the mouse, and you'll see the brush will change its size.
Live for nothing, OR CODE FOR SOMETHING!Tuesday, December 22, 2009 7:34 PM -
- When you press the right mouse button, you should be able to choose the pen color by putting your mouse over the color palette and releasing it. Who
Requested feature using the small color palette: LSK042-1
wants to add that feature? something like this: SGS247
I've written comments to the stuff I added or changed.Wednesday, December 23, 2009 10:20 AM -
- When you press the right mouse button, you should be able to choose the pen color by putting your mouse over the color palette and releasing it. Who
Requested feature using the small color palette: LSK042-1
wants to add that feature? something like this: SGS247
I've written comments to the stuff I added or changed.
we could also make the color palette a whole new window, wich can be dragged around.. could be more useful.
i'll see what i can do.
Live for nothing, OR CODE FOR SOMETHING!Wednesday, December 23, 2009 2:34 PM -
Conway's Game of Life: FXB616Friday, December 25, 2009 4:17 PM
-
here's an updated version of the paint program: KNK931
the color palette is a new window now. i'll make an RGB Slider window too soon.. (i dont have much time atm..)
and the pen size selector still doesnt work..
Live for nothing, OR CODE FOR SOMETHING!Saturday, December 26, 2009 4:40 PM -
here's my smoke editor code: PBH865
to use it just drag and drop the left mousebutton and a smoke emitter will be created. the lenght of the line created is equal to the smoke velocity. and the direction of the line represents the smoke emitting angle.
Live for nothing, OR CODE FOR SOMETHING!Saturday, January 2, 2010 6:07 PM -
Here's a marketing game called Whack-A-Soft. It's a specialized Whack-A-Mole that's intended to be a humorous (and unbiased) chronicling of over a 1/4 century of competition between Microsoft & Apple. Enjoy!
http://www.filefront.com/15367017/Whack-A-Soft%201.0.zipSaturday, January 16, 2010 9:56 PM -
Well, it's been over a year since I started on this project of my 3D maze, but here is my first version:
RCS876
It is sooooo easy for things to distract you. Also, I got discouraged because I couldn't go as far as I wanted to with my programming - mainly smoother animations using correct 3D math.
(I may use one of the addins I read about in one of the threads that adds support of 3D objects, in a future version, but for now I wanted to put a program together that can be looked at in SB right "out of the box".)
2 major short-commings are;
1) the sound the computer makes when you run into the wall - some people say that it is not found on their computer.
2) the maze only draws 3 wide. In other words if you change the data to have a double-wide hallway, you will see funny results including missing walls where you would expect walls to be drawn.
The maze data is pretty simple.
There are wall coordinates and 'where the player stands' coordinates.
Let's say you want to make the hallway on Mapdata 6 to be one square longer, going East (to the right).
You would have to put a 0 (zero) where the 1 (one) is (which means no wall, and then add another 0 for the place the player will be standing, and then add a 1 after that for the wall.
So think of it as Wall Position, Player Position, Wall Position, Player Position.. etc.
The Player Position in the data will always be zero.
It needs a lot of fine tunning and I am going to add a Map Maker program to let players build their own mazes, as well as ones be generated automaticly.
Needs a End of Maze with a reward because people are going to get board walking around a wireframe maze pretty quick.
I will also be grooming this into a simple (graphics wise anyway) RPG game.
Let me know what ya'll think. I can take constructive criticism. :-)
One more thing, the rest of the programs in this thread blow me, and my program, away.
drc- Edited by Path_drc Sunday, January 17, 2010 3:07 AM correct spelling
Sunday, January 17, 2010 3:04 AM -
Nice! My kids think it's cool. Looks pretty sophisticated. I wonder if some people can't play the sound because it assumes a few things about where the files are located or version of windows, such as a C: drive - says "C:\WINDOWS\Media\Windows XP Battery Low.wav". It worked on my computer. You could just run one of these sounds to be guaranteed a sound, or make your own audio files:
Sound.PlayBellRing()
Sound.PlayChime()
Sound.PlayChimes()
Sound.PlayClick()
I wonder if we could get a function that paints/flood fills an area, like alot of the old basic programs. Then you could paint the walls. That was a great function to have. Something like GraphicsWindow.Paint(floodcolor, bordercolor), or without parameters using the current BrushColor for the flood, and PenColor for the border stops. Vijaye?
I suppose you could paint things by using pre-shaped parallelogram bitmaps you paint on the screen, but that's a bit more work I think (or is it actually easier?). But you could have very detailed walls and textures then.
It'll be neat to see a full adventure.Sunday, January 17, 2010 6:30 AM -
I just saw snakebite, nice job, looks pro!Sunday, January 17, 2010 6:43 AM
-
wow! im impressed!
you posted about this long time ago! I tought you stopped working on it! but i was wrong! haha!
it would be so awesome if it you could really move around it, not just step by step..
Live for nothing, OR CODE FOR SOMETHING!Sunday, January 17, 2010 12:27 PM -
I created a simple reader tweets of twitter using FremyCompany's (FC) extension
English version SQD608
tks Davey-Wavey and dhester- Edited by MaCsousa Wednesday, January 20, 2010 12:58 AM
Monday, January 18, 2010 1:44 AM -
I created a simple reader tweets of twitter using FC extension
MaCsousa, you forgot to mention that it only works with Fremy's extension.
English version SQD608
Tuesday, January 19, 2010 7:40 PM -
Davey-Wavey
MaScousa did say that is was made with the FC (Fremy) extension. I think the Fremy extensions should be part of small basic as they are so useful.Tuesday, January 19, 2010 10:16 PM -
Import: KCH420-0
It's a cute lil' raytracer in Small Basic! It uses orthographic projection (not perspective), up to 10x reflection, any number of lights and spheres (but no other shapes) and diffuse (Lambertian) lighting (no specular highlights). For those unfamiliar with raytracing: it's not the fastest technique around. And Small Basic isn't known for it's amazing speed either so it takes several minutes to completely render the scene.
The code is heavily based on (or rather a port of) the code found on this raytracing tutorial: http://www.codermind.com/articles/Raytracer-in-C++-Part-I-First-rays.html
Update:
NEW! The lil' raytracer special Dudeson Awesomer edition! Includes random scene generation and scene preview. Get yours today!
- Edited by ThirdMagus Friday, January 22, 2010 1:16 PM Update
- Edited by Nonki Takahashi Monday, March 9, 2020 9:55 AM updated an image
Thursday, January 21, 2010 7:07 PM -
you gotta be kidding me...
this is the awesomest thing i've ever seen iN SMALL BASIC!
it would be even awesomer if it would randomly generate an image...
btw, since when is there a way to use multidimensional arrays like this:
Number[x][y]
???
Live for nothing, OR CODE FOR SOMETHING!Thursday, January 21, 2010 11:22 PM -
btw, since when is there a way to use multidimensional arrays like this:
Ever since version 0.5: http://blogs.msdn.com/smallbasic/archive/2009/06/20/arrays-in-small-basic.aspx
Number[x][y]
???Thursday, January 21, 2010 11:32 PM -
btw, since when is there a way to use multidimensional arrays like this:
Ever since version 0.5: http://blogs.msdn.com/smallbasic/archive/2009/06/20/arrays-in-small-basic.aspx
Number[x][y]
???
i didnt know that!!
looks like the project i was using this for was really old...
Live for nothing, OR CODE FOR SOMETHING!Friday, January 22, 2010 1:13 AM -
Okay guys!
heres a simple rope simulation: ZZW635-5
it has a few bugs and it would be awesome if someone could help me fixing them...
Live for nothing, OR CODE FOR SOMETHING!Friday, January 22, 2010 1:14 AM -
Dudeson:
This really is litdev's department, but I'll see what I can do to help ;)
First things first, with bugs I think you mean the wriggling of the rope at the end? That's caused by accuraccy problems. Because you're not working with a continuous time, but rather in steps of 15 ms, you'll end up with some inaccuraccies. One of the ways to deal with this is to add a 'dead-zone' to your calculations. Basicly, if it's smaller than your simulation can work with just call it zero. Another way would be to make the time steps smaller until the errors are no longer noticable. Usually a combination of these two methods are used.
I've updated your sample to use dead-zones: ZZW635-6
The second part would be to add actual physics. In real life, rope is not completely stiff, it can stretch a bit. Nor is rope weightless, each 'rope segment' has a certain weight and is pulled down by gravity. What you'll end up with is a large collection of masses connected by springs.
NeHe has a nice tutorial on rope physics (ignore the C++ and OpenGL stuff ;) ): http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=40Friday, January 22, 2010 12:21 PM -
thx!
i know that about the deadzone.. i just didnt want to add it because its not that logical..
btw, if i remove these lines it looks much more natural if you ask me, because the rope always moves a little bit:
If(Segment_Angle_Speed[i] < 0.1 And Segment_Angle_Speed[i] > -0.1) Then
Segment_Angle_Speed[i] = 0
EndIf
and the major "Bug" here is that the segment at the end of the rope doesnt affect the upper segments at all.. it just works vice versa.. but i just dont know how you add gravitation to such a calculation..
thx! i'll take a look at it!
[EDIT]
I think i found a solution by using my spring code!
Live for nothing, OR CODE FOR SOMETHING!Friday, January 22, 2010 12:31 PM -
I've updated the lil' raytracer: KCH420-0
Thanks for the suggestions Dudeson!Friday, January 22, 2010 1:22 PM -
I've updated the lil' raytracer: KCH420-0
hahaha! cool!
Thanks for the suggestions Dudeson!
no problem!
Live for nothing, OR CODE FOR SOMETHING!Friday, January 22, 2010 1:23 PM -
Heres a "Topdown View" version of the Rope: ZZW635-9
it was made with my spring code wich i made with a little help of litdev.
you can adjust the number of the segments and the "elasticity" (the elasticity isnt really natural at the moment)
now im working on adding gravitation..
Live for nothing, OR CODE FOR SOMETHING!Friday, January 22, 2010 2:13 PM -
here's the unrealistic sideview version of the rope: NVH805
i hope someone can give me a hint on how to make the rope swing..
Live for nothing, OR CODE FOR SOMETHING!Saturday, January 23, 2010 5:52 PM -
You have no momentum - the movement is just determined by the rope joint angle it is connected to and doesn't depend on its velocity.
Think about a swinging rope, it will only swing back and forth like a pendulum if:
1] it is given a continuous driving force - that is someone keeps swinging it, OR
2] it has a weight on the end.
I don't think a rope with no weight on its end and held fixed at the top swings very well, and if it does it is all about the rope pivoting about its top like a single rigid bar (the swinging rope fixed at the top doesn't bend much along its length). In this case the physics is the balance of kinetic(velocity) and potential(gravity) energy, exactly like a pendulum in a clock.
Alternatively, while I was playing:
This (import DBV654) has a bit more physics, with acceleration, velocity and position calculated for each joint. The acceleration of an joint is just the sum of the forces applied by the two segments connected to the joint. The forces depend on the extension (elastic stretch) of the segment and its direction.
The model is a bit sensitive to the parameters set - it can be quite unstable and need shorter time-steps - this is due to explicitness of the method - a more implicit method (calculating everything in one set of matrix equations) would be more complex, but more stable. However it looks a bit like very elastic rope, perhaps like a bungee.
This looks OK because the elastic forces are stronger than the gravity induced swinging, that this model also doesn't capture correctly.
If you want to capture a swinging rope, read up a bit on pendulums which is quite simple for a rigid pendulum, but would be more complex for a segmented rope model.Sunday, January 24, 2010 12:37 AM -
Hi, Alien Chase is a game where you get lots of bangs for your code and may encourage and help new starters who want to make blob chaser games - RBT709Tuesday, January 26, 2010 7:51 PM
-
A 3D wireframe model: RTQ437
i hope someone finds it useful.. (optimized as good as i could..)
next step:
make it rotate-able around the X,Y and Z axis.
Live for nothing, OR CODE FOR SOMETHING!Tuesday, January 26, 2010 8:05 PM -
Hi, Alien Chase is a game where you get lots of bangs for your code and may encourage and help new starters who want to make blob chaser games - RBT709
wow! nice!
i like the explison effect!
btw, its called "Laser" not "Lazer"...
also, why is the crosshair being controlled with the arrow keys? wouldn't it be better if you could aim with the mouse?
Live for nothing, OR CODE FOR SOMETHING!Wednesday, January 27, 2010 5:42 PM -
Nice work grandad, lots of explosions make it look real purty.
The wireframe looks kinda neat with the flashing look. Maybe you're next step is Battlezone? http://www.moteinteractive.com/tutorials/gameDev/battlezone2.gifThursday, February 4, 2010 5:53 AM -
The wireframe looks kinda neat with the flashing look. Maybe you're next step is Battlezone? http://www.moteinteractive.com/tutorials/gameDev/battlezone2.gif
are you talking to me?
if yes:
thx^^
well.. the performance of small basic is too bad for that...
Live for nothing, OR CODE FOR SOMETHING!Thursday, February 4, 2010 6:21 PM -
But his Lazer is better than a plain Laser :D
Thursday, February 4, 2010 6:30 PM -
But his Lazer is better than a plain Laser :D
Live for nothing, OR CODE FOR SOMETHING!Thursday, February 4, 2010 6:38 PM -
it would be nice if when authoring a reply like this one could use some tag like download:ID or [download]ID[/download] to mark a download. New users don't know what to do with "QND161" say number
Microsoft MVP J# 2004-2009, Borland Spirit of Delphi 2001
in general, the msdn devlab folks could give some meaningful names to all imported codes... and also, allow for users to search the user code library... thanksWednesday, February 10, 2010 7:14 PM -
HMC614 Just a little binary clock, but took a bit of effort to work out how to do it.Thursday, February 11, 2010 12:30 PM
-
That's a nice little gadget, it'd be funny to have one on your desk.Thursday, February 11, 2010 8:09 PM
-
HMC614 Just a little binary clock, but took a bit of effort to work out how to do it.
Hahaha! cool!
I saw such a real watch once! its really cool!
Live for nothing, OR CODE FOR SOMETHING!Thursday, February 11, 2010 10:30 PM -
Here is my finished Big Guns game. PGT741
This is my first Simple Basic program. Its kind of fun! I remember playing this type of game as a kid but had no idea how to make it. I tried to comment the source code and make it clear for somebody learning. Enjoy.Saturday, February 20, 2010 4:13 PM -
It's taken me 10 years, but I've finally done it!
SNAKEBITE - SBThe full program excluding images/sound: KTN094You can download the full game here: snakeBite.zipAn early concept version with vector graphics: VHG623
Very nice, Davey-Wavey.
Id: SNKBITE
Snake Bite is the sample of this week! Check it out at: http://blogs.msdn.com/smallbasic/archive/2010/02/22/sample-of-this-week-snake-bite.aspxMonday, February 22, 2010 8:39 AM -
Hi all, I´m introducing my greatest project, a GraphicStudio.
Here a screenshot from old version 2.1 (latest is 2.4)
http://sns.czweb.org/screenshots/SNS_GS_2.1_updates.png
Here code, but the program will not run without its components:
http://smallbasic.com/smallbasic.com/program/?PXL193
Here a webpage with a step by step description of the development and a download link (this will work properly) :
http://sns.czweb.org/gs
!! The website is in czech, but if u will be able to did not recognize what is the download link, you can use an automatic translator :-) or this link: http://sns.czweb.org/gs/sns_gs.zip
Very thanks to smallbasic, it helped me much, i am a 14-year-old small programer :-)
P.S.: Some bugs may appear, I will fix it in 2.4.1 and please sorry for my bad englishSaturday, February 27, 2010 10:14 PM -
Very nice Vittexikora,
I like the updates, help and colour transition.
This is the download zip needed as a link http://sns.czweb.org/gs/sns_gs.zip .Sunday, February 28, 2010 12:53 PM -
Snake Bite is the sample of this week! Check it out at: http://blogs.msdn.com/smallbasic/archive/2010/02/22/sample-of-this-week-snake-bite.aspx
Monday, March 1, 2010 1:36 AM -
http://smallbasic.com/program/?BXQ947 (Requires The FC Extension: http://tinyurl.com/ydze8u9)
Signature: Phillip MikesellTuesday, March 9, 2010 1:28 AM -
xsegs = 32 ysegs = 32 far = 1024 near = 0.1 radius = 3 '360 degrees pi2 = Math.Pi * 2 'Field of view f = 1.0 / Math.Tan(Math.Pi / 4) ' Calculate total number of segments to draw total = xsegs * ysegs / 2 'Specifies if line drawing has already started started = 0 'Old coordinates for line drawing (from) oldx = 0 oldy = 0 'Temporary variables for calculating x, y and z fx = 0 fy = 0 fz = 0 ' Draw vertical rings For i = 0 To total + xsegs ' Calculate current Y segment yseg = Math.Remainder(i, xsegs) ' Calculate curretn Y-axis slice xseg = Math.Floor(i / xsegs) ' Calculate angle for current vertex angle_x = pi2 * (xseg / (xsegs - 1)) angle_y = pi2 * (yseg / (ysegs - 1)) 'Calculate 3D vertex Calc3D() ' Draw 3D line DrawLine() ' Stop drawing when we have reached the end of the slice If(yseg = ysegs) Then started = 0 EndIf EndFor started = 0 ' Draw horizontal rings For i = 0 To total + ysegs ' Calculate current X segment xseg = Math.Remainder(i, ysegs) ' Calculate current X-axis slice yseg = Math.Floor(i / ysegs) 'Calculate angle angle_x = pi2 * (xseg / (xsegs - 1)) angle_y = pi2 * (yseg / (ysegs - 1)) 'Calculate 3D vertex Calc3D() 'Draw 3D line DrawLine() 'End drawing when we have reached the end of the slice If(xseg = xsegs - 1) Then started = 0 EndIf EndFor Sub Calc3D fx = (Math.Sin( angle_x ) * Math.Sin( angle_y )) * radius fy = (Math.Cos( angle_y )) * radius fz = (Math.Cos( angle_x ) * Math.Sin( angle_y )) * radius + 4 EndSub 'Draws a 3D line using x, y and z variables Sub DrawLine 'Calculate 3D projection x = fx * f y = fy * f z = fz * ((far + near)/(far-near)) + 1.0 w = (2*near*far)/(near-far) If w <> 0 Then x = x / z * w y = y / z * w z = z / z * w ' Move 2D screen coordinate to center for screen x = (x * GraphicsWindow.Width) / (2.0 * w) + (GraphicsWindow.Width / 2) y = (y * GraphicsWindow.Height) / (2.0 * w) + (GraphicsWindow.Height / 2) 'Only draw line, if we have at least calculated one earlier vertex If started <> 0 Then GraphicsWindow.DrawLine(oldx, oldy, x, y) Endif ' Drawing started started = 1 'Kepp old vertex position for next line oldx = x oldy = y EndIf EndSub
It's a little simple function which draws a wireframe 3D sphere.Tuesday, March 9, 2010 9:13 AM -
GeirGrusom,
Nice bit of work. You can publish the code for easy import (rather than posting the code in full) using the Publish button in the SmallBasic interface which gives an ID (Here is an ID for your code I published) - ZKQ163.
This can also be viewed on SilverLight web http://smallbasic.com/program/?ZKQ163 .Tuesday, March 9, 2010 11:02 PM -
Hi, Alien Chase is a game where you get lots of bangs for your code and may encourage and help new starters who want to make blob chaser games - RBT709
wow! nice!
i like the explison effect!
btw, its called "Laser" not "Lazer"...
also, why is the crosshair being controlled with the arrow keys? wouldn't it be better if you could aim with the mouse?
Live for nothing, OR CODE FOR SOMETHING!
Signature: Phillip MikesellWednesday, March 10, 2010 2:18 AM -
A 3D wireframe model: RTQ437
Very nice.
i hope someone finds it useful.. (optimized as good as i could..)
next step:
make it rotate-able around the X,Y and Z axis.
Live for nothing, OR CODE FOR SOMETHING!
Signature: Phillip MikesellWednesday, March 10, 2010 2:19 AM -
You have no momentum - the movement is just determined by the rope joint angle it is connected to and doesn't depend on its velocity.
Very nice, but runs like cra-p on my slow computer.
Think about a swinging rope, it will only swing back and forth like a pendulum if:
1] it is given a continuous driving force - that is someone keeps swinging it, OR
2] it has a weight on the end.
I don't think a rope with no weight on its end and held fixed at the top swings very well, and if it does it is all about the rope pivoting about its top like a single rigid bar (the swinging rope fixed at the top doesn't bend much along its length). In this case the physics is the balance of kinetic(velocity) and potential(gravity) energy, exactly like a pendulum in a clock.
Alternatively, while I was playing:
This (import DBV654) has a bit more physics, with acceleration, velocity and position calculated for each joint. The acceleration of an joint is just the sum of the forces applied by the two segments connected to the joint. The forces depend on the extension (elastic stretch) of the segment and its direction.
The model is a bit sensitive to the parameters set - it can be quite unstable and need shorter time-steps - this is due to explicitness of the method - a more implicit method (calculating everything in one set of matrix equations) would be more complex, but more stable. However it looks a bit like very elastic rope, perhaps like a bungee.
This looks OK because the elastic forces are stronger than the gravity induced swinging, that this model also doesn't capture correctly.
If you want to capture a swinging rope, read up a bit on pendulums which is quite simple for a rigid pendulum, but would be more complex for a segmented rope model.Wednesday, March 10, 2010 2:22 AM -
here's the unrealistic sideview version of the rope: NVH805
Very nice, but runs like cra-p on my slow computer.
i hope someone can give me a hint on how to make the rope swing..
Live for nothing, OR CODE FOR SOMETHING!
Signature: Phillip MikesellWednesday, March 10, 2010 2:27 AM -
here's my smoke editor code: PBH865
VERY NICE!
to use it just drag and drop the left mousebutton and a smoke emitter will be created. the lenght of the line created is equal to the smoke velocity. and the direction of the line represents the smoke emitting angle.
Live for nothing, OR CODE FOR SOMETHING!
Signature: Phillip MikesellWednesday, March 10, 2010 2:50 AM -
The main reason i made that program is to make it so when you press the first letter of the color it would equip that color.
Signature: Phillip MikesellWednesday, March 10, 2010 2:55 AM -
Hi Phillips101,
Well, I am planning on making a program that will control a turtle with th arrow keys, and it says OnKeyDown does not have left, right, up and down. How do I make OnKeyDown work with arrow keys?That's a good start on your way to mastering SmallBasic.Let me throw you a challenge... see if you can rewrite your colour changing section (OnKeyDown) using an array.Hint: check out array.containsindex ;-) and it should save you a lot of typing
Signature: Phillip MikesellWednesday, March 10, 2010 3:04 AM -
Here is the beggening of my paint progeam with fremy's extension.
Import~QGR352- Edited by The Hacker2 Wednesday, March 10, 2010 3:27 AM Added Paint
Wednesday, March 10, 2010 3:18 AM -
For the "Up Arrow" use "Up" Down use "Down" etc
But thats what I already tried.
Signature: Phillip MikesellWednesday, March 10, 2010 3:22 AM -
Wednesday, March 10, 2010 8:10 PM
-
Hi all, I´m introducing again my greatest project, a GraphicStudio.
Here code, but the program will not run without its components:
>> http://smallbasic.com/smallbasic.com/program/?PXL193
Here a webpage with a step by step description of the development and a download link (this will work properly) :
>> http://sns.czweb.org/gs
!! The website is in czech , but if u will be able to did not recognize what is the download link, you can use an automatic translator :-) or this link: > Download_link <.: SCREENSHOT :. (the graphic studio is a product of SINE Software - it is our own non-official software company - just a game...)
<big>
</big>
Now I have discovered fremy extension so I'm going to edit my strategic turn-based multiplayer game "Age of Dwarven Wars" :-)
It will now work properply so I will probably publish it, but I'm planning to add a possibility to play on-line, turns will be saved into file and then uploaded using FTP.Upload to my website. Will it work ? I'm afraid it will be too slow, P2P would be better.Thanks for SmallBasic, it helped me much and sorry for my bad english...
Tuesday, March 23, 2010 4:40 PM -
Wow Vittexikora, that is very impressive. I played with it and the animation player was very cool. Nice work!Wednesday, March 24, 2010 6:14 PM
-
Yeah, really thank you, but it´s not an animation player, but file loading ;-)
If you tried to edit any "image" in *.sgsf in folder /images by Notepad you will be able to see shapes, color, size and position where they are.
Well it will be better with fremy extension, but now I have no time...Now I will write the strategic game "Age of Dwarven Wars".
P.S.: Have you seen the code ? Have a look and find out how I solved the problem with buttons - theres no fremy extesion - the buttons are only rectangles with text, which will check a mouse over them on your click.
See the 1. and 3. Sub
and Sub GetBtnInfo (down)
and at the bottom of code is the number of lines....Wednesday, March 24, 2010 8:25 PM -
Wow Vittexikora That is an excellent program.
I made a minor change to the load subtoutine. (Sub Sbtn12Activity) I do not like to type file names. With my change to load a file you only have to type number and press ENTER instead of typing file name. I published the changed subroutine. It is SMD635
Thanks for the fun program.
Thursday, March 25, 2010 4:11 AM -
Thank you very much !
I should include this in next version, where I will use the fremy extension for better funcionality.
It will took some time. Maybe as u have seen, the code needs optimalization in some places.
Thursday, March 25, 2010 9:45 AM -
Keeping in tune with SmallBasic being a teaching language, Modify the routine where you read the data files to "Auto-create" a default version when the file is not there. That way users wouldn't need to download a zip file with the support files in order to run your program.
Bravo on the effort.
Saturday, March 27, 2010 8:51 PMAnswerer -
Good idea, thanks!Monday, March 29, 2010 6:08 AM
-
I have added a limeted .BMP fille saving to the mandelbrot program I submitter in the 25 line challenge. It needs an images folder in the same subdirectory as the program. This is not finished code as it does not check if an input is reasonable. It is just something I wanted to share with fellow programmers.
the import code is:KWQ126
I am just starting to learn Small BASIC. I find the challenge of learning Small BASIC to be fun. I found trying to learn Visual BASIC to be frustrating. I may not be smart enough for a grownup language but this is fun.
If anyone knows how to save a byte to a file with a value greater than 127? Text.GetCharacter(characterCode) and Text.GetCharacterCode(character) do not work for values greater that 127 if it has been written to a file.
thanks
Monday, March 29, 2010 9:03 PM -
Beardedboy,
The problem with 'standard' textfiles is that they is ASCII based, and only hold character codes between 1 and 127.
For the extended (full 256 characters and above) you would need a UTF-8 encoded text file I believe. I don't believe SmallBasic has a way of doing this, or of writing binary data to a file.
Monday, March 29, 2010 11:07 PM -
Beardedboy,
The problem with 'standard' textfiles is that they is ASCII based, and only hold character codes between 1 and 127.
For the extended (full 256 characters and above) you would need a UTF-8 encoded text file I believe. I don't believe SmallBasic has a way of doing this, or of writing binary data to a file.
EDIT: Actually, to correct myself, SmallBasic always writes UTF-8 textfiles, which is why codes above 127 wont work correctly in writing binary files.
- Edited by Davey-Wavey Wednesday, March 31, 2010 9:15 PM
Monday, March 29, 2010 11:07 PM -
Thanks Davey-Wavey
OK, I knew that it was a problem with the standard text file. I was just hoping someone knew of a way to save a full binary byte. I could encode the data into 7 bit packets and save a full color image. The problem with that is other programs would not be able to open the file. The .BMP save that I wrote is at least able to save a usable .BMP file. It is unfortunate that I can not yet save the full color pallet.
thanks
Monday, March 29, 2010 11:31 PM -
Vijaye,
Could we possibly split this forum again as it's getting a real pain to load all the replies. Thanks.
Monday, March 29, 2010 11:59 PM -
Hi all,
First time poster here. I am back to programming a bit for a hobby, for the first time in a long while. I am offering Beginning Programming as an enrichment course to my local elementary school (Grade 5) using Small Basic as a tool, and I figured I'd better shake some of the rust off and make sure I have a handle on how this language works.
Here is my first program that I've got to the point I'd like to share, a version of Connect Four: CHL704
It has a primitive AI (if I may dignify the computer's play by that turn) that looks ahead one turn to make its moves. Comments (of course) welcome. I am also attempting to post a screenshot of play in action, but I've never posted an image to a forum before, so I hope it works.
Best regards
Wednesday, March 31, 2010 4:02 AM -
Craig,
Nice game - only suggestion is to use PlayClickAndWait instead of PlayClick , since the latter can conflict if it is called again before the last click sound has finished playing - this can cause some funny squeaks or a crash.
Wednesday, March 31, 2010 7:09 PM -
Beardedboy, I was suprised you were able to make a binary file. To do bytes >127 though is going to be a real pain, check out the first table shown at http://en.wikipedia.org/wiki/UTF-8
This means (I think) that different numbers for your byte of interest > 127 are going to insert between 1 to 3 more bytes, a real mess, and I saw that in your test code above. I think you're stuck with 127, unless you're able to keep all bytes <=127 like you sneakily did. But you gave us a way to do bitmaps, nice! Maybe with alot more thought and luck, you can deal with the unicode limitation and get what you really want.
We'll you shook alot of rust off Zeven_Provincien, cool AI. I used to love playing this game.
Wednesday, March 31, 2010 8:37 PM -
Thank you bigdaddyo for the kind words. And thank you very much for the link. Until two weeks ago I had not done any programing in over 15 years. I did not know about UTF-8. Now at least I understand the reason the bytes are not what I had expected.
I think the friendly and helpful forum members are one of the best resources a Small BASIC programmer has.
Wednesday, March 31, 2010 11:43 PM -
Well Zeven_Provincien you have written a very nice program. At least that is my opinion. Thank you for sharing your work with us.Wednesday, March 31, 2010 11:53 PM
-
Litdev --
Thanks for having a look at the program. I adopted your suggestion and it does eliminate a strange squeaking sound that used to occur with the program at times.
However, it exposes something funny that I had noticed before but never figured out to my satisfaction: I tried to put a small program delay after the human move in order to give the player a chance to see what's going on -- the computer moves so fast after you finish your move it can be a bit confusing to figure out where the computer moved.
But as you can see from the extra small delay the playclickandwait command imparts to the program, the slot changes to cyan before changing to the player colour (purple or orange), the longer the delay the more evident the strange behaviour.
Cheers!
Thursday, April 1, 2010 12:59 AM -
Craig,
I see the effect and think it is due to the same issue as Vitexicora found in this thread:
The relevent bit is:
So, you need to set a flag from the event call, and use this flag to control the program from a Main Loop.
This is a recurring theme - do all the main work in the main program loop - and just use events to set control flag variables .
This is extended here to do not call subroutines that do any animation (work) directly from an event .
Basically, there are problems if you call graphics from within event subroutines - unfortunately there is no quick fix for your code.
The following is not completed, but shows how it might be approached - Import TWF273.
EDIT
bigdaddyo (re below -now on continuation tread), yes in general, but I try to use the event set flag (set to 1 say by the event) only in the top level While("True") .. EndWhile loop which is sequential and cannot be interrupted by events - and only reset the flag to 0 (allowing it to be changed by another event call) after it has been used. In summary a single flag will work if it is used and reset carefully. If these flags are used repeatedly in different places you may need more flags as you suggest to make sure that events don't change things as it is running, but this may not lead to the clearest code and I think should be avoided where possible.
Since the event call can only set the flag to 1 say, you can repeatedly use this flag (unchanged by any event calls) until you reset it to 0, once you have finished using it. Also, a short Program.Delay at the end of the main loop seems to give the events a little time.
- Edited by litdev Thursday, April 1, 2010 10:13 PM
Thursday, April 1, 2010 6:55 PM -
This is a program that plots the equation of a straight line y = mx + c where m = slope and c = x intercept
'cartesian co-ordinate system 'equation of a straight line 'the graph TextWindow.Title = "The Straight Line Equation" TextWindow.ForegroundColor = "Green" TextWindow.WriteLine("") TextWindow.Write("Enter the screen width: ") gw = TextWindow.Read() TextWindow.WriteLine("") TextWindow.Write("Enter the screen height: ") gh = TextWindow.Read() TextWindow.WriteLine("") TextWindow.WriteLine("y = mx + c") TextWindow.WriteLine("") TextWindow.Write("enter m/the slope: ") m = TextWindow.ReadNumber() TextWindow.WriteLine("") TextWindow.Write("enter the x-intercept: ") c = TextWindow.ReadNumber() TextWindow.Hide() 'constructing the graph GraphicsWindow.Width = gw GraphicsWindow.Height = gh GraphicsWindow.Top = 20 GraphicsWindow.Left = 200 GraphicsWindow.BrushColor = "Black" 'shift the (0,0) to the center of the window 'x' = x-half of window.width(because the x axis is shifted) 'y' = y+half of window.height(because the y axis is shifted + inverted) 'x axis GraphicsWindow.DrawText(0,gh/2-15,"x axis") GraphicsWindow.DrawLine(0,gh/2,gw,gh/2) 'y axis GraphicsWindow.DrawText(gw/2+1,gh-15,"y axis") GraphicsWindow.DrawLine(gw/2,0,gw/2,gh) GraphicsWindow.DrawText(gw/2+1,gh/2-15,"(0,0)") GraphicsWindow.PenColor = "Red" 'solve the equation and plot each individual point For x = -100 To 100 Step 10 'to "stretch" the graph so it doesn't look out of scale y = (m*x + c) 'the +10 step zooms the graph 'to find the actual co-ordinates in the graphicswindow x1 = x + gw/2 y1 = -(y - gh/2) 'the following condition is to prevent the line from (0,0) If (x >= -99) Then GraphicsWindow.DrawLine(x2,y2,x1,y1) EndIf x2 = x1 y2 = y1 EndFor 'to display the equation in standard format on screen f0 = Text.Append("y = ",m) f1 = Text.Append(f0,"x") f2 = Text.Append(f1,"+") f3 = Text.Append(f2,c) GraphicsWindow.DrawText(50,50,f3)
Saturday, July 10, 2010 5:58 AM -
Hey, came to submit a simple button-calculator (doesn't use arrays)
Import Code: VQP786
Hope you like it.
Airwaves
Monday, August 23, 2010 4:41 AM -
The calculator doesn't have an acurate remainder operation.Wednesday, September 15, 2010 2:57 AM
-
This is a weird turtle-thing. makes a cool picture, Import Code: DTX776
Tuesday, September 21, 2010 4:20 AM -
Another few, dtx776-0, dtx776-1,Thursday, September 23, 2010 6:36 AM