Converting QBasic Code to Blitz 3D
Blitz3D Forums/Blitz3D Programming/Converting QBasic Code to Blitz 3D
| ||
Hi, I was wondering how to convert an old QB program into B3D, because right now, B3D appears to be the form of the language of choice for me when it comes to BASIC. However, looking at programs in hindsight, I'd like to bring a program back to life, but trying to find equivalent code for B3D can be a nightmare. Here's the old QB code below: SCREEN 12 CLS RANDOMIZE TIMER FOR dots = 1 TO 2000 colr = INT(RND*16) col = INT(RND*480) row = INT(RND*640) PSET (col, row), colr NEXT dots FOR cnt = 1 to 60 centerCol = INT(RND*639) + 1 centerRow = INT(RND*479) + 1 radius = INT(RND*100) + 1 CIRCLE (centerCol, centerRow), radius NEXT cnt COLOR 12 LOCATE 12, 34 PRINT "Space FX v1.0" LOCATE 13, 28 PRINT "(c)2005, Robert A. Morin" FOR i = 1 TO 35 freq = INT(RND*2700) + 500 dur = INT(RND*3) + 1 SOUND freq, dur NEXT i FOR freq = 800 to 400 STEP -7 SOUND freq, 1 SOUND 900 - freq, 1 NEXT freq COLOR 10 LOCATE 25, 1 INPUT "Press <ENTER> to Quit Demo: ", ent$ END I was wondering how to convert this into the Blitz 3D environment, since I know that QBasic's code structure is far different, since QB was DOS-based, and used the PC Speaker, which Windows doesn't do, obviously, and this code is well over 10 years old. |
| ||
C'mon Bob. Surely you can convert this code yourself - it's very basic (ho-ho). :) If you're new to blitz then converting it would be a good exercise. You'll have to load a sound effect in place of the old SOUND command, of course. |
| ||
Here's a start:Graphics 640, 480 Cls Dim colors(16,2) For iter = 1 To 16 For byte = 0 To 2 Read colors(iter, byte) Next Next SeedRnd MilliSecs() For dots = 1 To 2000 colr = Rnd(16) col = Rnd(480) row = Rnd(640) Color colors(colr,0), colors(colr,1), colors(colr,2) Plot row, col Next For cnt = 1 To 60 centerCol = Rnd(639) + 1 centerRow = Rnd(479) + 1 radius = Rnd(100) + 1 CIRCLE (centerCol, centerRow, radius) Next Color colors(12,0), colors(12,1), colors(12,2) Locate 12*8, 34*8 Print "Space FX v1.0" Locate 13*8, 28*8 Print "(c)2005, Robert A. Morin" ;For i = 1 To 35 ; freq = Int(Rnd*2700) + 500 ; dur = Int(Rnd*3) + 1 ; SOUND freq, dur ;Next ;For freq = 800 To 400 Step -7 ; SOUND freq, 1 ; SOUND 900 - freq, 1 ;Next Color colors(10,0), colors(10,1), colors(10,2) Locate 25*8, 1*8 ent$ = Input("Press <ENTER> to Quit Demo: ") End ;CIRCLE COMMAND Function CIRCLE(xCenter, yCenter, rad) x = 0 y = rad Plot xCenter + x, yCenter + y Plot xCenter - x, yCenter + y Plot xCenter + x, yCenter - y Plot xCenter - x, yCenter - y Plot xCenter + y, yCenter + x Plot xCenter - y, yCenter + x Plot xCenter + y, yCenter - x Plot xCenter - y, yCenter - x p = 1 - rad While x < y If p < 0 x = x + 1 Else x = x + 1 y = y - 1 EndIf If p < 0 p = p + (x Shl 1) + 1 Else p = p + ((x - y) Shl 1) + 1 EndIf Plot xCenter + x, yCenter + y Plot xCenter - x, yCenter + y Plot xCenter + x, yCenter - y Plot xCenter - x, yCenter - y Plot xCenter + y, yCenter + x Plot xCenter - y, yCenter + x Plot xCenter + y, yCenter - x Plot xCenter - y, yCenter - x Wend End Function ;color data Data 0,0,0 ;black Data 0,0,255 ;blue Data 0,255,0 ;green Data 0,255,255 ;cyan Data 255,0,0 ;red Data 255,0,255 ;magenta Data 128,64,0 ;brown Data 192,192,192;white Data 128,128,128;gray Data 128,128,255;light blue Data 128,255,128;light green Data 128,255,255;light cyan Data 255,128,128;light red Data 255,128,255;light magenta Data 255,255,0 ;yellow Data 255,255,255;intense white |
| ||
What the??? There is an Oval command to draw circles, Wolron. Why over-complicate things? |
| ||
Ah yes, the elusive Oval command. Forgot about that one. Can't say I've used it recently... Works all the same... Updated to satisfy BIG10p: Graphics 640, 480 Cls Dim colors(16,2) For iter = 1 To 16 For byte = 0 To 2 Read colors(iter, byte) Next Next SeedRnd MilliSecs() For dots = 1 To 2000 colr = Rnd(16) col = Rnd(480) row = Rnd(640) Color colors(colr,0), colors(colr,1), colors(colr,2) Plot row, col Next For cnt = 1 To 60 centerCol = Rnd(639) + 1 centerRow = Rnd(479) + 1 radius = Rnd(100) + 1 Oval centerCol-radius, centerRow-radius, radius*2, radius*2, 0 Next Color colors(12,0), colors(12,1), colors(12,2) Locate 12*8, 34*8 Print "Space FX v1.0" Locate 13*8, 28*8 Print "(c)2005, Robert A. Morin" ;For i = 1 To 35 ; freq = Int(Rnd*2700) + 500 ; dur = Int(Rnd*3) + 1 ; SOUND freq, dur ;Next ;For freq = 800 To 400 Step -7 ; SOUND freq, 1 ; SOUND 900 - freq, 1 ;Next Color colors(10,0), colors(10,1), colors(10,2) Locate 25*8, 1*8 ent$ = Input("Press <ENTER> to Quit Demo: ") End ;color data Data 0,0,0 ;black Data 0,0,255 ;blue Data 0,255,0 ;green Data 0,255,255 ;cyan Data 255,0,0 ;red Data 255,0,255 ;magenta Data 128,64,0 ;brown Data 192,192,192;white Data 128,128,128;gray Data 128,128,255;light blue Data 128,255,128;light green Data 128,255,255;light cyan Data 255,128,128;light red Data 255,128,255;light magenta Data 255,255,0 ;yellow Data 255,255,255;intense white |
| ||
Except now your circles aren't centered about the x and y coordinates ;) |
| ||
Corrected the above code so that they are. Geez, I try to be helpful, and just keep getting critiqued... |
| ||
Sorry WolRon. I didn't mean to sound so critical. I should have used a smilie... and not posted after consuming alcohol. :P |
| ||
I was just extracting the urine ;) |