Smart Mobile Studio
  • News
  • Forums
  • Download
  • Store
  • Showcases
    • Featured demos
    • The Smart Contest 2013, Round 1 – Graphics
  • Documentation
    • Get the book
    • System requirements
    • Prerequisites
    • Getting started
      • Introduction
      • Application architecture
      • The application object
      • Forms and navigation
      • Message dialogs
      • Themes and styles
    • Project types
      • Visual project
      • Game project
      • Console project
    • Layout manager
    • Networking
      • TW3HttpRequest
      • TW3JSONP
      • Loading files
  • About

Archimedes spiral

Posted on 30.04.2012 by Jon Lennart Posted in Developers log

Here is a fun graphical effect. Start a new game project and paste in the following code (remember to keep the unit name). The effect is known as Archimedes spiral, although we play with the numbers to create a strobe like effect.

The numbers of life

The numbers of life

[sourcecode language=”delphi”]
unit ArchSpiral;

interface

uses w3system, w3components, w3ctrls, w3application,
w3game, w3gameapp, w3graphics, w3components;

type
TApplication = class(TW3CustomGameApplication)
private
{ Private methods }
FaValue: Float;
FbValue: Float;
protected
{ protected methods }
procedure ApplicationStarting; override;
procedure ApplicationClosing; override;
procedure PaintView(Canvas: TW3Canvas); override;
end;

implementation

procedure TApplication.ApplicationStarting;
begin
inherited;

FaValue := 5.0;
FbValue := 1.0;

//Initialize refresh interval, set this to 1 for optimal speed
GameView.Delay:=20;

//Start the redraw-cycle with framecounter active
//Note: the framecounter impacts rendering speed. Disable
//the framerate for maximum speed (false)
GameView.StartSession(true);
end;

procedure TApplication.ApplicationClosing;
begin
GameView.EndSession;
inherited;
end;

// Note: In a real live game you would try to cache as much
// info as you can. Typical tricks are:
// 1: Only get the width/height when resized
// 2: Pre-calculate strings, especially RGB/RGBA values
// 3: Only redraw what has changed, avoid a full repaint
// The code below is just to get you started

procedure TApplication.PaintView(Canvas:TW3Canvas);
var
cx,cy: Float;
i: Integer;
angle: Float;
x,y: Float;
begin
fbValue := fbValue + 0.0009;

// Clear background
Canvas.FillStyle := ‘rgba(0,0,99,0.3)’;
Canvas.FillRectF(0, 0, GameView.Width, GameView.Height);

// Draw our framerate on the screen
Canvas.Font := ’10pt verdana’;
Canvas.FillStyle := ‘rgb(255,255,255)’;
Canvas.FillTextF(‘FPS:’ + IntToStr(GameView.FrameRate),10,20,MAX_INT);

cx := GameView.Width div 2;
cy := GameView.Height div 2;
Canvas.MoveToF(cx,cy);
Canvas.BeginPath;
for i := 0 to 719 do
begin
angle := fbValue * i;
x := cx + (FaValue + FbValue * angle) * cos(angle);
y := cy + (FaValue + FbValue * angle) * sin(angle);
Canvas.LinetoF(x,y);
end;
Canvas.StrokeStyle := ColorToWebStr(clWhite);
Canvas.Stroke;
end;

end.
[/sourcecode]

Demo and code

You can download the project source code here: ArchSpiral.zip

You can find an online demo here: ArchSpiral demo

(Or simply scan the QR code below with your phone)

qrcode

« Smart game: WarTrail
Support for helper objects »

Pages

  • About
  • Feature Matrix
  • Forums
  • News
  • Release History
  • Download
  • Showcases
    • The Smart Contest 2013, Round 1 – Graphics
  • Store
  • Documentation
    • Creating your own controls
    • Debugging, exceptions and error handling
    • Differences between Delphi and Smart
    • Get the book
    • Getting started
      • Introduction
      • Local storage, session storage and global storage
      • Application architecture
      • The application object
      • Forms and navigation
      • Message dialogs
      • pmSmart Box Model
      • Themes and styles
    • Layout manager
    • Networking
      • Loading files
      • TW3HttpRequest
      • TW3JSONP
    • Prerequisites
    • Real data, talking to sqLite
    • System requirements
    • Project types
      • Visual project
      • Game project
      • Console project

Archives

  • December 2019
  • December 2018
  • November 2018
  • July 2018
  • June 2018
  • February 2018
  • September 2017
  • April 2017
  • November 2016
  • October 2016
  • September 2016
  • April 2016
  • March 2016
  • January 2016
  • October 2015
  • September 2015
  • July 2015
  • April 2015
  • January 2015
  • December 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • June 2014
  • March 2014
  • February 2014
  • January 2014
  • December 2013
  • November 2013
  • October 2013
  • August 2013
  • July 2013
  • June 2013
  • May 2013
  • April 2013
  • March 2013
  • February 2013
  • January 2013
  • December 2012
  • November 2012
  • August 2012
  • July 2012
  • June 2012
  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • November 2011
  • October 2011
  • September 2011

Categories

  • Announcements (25)
  • Developers log (119)
  • Documentation (26)
  • News (104)
  • News and articles (16)

WordPress

  • Register
  • Log in
  • WordPress

Subscribe

  • Entries (RSS)
  • Comments (RSS)
© Optimale Systemer AS