WeixiangYan/CodeTransOcean huggingface dataset:
Task: Angle difference between two bearings



C#: using System;

namespace Angle_difference_between_two_bearings
{
	class Program
	{
		public static void Main(string[] args)
		{
			Console.WriteLine();
			Console.WriteLine("Hello World!");
			Console.WriteLine();
			
			
			Console.WriteLine(Delta_Bearing( 20M,45));
			Console.WriteLine(Delta_Bearing(-45M,45M));
			Console.WriteLine(Delta_Bearing(-85M,90M));
			Console.WriteLine(Delta_Bearing(-95M,90M));
			Console.WriteLine(Delta_Bearing(-45M,125M));
			Console.WriteLine(Delta_Bearing(-45M,145M));
			Console.WriteLine(Delta_Bearing( 29.4803M,-88.6381M));
			Console.WriteLine(Delta_Bearing(-78.3251M, -159.036M));
			
			
			Console.WriteLine(Delta_Bearing(-70099.74233810938M,   29840.67437876723M));
			Console.WriteLine(Delta_Bearing(-165313.6666297357M,   33693.9894517456M));
			Console.WriteLine(Delta_Bearing( 1174.8380510598456M, -154146.66490124757M));
			Console.WriteLine(Delta_Bearing( 60175.77306795546M,   42213.07192354373M));
			
			Console.WriteLine();
			Console.Write("Press any key to continue . . . ");
			Console.ReadKey(true);
		}
		
		static decimal Delta_Bearing(decimal b1, decimal b2)
		{
			
			
			
			
			
			
			decimal d = 0;
			
			
			if(b1<0)
				b1 += 360;
			if(b2<0)
				b2 += 360;
			
			
			
			
			d = (b2 - b1)%360;
			
			if(d>180)
				d -= 360;
			else if(d<-180)
				d += 360;
			
			return d;
			
			
			
			
		}
	}
}








Fortran:       SUBROUTINE BDIFF (B1,B2)	
       REAL*8 B1,B2	
       COMPLEX*16 CIS,Z1,Z2,Z	
       CIS(T) = CMPLX(COSD(T),SIND(T))	
        Z1 = CIS(90 - B1)	
        Z2 = CIS(90 - B2)	
        Z = Z1*CONJG(Z2)	
        T = ATAN2D(AIMAG(Z),REAL(Z))	
        WRITE (6,10) B1,Z1,B2,Z2,T	
   10   FORMAT (2(F14.4,"(",F9.6,",",F9.6,")"),F9.3)	
      END SUBROUTINE BDIFF	

      PROGRAM ORIENTED
      REAL*8 B(24)	
      DATA B/20D0,45D0, -45D0,45D0, -85D0,90D0, -95D0,90D0,	
     1      -45D0,125D0, -45D0,145D0, 29.4803D0,-88.6381D0,
     2      -78.3251D0,              -159.036D0,
     3   -70099.74233810938D0,      29840.67437876723D0,
     4  -165313.6666297357D0,       33693.9894517456D0,
     5     1174.8380510598456D0,  -154146.66490124757D0,
     6    60175.77306795546D0,      42213.07192354373D0/

      WRITE (6,1) ("B",I,"x","y", I = 1,2)	
    1 FORMAT (28X,"Bearing calculations, in degrees"//
     * 2(A13,I1,"(",A9,",",A9,")"),A9)	

      DO I = 1,23,2	
        CALL BDIFF(B(I),B(I + 1))
      END DO

      END
Task: Angle difference between two bearings


C++: #include <cmath>
#include <iostream>
using namespace std;

double getDifference(double b1, double b2) {
	double r = fmod(b2 - b1, 360.0);
	if (r < -180.0)
		r += 360.0;
	if (r >= 180.0)
		r -= 360.0;
	return r;
}

int main()
{
	cout << "Input in -180 to +180 range" << endl;
	cout << getDifference(20.0, 45.0) << endl;
	cout << getDifference(-45.0, 45.0) << endl;
	cout << getDifference(-85.0, 90.0) << endl;
	cout << getDifference(-95.0, 90.0) << endl;
	cout << getDifference(-45.0, 125.0) << endl;
	cout << getDifference(-45.0, 145.0) << endl;
	cout << getDifference(-45.0, 125.0) << endl;
	cout << getDifference(-45.0, 145.0) << endl;
	cout << getDifference(29.4803, -88.6381) << endl;
	cout << getDifference(-78.3251, -159.036) << endl;
	
	cout << "Input in wider range" << endl;
	cout << getDifference(-70099.74233810938, 29840.67437876723) << endl;
	cout << getDifference(-165313.6666297357, 33693.9894517456) << endl;
	cout << getDifference(1174.8380510598456, -154146.66490124757) << endl;
	cout << getDifference(60175.77306795546, 42213.07192354373) << endl;

	return 0;
}









Fortran:       SUBROUTINE BDIFF (B1,B2)	
       REAL*8 B1,B2	
       COMPLEX*16 CIS,Z1,Z2,Z	
       CIS(T) = CMPLX(COSD(T),SIND(T))	
        Z1 = CIS(90 - B1)	
        Z2 = CIS(90 - B2)	
        Z = Z1*CONJG(Z2)	
        T = ATAN2D(AIMAG(Z),REAL(Z))	
        WRITE (6,10) B1,Z1,B2,Z2,T	
   10   FORMAT (2(F14.4,"(",F9.6,",",F9.6,")"),F9.3)	
      END SUBROUTINE BDIFF	

      PROGRAM ORIENTED
      REAL*8 B(24)	
      DATA B/20D0,45D0, -45D0,45D0, -85D0,90D0, -95D0,90D0,	
     1      -45D0,125D0, -45D0,145D0, 29.4803D0,-88.6381D0,
     2      -78.3251D0,              -159.036D0,
     3   -70099.74233810938D0,      29840.67437876723D0,
     4  -165313.6666297357D0,       33693.9894517456D0,
     5     1174.8380510598456D0,  -154146.66490124757D0,
     6    60175.77306795546D0,      42213.07192354373D0/

      WRITE (6,1) ("B",I,"x","y", I = 1,2)	
    1 FORMAT (28X,"Bearing calculations, in degrees"//
     * 2(A13,I1,"(",A9,",",A9,")"),A9)	

      DO I = 1,23,2	
        CALL BDIFF(B(I),B(I + 1))
      END DO

      END
Task: Angle difference between two bearings

C: #include<stdlib.h>
#include<stdio.h>
#include<math.h>

void processFile(char* name){
	
	int i,records;
	double diff,b1,b2;
	FILE* fp = fopen(name,"r");
	
	fscanf(fp,"%d\n",&records);
	
	for(i=0;i<records;i++){
		fscanf(fp,"%lf%lf",&b1,&b2);
		
		diff = fmod(b2-b1,360.0);
		printf("\nDifference between b2(%lf) and b1(%lf) is %lf",b2,b1,(diff<-180)?diff+360:((diff>=180)?diff-360:diff));	
	}
	
	fclose(fp);
}

int main(int argC,char* argV[])
{
	double diff;
	
	if(argC < 2)
		printf("Usage : %s <bearings separated by a space OR full file name which contains the bearing list>",argV[0]);
	else if(argC == 2)
		processFile(argV[1]);
	else{
		diff = fmod(atof(argV[2])-atof(argV[1]),360.0);
		printf("Difference between b2(%s) and b1(%s) is %lf",argV[2],argV[1],(diff<-180)?diff+360:((diff>=180)?diff-360:diff));
	}

	return 0;
}










Fortran:       SUBROUTINE BDIFF (B1,B2)	
       REAL*8 B1,B2	
       COMPLEX*16 CIS,Z1,Z2,Z	
       CIS(T) = CMPLX(COSD(T),SIND(T))	
        Z1 = CIS(90 - B1)	
        Z2 = CIS(90 - B2)	
        Z = Z1*CONJG(Z2)	
        T = ATAN2D(AIMAG(Z),REAL(Z))	
        WRITE (6,10) B1,Z1,B2,Z2,T	
   10   FORMAT (2(F14.4,"(",F9.6,",",F9.6,")"),F9.3)	
      END SUBROUTINE BDIFF	

      PROGRAM ORIENTED
      REAL*8 B(24)	
      DATA B/20D0,45D0, -45D0,45D0, -85D0,90D0, -95D0,90D0,	
     1      -45D0,125D0, -45D0,145D0, 29.4803D0,-88.6381D0,
     2      -78.3251D0,              -159.036D0,
     3   -70099.74233810938D0,      29840.67437876723D0,
     4  -165313.6666297357D0,       33693.9894517456D0,
     5     1174.8380510598456D0,  -154146.66490124757D0,
     6    60175.77306795546D0,      42213.07192354373D0/

      WRITE (6,1) ("B",I,"x","y", I = 1,2)	
    1 FORMAT (28X,"Bearing calculations, in degrees"//
     * 2(A13,I1,"(",A9,",",A9,")"),A9)	

      DO I = 1,23,2	
        CALL BDIFF(B(I),B(I + 1))
      END DO

      END
Task: Angle difference between two bearings




Go: package main

import "fmt"

type bearing float64

var testCases = []struct{ b1, b2 bearing }{
    {20, 45},
    {-45, 45},
    {-85, 90},
    {-95, 90},
    {-45, 125},
    {-45, 145},
    {29.4803, -88.6381},
    {-78.3251, -159.036},
}

func main() {
    for _, tc := range testCases {
        fmt.Println(tc.b2.Sub(tc.b1))
    }
}

func (b2 bearing) Sub(b1 bearing) bearing {
    switch d := b2 - b1; {
    case d < -180:
        return d + 360
    case d > 180:
        return d - 360
    default:
        return d
    }
}







Fortran:       SUBROUTINE BDIFF (B1,B2)	
       REAL*8 B1,B2	
       COMPLEX*16 CIS,Z1,Z2,Z	
       CIS(T) = CMPLX(COSD(T),SIND(T))	
        Z1 = CIS(90 - B1)	
        Z2 = CIS(90 - B2)	
        Z = Z1*CONJG(Z2)	
        T = ATAN2D(AIMAG(Z),REAL(Z))	
        WRITE (6,10) B1,Z1,B2,Z2,T	
   10   FORMAT (2(F14.4,"(",F9.6,",",F9.6,")"),F9.3)	
      END SUBROUTINE BDIFF	

      PROGRAM ORIENTED
      REAL*8 B(24)	
      DATA B/20D0,45D0, -45D0,45D0, -85D0,90D0, -95D0,90D0,	
     1      -45D0,125D0, -45D0,145D0, 29.4803D0,-88.6381D0,
     2      -78.3251D0,              -159.036D0,
     3   -70099.74233810938D0,      29840.67437876723D0,
     4  -165313.6666297357D0,       33693.9894517456D0,
     5     1174.8380510598456D0,  -154146.66490124757D0,
     6    60175.77306795546D0,      42213.07192354373D0/

      WRITE (6,1) ("B",I,"x","y", I = 1,2)	
    1 FORMAT (28X,"Bearing calculations, in degrees"//
     * 2(A13,I1,"(",A9,",",A9,")"),A9)	

      DO I = 1,23,2	
        CALL BDIFF(B(I),B(I + 1))
      END DO

      END
Task: Angle difference between two bearings





Java: public class AngleDifference {

    public static double getDifference(double b1, double b2) {
        double r = (b2 - b1) % 360.0;
        if (r < -180.0)
            r += 360.0;
        if (r >= 180.0)
            r -= 360.0;
        return r;
    }

    public static void main(String[] args) {
        System.out.println("Input in -180 to +180 range");
        System.out.println(getDifference(20.0, 45.0));
        System.out.println(getDifference(-45.0, 45.0));
        System.out.println(getDifference(-85.0, 90.0));
        System.out.println(getDifference(-95.0, 90.0));
        System.out.println(getDifference(-45.0, 125.0));
        System.out.println(getDifference(-45.0, 145.0));
        System.out.println(getDifference(-45.0, 125.0));
        System.out.println(getDifference(-45.0, 145.0));
        System.out.println(getDifference(29.4803, -88.6381));
        System.out.println(getDifference(-78.3251, -159.036));

        System.out.println("Input in wider range");
        System.out.println(getDifference(-70099.74233810938, 29840.67437876723));
        System.out.println(getDifference(-165313.6666297357, 33693.9894517456));
        System.out.println(getDifference(1174.8380510598456, -154146.66490124757));
        System.out.println(getDifference(60175.77306795546, 42213.07192354373));
    }
}






Fortran:       SUBROUTINE BDIFF (B1,B2)	
       REAL*8 B1,B2	
       COMPLEX*16 CIS,Z1,Z2,Z	
       CIS(T) = CMPLX(COSD(T),SIND(T))	
        Z1 = CIS(90 - B1)	
        Z2 = CIS(90 - B2)	
        Z = Z1*CONJG(Z2)	
        T = ATAN2D(AIMAG(Z),REAL(Z))	
        WRITE (6,10) B1,Z1,B2,Z2,T	
   10   FORMAT (2(F14.4,"(",F9.6,",",F9.6,")"),F9.3)	
      END SUBROUTINE BDIFF	

      PROGRAM ORIENTED
      REAL*8 B(24)	
      DATA B/20D0,45D0, -45D0,45D0, -85D0,90D0, -95D0,90D0,	
     1      -45D0,125D0, -45D0,145D0, 29.4803D0,-88.6381D0,
     2      -78.3251D0,              -159.036D0,
     3   -70099.74233810938D0,      29840.67437876723D0,
     4  -165313.6666297357D0,       33693.9894517456D0,
     5     1174.8380510598456D0,  -154146.66490124757D0,
     6    60175.77306795546D0,      42213.07192354373D0/

      WRITE (6,1) ("B",I,"x","y", I = 1,2)	
    1 FORMAT (28X,"Bearing calculations, in degrees"//
     * 2(A13,I1,"(",A9,",",A9,")"),A9)	

      DO I = 1,23,2	
        CALL BDIFF(B(I),B(I + 1))
      END DO

      END
Task: Angle difference between two bearings







Python: from __future__ import print_function
 
def getDifference(b1, b2):
	r = (b2 - b1) % 360.0
	
	
	if r >= 180.0:
		r -= 360.0
	return r
 
if __name__ == "__main__":
	print ("Input in -180 to +180 range")
	print (getDifference(20.0, 45.0))
	print (getDifference(-45.0, 45.0))
	print (getDifference(-85.0, 90.0))
	print (getDifference(-95.0, 90.0))
	print (getDifference(-45.0, 125.0))
	print (getDifference(-45.0, 145.0))
	print (getDifference(-45.0, 125.0))
	print (getDifference(-45.0, 145.0))
	print (getDifference(29.4803, -88.6381))
	print (getDifference(-78.3251, -159.036))
 
	print ("Input in wider range")
	print (getDifference(-70099.74233810938, 29840.67437876723))
	print (getDifference(-165313.6666297357, 33693.9894517456))
	print (getDifference(1174.8380510598456, -154146.66490124757))
	print (getDifference(60175.77306795546, 42213.07192354373))




Fortran:       SUBROUTINE BDIFF (B1,B2)	
       REAL*8 B1,B2	
       COMPLEX*16 CIS,Z1,Z2,Z	
       CIS(T) = CMPLX(COSD(T),SIND(T))	
        Z1 = CIS(90 - B1)	
        Z2 = CIS(90 - B2)	
        Z = Z1*CONJG(Z2)	
        T = ATAN2D(AIMAG(Z),REAL(Z))	
        WRITE (6,10) B1,Z1,B2,Z2,T	
   10   FORMAT (2(F14.4,"(",F9.6,",",F9.6,")"),F9.3)	
      END SUBROUTINE BDIFF	

      PROGRAM ORIENTED
      REAL*8 B(24)	
      DATA B/20D0,45D0, -45D0,45D0, -85D0,90D0, -95D0,90D0,	
     1      -45D0,125D0, -45D0,145D0, 29.4803D0,-88.6381D0,
     2      -78.3251D0,              -159.036D0,
     3   -70099.74233810938D0,      29840.67437876723D0,
     4  -165313.6666297357D0,       33693.9894517456D0,
     5     1174.8380510598456D0,  -154146.66490124757D0,
     6    60175.77306795546D0,      42213.07192354373D0/

      WRITE (6,1) ("B",I,"x","y", I = 1,2)	
    1 FORMAT (28X,"Bearing calculations, in degrees"//
     * 2(A13,I1,"(",A9,",",A9,")"),A9)	

      DO I = 1,23,2	
        CALL BDIFF(B(I),B(I + 1))
      END DO

      END
Task: Angle difference between two bearings








VB: Private Function tx(a As Variant) As String
    Dim s As String
    s = CStr(Format(a, "0.######"))
    If Right(s, 1) = "," Then
        s = Mid(s, 1, Len(s) - 1) & "       "
    Else
        i = InStr(1, s, ",")
        s = s & String$(6 - Len(s) + i, " ")
    End If
    tx = s
End Function
Private Sub test(b1 As Variant, b2 As Variant)
    Dim diff As Variant
    diff = (b2 - b1) - ((b2 - b1) \ 360) * 360
    diff = diff - IIf(diff > 180, 360, 0)
    diff = diff + IIf(diff < -180, 360, 0)
    Debug.Print Format(tx(b1), "@@@@@@@@@@@@@@@@"); Format(tx(b2), "@@@@@@@@@@@@@@@@@"); Format(tx(diff), "@@@@@@@@@@@@@@@@@")
End Sub
Public Sub angle_difference()
    Debug.Print "       b1               b2             diff"
    Debug.Print "---------------- ---------------- ----------------"
    test 20, 45
    test -45, 45
    test -85, 90
    test -95, 90
    test -45, 125
    test -45, 145
    test 29.4803, -88.6381
    test -78.3251, -159.036
    test -70099.7423381094, 29840.6743787672
    test -165313.666629736, 33693.9894517456
    test 1174.83805105985, -154146.664901248
    test 60175.7730679555, 42213.0719235437
End Sub



Fortran:       SUBROUTINE BDIFF (B1,B2)	
       REAL*8 B1,B2	
       COMPLEX*16 CIS,Z1,Z2,Z	
       CIS(T) = CMPLX(COSD(T),SIND(T))	
        Z1 = CIS(90 - B1)	
        Z2 = CIS(90 - B2)	
        Z = Z1*CONJG(Z2)	
        T = ATAN2D(AIMAG(Z),REAL(Z))	
        WRITE (6,10) B1,Z1,B2,Z2,T	
   10   FORMAT (2(F14.4,"(",F9.6,",",F9.6,")"),F9.3)	
      END SUBROUTINE BDIFF	

      PROGRAM ORIENTED
      REAL*8 B(24)	
      DATA B/20D0,45D0, -45D0,45D0, -85D0,90D0, -95D0,90D0,	
     1      -45D0,125D0, -45D0,145D0, 29.4803D0,-88.6381D0,
     2      -78.3251D0,              -159.036D0,
     3   -70099.74233810938D0,      29840.67437876723D0,
     4  -165313.6666297357D0,       33693.9894517456D0,
     5     1174.8380510598456D0,  -154146.66490124757D0,
     6    60175.77306795546D0,      42213.07192354373D0/

      WRITE (6,1) ("B",I,"x","y", I = 1,2)	
    1 FORMAT (28X,"Bearing calculations, in degrees"//
     * 2(A13,I1,"(",A9,",",A9,")"),A9)	

      DO I = 1,23,2	
        CALL BDIFF(B(I),B(I + 1))
      END DO

      END
Task: Archimedean spiral

C: #include <jambo.h>

Main
   Set break
   a=1.5, b=1.5, r=0, origen x=200, origen y=105
   total = 0, Let ( total := Mul(20, M_PI) )
   Cls
   Loop for ( t=0, var 't' Is less equal to 'total', Let (t := Add (t, 0.005)) )
       #( r = a + b * t )
       Set 'origen x, origen y', # ( 200 + (2*r*sin(t)) ) » 'origen x', #( 105 + (r*cos(t)) ) » 'origen y', 
       Gosub 'Dibuja un segmento'
   Next
   Pause
End

Subrutines

Define (Dibuja un segmento, x1, y1, x2, y2)
  dx=0, dy=0, paso=0, i=0, DX=0, DY=0

  Sub(x2, x1), Sub (y2, y1), Move to ' dx, dy '

  Let( paso := Get if( Greater equal ( Abs(dx) » (DX), Abs(dy)»(DY) ), DX, DY ) )

  
  Div(dx, paso), Div(dy, paso), Move to ( dx, dy )

  Color back (13)
  
  i = 0
  Loop if ( Less equal (i, paso) )
     Locate( y1, x1 ), Printnl( " " )
     Add ( x1, dx), Add( y1, dy ), Move to ( x1, y1 )
     ++i
  Back
  Printnl("\OFF")
Return











Ada: with Ada.Numerics.Elementary_Functions;

with SDL.Video.Windows.Makers;
with SDL.Video.Renderers.Makers;
with SDL.Events.Events;

procedure Archimedean_Spiral is

   Width      : constant := 800;
   Height     : constant := 800;
   A          : constant := 4.2;
   B          : constant := 3.2;
   T_First    : constant := 4.0;
   T_Last     : constant := 100.0;

   Window   : SDL.Video.Windows.Window;
   Renderer : SDL.Video.Renderers.Renderer;
   Event    : SDL.Events.Events.Events;

   procedure Draw_Archimedean_Spiral is
      use type SDL.C.int;
      use Ada.Numerics.Elementary_Functions;
      Pi   : constant := Ada.Numerics.Pi;
      Step : constant := 0.002;
      T    : Float;
      R    : Float;
   begin
      T := T_First;
      loop
         R := A + B * T;
         Renderer.Draw
           (Point => (X => Width  / 2 + SDL.C.int (R * Cos (T, 2.0 * Pi)),
                      Y => Height / 2 - SDL.C.int (R * Sin (T, 2.0 * Pi))));
         exit when T >= T_Last;
         T := T + Step;
      end loop;
   end Draw_Archimedean_Spiral;

   procedure Wait is
      use type SDL.Events.Event_Types;
   begin
      loop
         while SDL.Events.Events.Poll (Event) loop
            if Event.Common.Event_Type = SDL.Events.Quit then
               return;
            end if;
         end loop;
      end loop;
   end Wait;

begin
   if not SDL.Initialise (Flags => SDL.Enable_Screen) then
      return;
   end if;

   SDL.Video.Windows.Makers.Create (Win      => Window,
                                    Title    => "Archimedean spiral",
                                    Position => SDL.Natural_Coordinates'(X => 10, Y => 10),
                                    Size     => SDL.Positive_Sizes'(Width, Height),
                                    Flags    => 0);
   SDL.Video.Renderers.Makers.Create (Renderer, Window.Get_Surface);
   Renderer.Set_Draw_Colour ((0, 0, 0, 255));
   Renderer.Fill (Rectangle => (0, 0, Width, Height));
   Renderer.Set_Draw_Colour ((0, 220, 0, 255));

   Draw_Archimedean_Spiral;
   Window.Update_Surface;

   Wait;
   Window.Finalize;
   SDL.Finalise;
end Archimedean_Spiral;
Task: Archimedean spiral




Go: package main

import (
	"image"
	"image/color"
	"image/draw"
	"image/png"
	"log"
	"math"
	"os"
)

func main() {
	const (
		width, height = 600, 600
		centre        = width / 2.0
		degreesIncr   = 0.1 * math.Pi / 180
		turns         = 2
		stop          = 360 * turns * 10 * degreesIncr
		fileName      = "spiral.png"
	)

	img := image.NewNRGBA(image.Rect(0, 0, width, height)) 
	bg := image.NewUniform(color.RGBA{255, 255, 255, 255}) 
	draw.Draw(img, img.Bounds(), bg, image.ZP, draw.Src)   
	fgCol := color.RGBA{255, 0, 0, 255}                    

	a := 1.0
	b := 20.0

	for theta := 0.0; theta < stop; theta += degreesIncr {
		r := a + b*theta
		x := r * math.Cos(theta)
		y := r * math.Sin(theta)
		img.Set(int(centre+x), int(centre-y), fgCol)
	}

	imgFile, err := os.Create(fileName)
	if err != nil {
		log.Fatal(err)
	}
	defer imgFile.Close()

	if err := png.Encode(imgFile, img); err != nil {
		imgFile.Close()
		log.Fatal(err)
	}
}








Ada: with Ada.Numerics.Elementary_Functions;

with SDL.Video.Windows.Makers;
with SDL.Video.Renderers.Makers;
with SDL.Events.Events;

procedure Archimedean_Spiral is

   Width      : constant := 800;
   Height     : constant := 800;
   A          : constant := 4.2;
   B          : constant := 3.2;
   T_First    : constant := 4.0;
   T_Last     : constant := 100.0;

   Window   : SDL.Video.Windows.Window;
   Renderer : SDL.Video.Renderers.Renderer;
   Event    : SDL.Events.Events.Events;

   procedure Draw_Archimedean_Spiral is
      use type SDL.C.int;
      use Ada.Numerics.Elementary_Functions;
      Pi   : constant := Ada.Numerics.Pi;
      Step : constant := 0.002;
      T    : Float;
      R    : Float;
   begin
      T := T_First;
      loop
         R := A + B * T;
         Renderer.Draw
           (Point => (X => Width  / 2 + SDL.C.int (R * Cos (T, 2.0 * Pi)),
                      Y => Height / 2 - SDL.C.int (R * Sin (T, 2.0 * Pi))));
         exit when T >= T_Last;
         T := T + Step;
      end loop;
   end Draw_Archimedean_Spiral;

   procedure Wait is
      use type SDL.Events.Event_Types;
   begin
      loop
         while SDL.Events.Events.Poll (Event) loop
            if Event.Common.Event_Type = SDL.Events.Quit then
               return;
            end if;
         end loop;
      end loop;
   end Wait;

begin
   if not SDL.Initialise (Flags => SDL.Enable_Screen) then
      return;
   end if;

   SDL.Video.Windows.Makers.Create (Win      => Window,
                                    Title    => "Archimedean spiral",
                                    Position => SDL.Natural_Coordinates'(X => 10, Y => 10),
                                    Size     => SDL.Positive_Sizes'(Width, Height),
                                    Flags    => 0);
   SDL.Video.Renderers.Makers.Create (Renderer, Window.Get_Surface);
   Renderer.Set_Draw_Colour ((0, 0, 0, 255));
   Renderer.Fill (Rectangle => (0, 0, Width, Height));
   Renderer.Set_Draw_Colour ((0, 220, 0, 255));

   Draw_Archimedean_Spiral;
   Window.Update_Surface;

   Wait;
   Window.Finalize;
   SDL.Finalise;
end Archimedean_Spiral;
Task: Archimedean spiral







Python: theta = 0
rotation = 0.1

def setup():
    size(300, 300)
    background(255)

def draw():
    global theta
    translate(width / 2.0, height / 2.0)
    x = theta * cos(theta / PI)
    y = theta * sin(theta / PI)
    point(x, y)
    theta = theta + rotation
    
    if x > width / 2.0:
        background(255)
        theta = 0





Ada: with Ada.Numerics.Elementary_Functions;

with SDL.Video.Windows.Makers;
with SDL.Video.Renderers.Makers;
with SDL.Events.Events;

procedure Archimedean_Spiral is

   Width      : constant := 800;
   Height     : constant := 800;
   A          : constant := 4.2;
   B          : constant := 3.2;
   T_First    : constant := 4.0;
   T_Last     : constant := 100.0;

   Window   : SDL.Video.Windows.Window;
   Renderer : SDL.Video.Renderers.Renderer;
   Event    : SDL.Events.Events.Events;

   procedure Draw_Archimedean_Spiral is
      use type SDL.C.int;
      use Ada.Numerics.Elementary_Functions;
      Pi   : constant := Ada.Numerics.Pi;
      Step : constant := 0.002;
      T    : Float;
      R    : Float;
   begin
      T := T_First;
      loop
         R := A + B * T;
         Renderer.Draw
           (Point => (X => Width  / 2 + SDL.C.int (R * Cos (T, 2.0 * Pi)),
                      Y => Height / 2 - SDL.C.int (R * Sin (T, 2.0 * Pi))));
         exit when T >= T_Last;
         T := T + Step;
      end loop;
   end Draw_Archimedean_Spiral;

   procedure Wait is
      use type SDL.Events.Event_Types;
   begin
      loop
         while SDL.Events.Events.Poll (Event) loop
            if Event.Common.Event_Type = SDL.Events.Quit then
               return;
            end if;
         end loop;
      end loop;
   end Wait;

begin
   if not SDL.Initialise (Flags => SDL.Enable_Screen) then
      return;
   end if;

   SDL.Video.Windows.Makers.Create (Win      => Window,
                                    Title    => "Archimedean spiral",
                                    Position => SDL.Natural_Coordinates'(X => 10, Y => 10),
                                    Size     => SDL.Positive_Sizes'(Width, Height),
                                    Flags    => 0);
   SDL.Video.Renderers.Makers.Create (Renderer, Window.Get_Surface);
   Renderer.Set_Draw_Colour ((0, 0, 0, 255));
   Renderer.Fill (Rectangle => (0, 0, Width, Height));
   Renderer.Set_Draw_Colour ((0, 220, 0, 255));

   Draw_Archimedean_Spiral;
   Window.Update_Surface;

   Wait;
   Window.Finalize;
   SDL.Finalise;
end Archimedean_Spiral;