B4i: First B4i app in Apple App Store

First B4i App in the store!
Breaking News! Erel has put up the first B4i app on the Apple App Store. I have a feeling we won’t have to wait much longer until we can build iOS apps in this wonderful tool.

While Xojo keeps saying ‘it’s ready when it’s ready’ (it’s getting old Xojo…), B4i is going to take the world by storm! Tools by Anywhere Software have proven to be very stable and production ready by its first releases, so you better start thinking what your first app written in B4i will be like. I know I am…

You can download the app from the store here.

Realy looking forward for this one! I may even buy my first iPhone just to be able to play with it #ChuckleByMyFriends

Updates follow…


Xojo: Nintendo Game & Watch Mario Bros

Mario Bros in Xojo Box
Last weekend I found back my old Nintendo Game & Watch game Mario Bros under some dust. I remember having a good time with this old game console. So why not rebuild it in Xojo?

I found some graphics and sounds on the internet and started rebuilding the game. A couple of evenings later, here it is!

I’m not 100% sure the gameplay is exactly the same as on the real console as the original source code is not released by Nintendo, but I think I’m close. Check out the video:

Use the mouse to:
1. start the games (Game A, Game B).
2. run a demo play (Time)
3. navigate Mario and Luigi up/down

Use the keyboard keys to:
1. ESC to close the game
2. D to move Luigi Up, C to move Luigi down
3. Upkey to move Mario Up, DownKey to move Mario Down.

Note: if you have problems moving Luigi (make sure caps lock is ON), or change the code in the canGame canvas KeyDown event to:

 select case asc(key)
    case 30 ' keyUp
    case 31 ' keydown
    case 68, 100  'd, D
    case 67, 99 ' c, C
    end select

Thanks to Alwyn for pointing this out!

You can download the full source here.
And the binaries (Windows & OSX) here.

Bye for now,


Xojo: The Xharity initiative



Last week Richard Summers launched the idea on the Xojo forums to start a community project for charity.

Here is his post:

Hi everyone.

A few months ago, I came across the idea of Xojo community members collaborating on a community project.
Anyone could contribute (new members to Xojo included), and the resulting project could be sold and the money given to a yet to be determined charity.

This would serve 3 purposes:

1) Raise money for a charity such as one for terminally ill children.

2) Be excellent advertising for Xojo and it’s unparalelled community.

3) Create a great sense of community for new members, and allow them to integrate with regular members.

I appreciate that many developers here are busy, but I am sure we could all donate 30 minutes here and there, in order to make whatever time the children have left – a pleasurable one!

The more members which work on the project – the less time we will each need to work on it.

If anyone is interested, please reply to this thread (as opposed to creating another thread – thus making it difficult to communicate).
The first stage would be on deciding a project / app to create. I would imagine a game would be a good seller?

Hope others are interested.

Thank you for your consideration.

Alwaysbusy’s Corner is of course joining this initiative! Already great ideas are flowing around and I feel some excellent new frameworks will come out of this that will benefit all Xojo users. Being able to work with some driven Xojo programmers who are doing this for a good cause is a big plus!

If you want to get involved, go to the Xharity forum and join us!



Xojo: Comanche 3D in about 100 lines UPDATE

Tomas made HUD and Maps active!

Tomas made HUD and Maps active!

A quick update with a much smoother and faster version of the ABComanche article. This one is using some tricks out of the ABXVision framework using Memoryblocks and pointers. (Don’t worry, sound worse than it is).

You can download this new version here

I’ve been amazed how many people enjoyed playing with this! Some of you made great additions like the HUD display, camera views and added sound. Thanks Tomas Jakobs for this! Will Shank even made a OpenGL viewer for the maps. It’s not using the voxel engine discribed in the previous article but it looks great!

Will Shanks OpenGL version!

Will Shanks OpenGL version!

Check out the Xojo forum post for their creations!



Xojo: Building Comanche 3D in 100 lines

Comanche: Maximum Overkill

Comanche: Maximum Overkill

If you are a child of the 90s, you certainly will remember Comanche: Maximum Overkill. The graphics were awesome and way ahead of its time. Remember, we did’t have fancy 3D accelerated graph cards. They used a technique called voxel space. Using only a picture containing the colors and another one with the depths they displayed wonderful landscapes on your screen. With your Comanche chopper you could fly over this landscape, diving towards the enemy. It was fun! I’ve must have spend hundreds of hours playing with this.

It is surprising how little code is needed to reproduce this experience. In this article, we’ll build the 3D world and will be able to fly, dive etc over the landscape with Xojo in less than 100 lines of code! The code is based on the work of Sebastian Macke.

First some background on the algorithm. Voxel Space is very similar to raycasting (the technique used in games like *Wolfenstein 3D, the old one). The algorithm draws simply perspectively correctly vertical lines by shooting a ray from the camera into the map. This image illustrates this:

Voxel Space Raytracing

Voxel Space Raytracing

*Note: I first had Doom also listed but thedeemon at Reddit pointed out Doom uses another algorithm, BSP trees (binary space partition).

The algorithm goes like this:
1. For every column of the screen define a light ray which starts at the camera and ends at the horizon somewhere far away.
2. Divide the ray into very small segments so that every pixel lying on the map is considered.
3. Load the height and color from the 2D maps corresponding to the position on the ray.
4. Do some clever perspective corrections for the height coordinate. This is the hard part of the algorithm but it uses some easy math.
5. Draw a vertical line with the corresponding color with the height retrieved from the perspective correction.

So we need two pictures to do this. One containing the colors and one with the depth levels (0 – 255). The original Comanche game used 1024×1024 pictures, so that’s what we are going to do. Here is an example of both maps:

Example color and depth maps

Example color and depth maps

Ok, let’s do some code! This is what we’re going to build:

Example screen of what we will build

Example screen of what we will build

In the Open event we initialize some pictures

Sub Open()
  ' initialize the buffers
  mBuffer = new Picture(1024,768,32)
  mBuildBuffer = new Picture(VoxWidth, VoxHeight, 32)
  mBuildBufferRGB = mBuildBuffer.RGBSurface
  ' create the chopper picture with the transparent areas
  Chopper = new Picture(1024,768,32)
  Chopper.Graphics.DrawPicture Comanche,0,0
  Chopper.Mask.Graphics.DrawPicture ComancheMask,0,0
  ' load a map
  CurrentMap = 1
End Sub

LoadMap is just a simple method to load the maps and reinitialize our start position:

Sub LoadMap(MapID as integer)
  dim x,y as Integer
  'Initialize the position and the lookup/lookdown vars
  xp = 512
  yp = 800
  hp = -50
  vp = -100
  ' prebuild the tables holding the pixel data of the map and depthmap to speed things up
  select case MapID
  case 1
    VoxelMapRGB = C1W.RGBSurface
    for y = 0 to 1023
      for x = 0 to 1023
        VoxelHeight(y,x) = C1D.RGBSurface.Pixel(y,x).Red
  case 2
    VoxelMapRGB = C2W.RGBSurface
    for y = 0 to 1023
      for x = 0 to 1023
        VoxelHeight(y,x) = C2D.RGBSurface.Pixel(y,x).Red
  case 3
    VoxelMapRGB = C3W.RGBSurface
    for y = 0 to 1023
      for x = 0 to 1023
        VoxelHeight(y,x) = C3D.RGBSurface.Pixel(y,x).Red
  case 4
    VoxelMapRGB = C4W.RGBSurface
    for y = 0 to 1023
      for x = 0 to 1023
        VoxelHeight(y,x) = C4D.RGBSurface.Pixel(y,x).Red
  end select
  ' Draw!
End Sub

Now, we just have to make our algorithm. The Update function will go over every vertical line and calculate what needs to be drawn to mimic the 3D view.

Sub Update()
  dim i as Integer
  dim x3d, y3d, rotx, roty as Double
  ' draw the sky first on the end picture
  mBuildBuffer.Graphics.DrawPicture Sky,0,0
  y3d = -VoxDepth
  ' update the view. Calculate the rotation and raycast every line
  while i < VoxWidth
    x3d = (i - VoxWidth / 2) * 1.5
    rotx =cos(angle) * x3d + sin(angle) * y3d
    roty = -sin(angle) * x3d + cos(angle) * y3d
    raycast(i, xp, yp, rotx + xp, roty + yp, y3d / sqrt(x3d * x3d + y3d * y3d))
    i = i + 1
  ' draw the result on the end picture
  mBuffer.Graphics.DrawPicture mBuildBuffer, 0,0, 1024, 512, 0,0,512,256
  ' draw the chopper overlay
  mBuffer.Graphics.DrawPicture Chopper,0,0
  ' refresh the canvas
End Sub

And our Raycast method that will build the result:

Sub Raycast(line as integer, x1 as double, y1 as double, x2 as double, y2 as double, d as double)
  ' The magic! Raycast on the current line. 
  ' line: vertical line to compute
  ' x1, y1: initial points on map for ray
  ' x2, y2: final points on map for ray
  ' d: correction parameter for the perspective
  dim dx,dy as Double
  dx = x2 - x1
  dy = y2 - y1
  dim r as Double = sqrt(dx * dx + dy * dy)
  dx = dx / r
  dy = dy / r
  dim yMin as Integer = 256
  dim i,k as Integer
  dim h as Integer
  dim ci as Color
  dim y3 as Double
  dim z3 as Integer
  while i < r-20
    i = i + 1
    x1 = x1 + dx
    y1 = y1 + dy
    if x1 > 0 and y1 > 0 and x1 < 1024 and y1 < 1024 then
      ' get the height
      h = VoxelHeight(x1, y1)
      ' get the color
      ci = VoxelMapRGB.Pixel(x1, y1)
      ' calculate the ray depth. Do some perspective correction for the height.
      h = 256 - h
      h = h - 128 + hp
      y3 = abs(d) * i
      z3 = h / y3 * 100 - vp
      if (z3 < 0) then z3 = 0
      if (z3 < voxHeight) then
        k = z3
        While k < ymin
          ' draw a vertical line with the corresponding color with the height retrieved from the perspective correction
          mBuildBufferRGB.Pixel(line, k) = ci
          k = k + 1
      end if
      if (ymin > z3) then
         ymin = z3
      end if
    end if
End Sub

Finally the key handeling on the Canvas:

Sub KeyDown(Key as String) as Boolean
    elect case key
  case "4" ' left
    angle = angle + 0.1
  case "6" ' right
    angle = angle - 0.1
  case "8" ' forward
    xp = xp - 2.0 * sin(angle)
    yp = yp - 2.0 * cos(angle)
  case "2" ' backward
    xp = xp + 2.0 * sin(angle)
    yp = yp + 2.0 * cos(angle)
  case "7" ' up
    hp = hp + 2
  case "1" ' down
    hp = hp - 2
  case "9" ' look up
    vp = vp + 2
  case "3" ' look down
    vp = vp - 2
  case "m", "M" ' cycle through the maps
    CurrentMap = CurrentMap + 1
    if CurrentMap = 5 then CurrentMap = 1
    Return true
  end select
  ' update with the new params
  Return true
End Sub

Note: Alwyn Bester noticed some problems with the key navigation and did this to fix it:

…Just a quick one, not sure if it’s a focus thing on Windows, but I had to move the KeyDown code from the Canvas event to the keydown event of the Form, for the navigation to work…

Done! Here is a video demonstrating what we just build with 100 lines of Xojo code:

Are Voxel engines a thing of the past? I don’t think so. As a matter of fact they are very hot nowadays. Being able to use 3D acceleration is producing some interesting engines like VoxelFarm and Atomontage. Check this last one out if you are interested in such engines.

Note: This is the original version of this article. There is a newer faster version in this article UPDATE

You can download the source code here.
Or the binaries here if you do not have Xojo.

The keys to play with it are:

Use the KeyPad!

Use the KeyPad!

Note: “M” to cycle through the maps!

See ya!


Xojo: THE Canvas reference book

Program the Canvas Control with Xojo Desktop

Program the Canvas Control with Xojo Desktop

I Wish I Knew How To… Program the Canvas Control with Xojo Desktop is the latest book of Eugene Dakin in his excellent I Wish I Knew How To… series.

If you ever wondered how stuff is done with the canvas control in Xojo, this is the book you need to have on your virtual shelf. In his well known swift (no pun intended) style, Eugene has written the reference manual for you. Alwaysbusy’s Corner did some humble contributions to the more advanced topics.

For the novice Xojo user, you quickly can get started and learn about the basics of graphics. Step by step you learn more and more when you move through the more advanced topics. This 400 page volume covers a lot of interesting chapters and includes a lot of useful examples with source code:

Topics included in the book:

Chart Fundamentals
2D Objects
Gaussian Blur
Building basic controls
and there are two games with step-by-step code explanations to help you build your own.

So head over to Eugene’s Personal Website and get your copy. Also check out his other books in the series on topics like SQLite, XML, PostgreSQL, Office etc…

Xojo: ABThinkGear – Mind Reading with the computer

Using the MindWave in Xojo

Using the MindWave in Xojo

Use the force Luke… In Xojo! ABThinkGear is a wrapper around the ThinkGear engine to use the NeuroSky Mindwave device in Xojo. The wrapper is Windows only.

The MindWave is a cheap mind reader device ($79.99) you can buy online e.g. here. It can do some very basic mind wave readings, so don’t expect it to recognize thoughts or so.

– Raw signal
– Neuroscience defined EEG power spectrum (Alpha, Beta, etc.)
– eSense meter for Attention
– eSense meter for Meditation
– eSense Blink Detection
– On-head detection

But still, it’s a fun little thing to play with!

As always, I tried to build an easy to use framework. Here is the structure:
The actual wrapper around the DLL.
A class containing all the data of one reading (Attention, Meditation, Blinkstrenght, Alpha, Beta, etc…)
A thread that polls the data from the device. The data of a MindWave device is only updated once a second, so the poll happens also only once every second. This is the class you’ll use in Xojo the most.

Some code on the use of the framework:

First we need to initialize the MindWave:

  if not MyThinkGear.Connect("COM9", BAUD_57600, true) then
    MsgBox "Could not connect to headset!"
     ' enable the blink detection
    dim ret as boolean = MyThinkGear.EnableBlinkDetection(true)
  end if

The ABThinkGear class has only one event:

ThinkGearChanged(State as ABThinkGearState)

In this event you receive a State containing all the data of the last reading. It is then up to you to do something useful with this data. In the attached demo, I displayed the incoming data.

Mindwave incoming data display in Xojo

Mindwave incoming data display in Xojo

You get quite a bit of info (although not that accurate as it only uses one sensor):

Properties of the ABThinkGearState class

Properties of the ABThinkGearState class

But you can for example start interpreting the data. e.g. if the Attention level is above 80 (in a range of 0 to 100) you could consider performing a certain action.

A couple of days ago, a project using Google Glass was shown doing exactly that. When the attention level reaches a certain point, they take a picture with Glass. On the next attention peak, they post it to twitter. But this can be done now also with Xojo! (take a picture with the webcam, send it to some social media site using the RESt api, et voila!

Here is a video of the Glass project:

The source code of the framework and Demo can be downloaded from http://gorgeousapps.com/ABThinkGear.zip

This framework will be part of the ABXVision framework later.

Cogito ergo sum

“I think, therefore I am”

Happy programming!



Get every new post delivered to your Inbox.

Join 419 other followers

%d bloggers like this: