QBasic conversion

Hi,
I’m currently converting an old QBasic listing to Xojo. It is about generating a Fractal set. The Xojo code produces some vague pixel formations which is definitely wrong. In the original code the following statements are used:

Screen 12 : CLS: Randomize 11
Window (-3.5,-2.1) - (2.1,2.1)

‘Screen 12’ switches to VGA (640*480). The ‘window’ statement defines a new set of coordinates I need to convert somewhere but unclear for me how? This is the Xojo code:

Var somePicture As New Picture(Canvas1.Width,Canvas1.Height)
Var surf As RGBSurface = somePicture.RGBSurface

Var A As Double = 0.65
Var B As Double = 0.65
Var C As Double = 0.1
Var D As Double = -0.1

Var F1 As Double = Sqrt(A*A+B*B)
Var F2 As Double = Sqrt(C*C+D*D)
Var Q As Double = F1/(F1+F2)
Var X1 As Double
Var Y1 As Double

Var X As Integer = 1
Var Y As Integer = 0
Var K As Integer = 0

Var R As Double

For K = 0 To 20000
  R = Rnd()
  If R < Q Then
    X1 = A*X-B*Y-1+A
    Y1 = B*X+A*Y+B
  Else
    X1 = C*X-D*Y+1-C
    Y1 = D*X+C*Y-D
  End If
  
  X=X1
  Y=Y1
  Surf.Pixel(X,Y) = &c0080FF00
  
Next
g.DrawPicture(somePicture, 0, 0)

20 000 random points
Var rr As New random
For K = 0 To 20000

X = rr.InRange(0,640)
Y= rr.InRange(0,480)
Surf.Pixel(x,Y) = &c0080FF00

Next

Thanks, but no, this is not a solution.

It is strange that you don’t have references to Canvas1.Width and Canvas1.Height when you calculate X and Y.

The reference to Canvas1 is in the original code.

The Window command in QBASIC maps the viewport coordinates; in your case the upper-left becomes -3.5,-2.1, and the lower-right is 2.1,2.1. Your RGBsurface is 0,0 (upper-left) to Canvas1.width, canvas1.height. To transform, map from the QBASIC coordinates to the RGBSurface coordinates:

X = Canvas1.width * (X1+3.5) / 5.6
Y = Canvas1.height * (Y1+2.1) / 4.2

Untested browser code…

Yes, I see. But I doesn’t work. The values of X and Y (before mapping) are sometimes way too high. Must be something else wrong. Thanks anyway.

That suggests that the original scaling was too small – just adjust accordingly. Or, better, make the scaling dynamic.

I added the 2 values and got a very good result

X=X1+400
Y=Y1-200
Surf.Pixel(X,Y) = &c0080FF00

Will try that. Thanks!

This is it! Thanks, works great!