Flaming Thunder
Examples 
Yin Yang, by Stijn Hertelé
 
         
Field Flow, by David Parker

Hello world!

Write "Hello world!".


Mad libs

Instead of buying publishers' mad libs for an English class, students can create their own.

Write "Please enter an animal: ".
Read animal.
Write "Please enter a color: ".
Read color.
Write "The ", animal, " ate my ", color, " shoes.".

You can write Flaming Thunder programs in paragraph form if you'd like:

Write "Please enter an animal: ". Read animal. Write
"Please enter a color: ". Read color. Write "The ",
animal, " ate my ", color, " shoes.".


See all the digits of 69!

Most calculators can display only the first 8 or 10 digits of 69!. Here is how to display all of them.

Write 69!.


Calculating factorials

Flaming Thunder has factorials built-in but you can calculate them yourself if you'd like. Here is how to calculate 1000! and check your answer against Flaming Thunder.

Set myfactorial to 1.
For i from 2 to 1000 do set myfactorial to i*myfactorial.
If myfactorial = 1000! then write "Flaming Thunder got it right!"
                       else write "Flaming Thunder got it wrong!".


Seive of Eratosthenes

The Seive of Eratosthenes is an ancient method used to find prime numbers. This particular example lets you set the trial prime to start searching at, and then it prints all the primes from the trial prime on up.

# Write the prime numbers starting at TrialPrime,
# which you can initialize to any odd integer
# greater than or equal to 5.

  Set TrialPrime to 10_000_000_001.

StartTestingTrialPrime:
  Set TrialDivisor to 3.

TryNextDivisor:
  If TrialDivisor divides TrialPrime then go to NextTrialPrime.
  Set TrialDivisor to TrialDivisor + 2.
  If TrialDivisor^2 < TrialPrime then go to TryNextDivisor.

  Write TrialPrime, " ".

NextTrialPrime:
  Set TrialPrime to TrialPrime + 2.
  Go to StartTestingTrialPrime.


A "Hello world!" CGI script

CGI (Common Gateway Interface) scripts are the programs that power many web sites. Programming CGI scripts in other languages can be difficult, but in Flaming Thunder they're easy. Here is a simple CGI script that writes "Hello world!":

Write "Content-type: text/html", CarriageReturn, Linefeed.
Write CarriageReturn, Linefeed.
Write "Hello world!".

The first two lines are required by HTTP (HyperText Transfer Protocol). The first line is a header informing the browser that the data should be treated like HTML (HyperText Markup Language) and displayed by the browser. The second line separates the header from the data.

This is an example of the power of Flaming Thunder's ability to cross-compile (create a program for a different machine than the one you are using). Many servers run Linux, but most users have a Mac or Windows machine. You can compile the CGI script on a Mac or Windows machine using the command:

ft file helloworldcgi.ft output helloworld.cgi target linux32

Flaming Thunder will create a Linux program called helloworld.cgi that you can FTP up to your server.

In fact, that's just what we've done. Click here to run helloworld.cgi from our server.



IP address CGI script

On the internet, your IP (Internet Protocol) address is similar to your street address. It is a number that identifies your internet connection. If you have ever visited a website that seemed to magically know what city you lived in, it is because your IP address can often be used to retrieve information about your approximate geographical location.

Here is a small Flaming Thunder CGI script that retrieves a website visitor's IP address:

Write "Content-type: text/html", CarriageReturn, Linefeed.
Write CarriageReturn, Linefeed.
Write "Your IP address is ",
      GetEnvironmentVariableValue("REMOTE_ADDR"),
       ".".

You can compile it using the command:

ft file ipaddress.ft output ipaddress.cgi target linux32

Flaming Thunder will create a Linux program called ipaddress.cgi that you can FTP up to your server.

Click here to run ipaddress.cgi from our server.



All environment variables CGI script

The previous CGI script examples were formatted without using any HTML markup. To display all of the environment variables, it will be more convenient to format them as an HTML table.

Write "Content-type: text/html", CarriageReturn, Linefeed.
Write CarriageReturn, Linefeed.
Write "<html><body><table cellspacing=0 cellpadding=0 border=1>".
For i from 1 to GetEnvironmentVariableCount() do
  write "<tr><td>",
        GetEnvironmentVariableName(i),
        "</td><td>",
        GetEnvironmentVariableValue(i),
        "</td></tr>".
Write "</table></body></html>".

You can compile it using the command:

ft file allvariables.ft output allvariables.cgi target linux32

Flaming Thunder will create a Linux program called allvariables.cgi that you can FTP up to your server.

Click here to run allvariables.cgi from our server.



Greenwich Mean Time CGI script

To internally timestamp most operations, the internet uses Greenwich Mean Time (also sometimes referred to as coordinated universal time, or temps universel coordonné, or abbreviated as UTC in a compromise between English and French because the abbreviation matches neither of them). Here's a Flaming Thunder CGI script that displays the current Greenwich Mean Time.

Write "Content-type: text/html", CarriageReturn, Linefeed,
      CarriageReturn, Linefeed,
      GetGreenwichMeanTime().

Notice how we did something a little different this time and combined all of the write statements into one multi-line write statement.

You can compile the CGI script using the command:

ft file greenwichmeantime.ft output greenwichmeantime.cgi target linux32

Flaming Thunder will create a Linux program called greenwichmeantime.cgi that you can FTP up to your server.

Click here to run greenwichmeantime.cgi from our server.



Say hello CGI script

One of the main purposes of CGI scripting is to get input from the user and then do something with it. This example has two parts: the HTML for a webpage that gets input from the user, and the Flaming Thunder CGI program that does something with the input.

First, here is the HTML for a webpage that asks a user for their first name:

<html>
<body>
<form action="/cgi/sayhello.cgi">
<input type=text name="first name" width=10>
<input type=submit name=submit
       value="Enter your first name, then press here">
</form>
</html>
</body>

Second, here is a Flaming Thunder program to read the value of the "first name" CGI variable and say hello to the user:

Write "Content-type: text/html", CarriageReturn, Linefeed,
      CarriageReturn, Linefeed,
      "<html><body>",
      "Hello ", GetDecodedCGIVariableValue("first name"), "!",
      "</html></body>".

Click here to access sayhello.html on our server.



Small red 3D triangle

Here is a simple example of Flaming Thunder's 3D graphics. This program draws a small red 3d triangle that you can walk around.

To exit from the program, press the ESC key.

To walk, use the W, A, S, and D keys. W is forward, S is backward, A is left, and D is right. Or, you can use the arrow keys.

To look around, use your mouse.

BeginFullScreen.
Repeat
  (
  BeginFrame.
  SetFrameBackgroundRGB 0,0,0.
  Draw3DTriangleXYZ3RGB -1,0,0, 1,0,0, 0,0,2, 1,0,0.
  EndFrame.
  DrawFrame.
  )
until RequestedToStop.
EndFullScreen.

Click here to download or run the Windows version.



Blue 3D cube

BeginFullScreen.
Repeat
  (
  BeginFrame.
  SetFrameBackgroundRGB 0,0,0.
  Draw3DQuadrilateralXYZ4RGB -1,-1,0,  1,-1,0,  1,-1,2, -1,-1,2, 0,0.9,1.
  Draw3DQuadrilateralXYZ4RGB -1, 1,0, -1,-1,0, -1,-1,2, -1, 1,2, 0,0.9,1.
  Draw3DQuadrilateralXYZ4RGB  1, 1,0, -1, 1,0, -1, 1,2,  1, 1,2, 0,0.9,1.
  Draw3DQuadrilateralXYZ4RGB  1,-1,0,  1, 1,0,  1, 1,2,  1,-1,2, 0,0.9,1.
  Draw3DQuadrilateralXYZ4RGB -1,-1,2,  1,-1,2,  1, 1,2, -1, 1,2, 0,0.9,1.
  Draw3DQuadrilateralXYZ4RGB -1, 1,0,  1, 1,0,  1,-1,0, -1,-1,0, 0,0.9,1.
  EndFrame.
  DrawFrame.
  )
until RequestedToStop.
EndFullScreen.

Click here to download or run the Windows version.



Green rotating 3D cube

BeginFullScreen.
Set Angle to 0.0.
Set AngleIncrement to 0.03.
Repeat
  (
  BeginFrame.
  SetFrameBackgroundRGB 0,0,0.
  Set CosAngle to Cos(Angle).
  Set SinAngle to Sin(Angle).
  Set MinusMinus to -CosAngle-SinAngle.
  Set MinusPlus  to -CosAngle+SinAngle.
  Set PlusMinus  to +CosAngle-SinAngle.
  Set PlusPlus   to +CosAngle+SinAngle.
  Draw3DQuadrilateralXYZ4RGB MinusMinus,PlusMinus ,0,
                             PlusMinus ,PlusPlus  ,0,
                             PlusPlus  ,MinusPlus ,0,
                             MinusPlus ,MinusMinus,0,
                             0,1,0.
  Draw3DQuadrilateralXYZ4RGB MinusPlus ,MinusMinus,0,
                             PlusPlus  ,MinusPlus ,0,
                             PlusPlus  ,MinusPlus ,2,
                             MinusPlus ,MinusMinus,2,
                             0,1,0.
  Draw3DQuadrilateralXYZ4RGB MinusMinus,PlusMinus ,0,
                             MinusPlus ,MinusMinus,0,
                             MinusPlus ,MinusMinus,2,
                             MinusMinus,PlusMinus ,2,
                             0,1,0.
  Draw3DQuadrilateralXYZ4RGB PlusMinus ,PlusPlus  ,0,
                             MinusMinus,PlusMinus ,0,
                             MinusMinus,PlusMinus ,2,
                             PlusMinus ,PlusPlus  ,2,
                             0,1,0.
  Draw3DQuadrilateralXYZ4RGB PlusPlus  ,MinusPlus ,0,
                             PlusMinus ,PlusPlus  ,0,
                             PlusMinus ,PlusPlus  ,2,
                             PlusPlus  ,MinusPlus ,2,
                             0,1,0.
  Draw3DQuadrilateralXYZ4RGB MinusPlus ,MinusMinus,2,
                             PlusPlus  ,MinusPlus ,2,
                             PlusMinus ,PlusPlus  ,2,
                             MinusMinus,PlusMinus ,2,
                             0,1,0.
  Set Angle to Angle + AngleIncrement.
  EndFrame.
  DrawFrame.
  )
until RequestedToStop.
EndFullScreen.

Click here to download or run the Windows version.



Golden rotating 3D cube on a tiled floor

Golden rotating 3D cube on a tiled floor  
  
BeginFullScreen.
Set Angle to 0.0.
Set AngleIncrement to 0.03.
Repeat
  (
  BeginFrame.
  SetFrameBackgroundRGB 0,0,0.
  For i from -5 to 4 do        # Draw the floor.
    for j from -5 to 4 do
      (
      Set GrayShade to ((i+j) mod 2)*0.5 + 0.25.
      Draw3DQuadrilateralXYZ4RGB i,    j,0,
                              i  ,j+1,0,
                              i+1,j+1,0,
                              i+1,  j,0,
                              GrayShade,GrayShade,GrayShade.
      ).
  Set CosAngle to Cos(Angle).  # Draw the cube.
  Set SinAngle to Sin(Angle).
  Set MinusMinus to -CosAngle-SinAngle.
  Set MinusPlus  to -CosAngle+SinAngle.
  Set PlusMinus  to +CosAngle-SinAngle.
  Set PlusPlus   to +CosAngle+SinAngle.
  Draw3DQuadrilateralXYZ4RGB MinusMinus,PlusMinus ,0,
                             PlusMinus ,PlusPlus  ,0,
                             PlusPlus  ,MinusPlus ,0,
                             MinusPlus ,MinusMinus,0,
                             1,0.9,0.
  Draw3DQuadrilateralXYZ4RGB MinusPlus ,MinusMinus,0,
                             PlusPlus  ,MinusPlus ,0,
                             PlusPlus  ,MinusPlus ,2,
                             MinusPlus ,MinusMinus,2,
                             1,0.9,0.
  Draw3DQuadrilateralXYZ4RGB MinusMinus,PlusMinus ,0,
                             MinusPlus ,MinusMinus,0,
                             MinusPlus ,MinusMinus,2,
                             MinusMinus,PlusMinus ,2,
                             1,0.9,0.
  Draw3DQuadrilateralXYZ4RGB PlusMinus ,PlusPlus  ,0,
                             MinusMinus,PlusMinus ,0,
                             MinusMinus,PlusMinus ,2,
                             PlusMinus ,PlusPlus  ,2,
                             1,0.9,0.
  Draw3DQuadrilateralXYZ4RGB PlusPlus  ,MinusPlus ,0,
                             PlusMinus ,PlusPlus  ,0,
                             PlusMinus ,PlusPlus  ,2,
                             PlusPlus  ,MinusPlus ,2,
                             1,0.9,0.
  Draw3DQuadrilateralXYZ4RGB MinusPlus ,MinusMinus,2,
                             PlusPlus  ,MinusPlus ,2,
                             PlusMinus ,PlusPlus  ,2,
                             MinusMinus,PlusMinus ,2,
                             1,0.9,0.
  Set Angle to Angle + AngleIncrement.
  EndFrame.
  DrawFrame.
  )
until RequestedToStop.
EndFullScreen.

Click here to download or run the Windows version.


 
     
Home
Free version
Full version
Subscribe
List of site
subscribers
Specs
Docs
Contact
News
13 Sep 2010
 
Graph credits: field flow by David Parker, yin yang by Stijn Hertelé.
 
©2002-2010 Flaming Thunder