My_first_sdl

by Steven Binns: Y11 Age ~15

Introduction

This neat and effective program produces a pleasing visual effect. The screenshot shows the program in action. We encourage you to execute the program and see if you like the animation.


Output from my_first_sdl

Output from my_first_sdl

All of Steven's other contributions except PlatformDemo use SDL or its successor, SDL2.

The source code is below. To view the program you can download my_first_sdl.zip here, unzip it and double click on my_first_sdl.exe. If you would like to develop the code, see Getting Started with SDL for download details of SDL.pas and other Pascal header files as necessary.

For for a version in Smart Mobile Studio (that you can see on its web page) follow the link below.

The Program

program my_first_sdl;
{
    Copyright (c) 2011 Steven Binns

    Licensed under the Apache License, Version 2.0 (the "License"); you may not
    use this file except in compliance with the License, as described at
    http://www.apache.org/licenses/ and http://www.pp4s.co.uk/licenses/
}
{$apptype gui}
uses
  SDL, SDL_GFX;
var
  screen : pSDL_SURFACE;
  x, y :  integer;
begin
  SDL_Init(SDL_INIT_VIDEO);
  screen := SDL_SetVideoMode(400, 400, 32, SDL_SWSURFACE);
  if screen = nil then
    halt;
  x := 0;
  y := 200;
  repeat
    if x <= 200 then
       x += 1
    else
       x := 0;
    if y >= 0 then
      y -= 1
    else
      y := 200;
    EllipseColor(screen, 200, 200, x, y, $00FF00FF);
    SDL_Flip(screen);
    SDL_Delay(15);
  until x = 0;
  SDL_Delay(5000);
  SDL_FreeSurface(screen);
  SDL_Quit;
end. 

Remarks

Could you "ring the changes" on this program to make an effective animation?

Programming - a skill for life!

Seven programs including ALifeSim, Invader, My_first_sdl2 and PlatformDemo by Steven Binns