2010-11-20 19:08 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)

* contrib/hbgd/tests/tpoly.prg
    * Applied patch from Tamas. Nicer flakes!
This commit is contained in:
Viktor Szakats
2010-11-20 18:09:01 +00:00
parent 82c2c97a65
commit de66a718aa
2 changed files with 58 additions and 34 deletions

View File

@@ -16,6 +16,10 @@
The license applies to all entries newer than 2009-04-28.
*/
2010-11-20 19:08 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)
* contrib/hbgd/tests/tpoly.prg
* Applied patch from Tamas. Nicer flakes!
2010-11-20 17:27 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)
* src/rtl/sha1.c
* Settling back to original version of some lines.

View File

@@ -9,90 +9,110 @@
#include "gd.ch"
#include "simpleio.ch"
#command TurnRight( <x> ) => nAngle += M_PI / 3 * <x>
#command TurnLeft( <x> ) => nAngle -= M_PI / 3 * <x>
#command TurnRight( <x> ) => s_nAngle += M_PI / 3 * <x>
#command TurnLeft( <x> ) => s_nAngle -= M_PI / 3 * <x>
#define M_PI 3.14159265358979323846
#define IMAGES_OUT "imgs_out" + hb_ps()
STATIC s_aCoords
STATIC s_nSides, s_nSideLen
STATIC s_nAngle, s_nCoordX, s_nCoordY
PROCEDURE Main()
LOCAL nDepth, nSide
LOCAL gdImage, gdColor
DrawFlake( .T. )
DrawFlake( .F. )
s_nSides := 3
s_nSideLen := 1500
RETURN
PROCEDURE DrawFlake( lOpenPoly )
LOCAL nDepth, nSide, nSides, nSideLen
LOCAL gdImage, gdColor
LOCAL cImageName
nSides := 3
nSideLen := 1500
nDepth := 7
cImageName := IIF( lOpenPoly, "flakeo.png", "flake.png" )
gdImage := gdImageCreate( 1900, 2100 )
gdImageColorAllocate( gdImage, 0, 0, 0 )
/* Flake inside out, initial state */
s_nCoordX := 200
s_nCoordY := 600
s_aCoords := { { s_nCoordX, s_nCoordY } }
s_nAngle := 0
/* Regular flake */
FOR nSide := 1 TO s_nSides
KochFlake( nDepth, s_nSideLen, .T. )
s_nAngle += M_PI * 2 / s_nSides
NEXT
/* Flake inside out */
FOR nSide := 1 TO s_nSides
KochFlake( nDepth, s_nSideLen, .F. )
s_nAngle += M_PI * 2 / s_nSides
FOR nSide := 1 TO nSides
KochFlake( nDepth, nSideLen, .F. )
s_nAngle += M_PI * 2 / nSides
NEXT
OutStd( hb_strFormat( "Drawing %d vertices%s", Len( s_aCoords ), hb_eol() ) )
gdImage := gdImageCreate( 1900, 2100 )
gdImageColorAllocate( gdImage, 0, 0, 0 )
gdColor := gdImageColorAllocate( gdImage, 255, 255, 0 )
gdImagePolygon( gdImage, s_aCoords, gdColor )
gdImagePng( gdImage, IMAGES_OUT + "flake.png" )
gdImageDestroy( gdImage )
/** In green */
gdColor := gdImageColorAllocate( gdImage, 0, 255, 0 )
IIF( lOpenPoly,;
gdImageOpenPolygon( gdImage, s_aCoords, gdColor ),;
gdImagePolygon( gdImage, s_aCoords, gdColor ) )
gdImage := gdImageCreate( 1900, 2100 )
gdImageColorAllocate( gdImage, 0, 0, 0 )
/* Regular flake, initial state */
s_nCoordX := 200
s_nCoordY := 600
s_aCoords := { { s_nCoordX, s_nCoordY } }
s_nAngle := 0
FOR nSide := 1 TO nSides
KochFlake( nDepth, nSideLen, .T. )
s_nAngle += M_PI * 2 / nSides
NEXT
OutStd( hb_strFormat( "Drawing %d vertices%s", Len( s_aCoords ), hb_eol() ) )
/** In yellow */
gdColor := gdImageColorAllocate( gdImage, 255, 255, 0 )
gdImageOpenPolygon( gdImage, s_aCoords, gdColor )
gdImagePng( gdImage, IMAGES_OUT + "flakeo.png" )
IIF( lOpenPoly,;
gdImageOpenPolygon( gdImage, s_aCoords, gdColor ),;
gdImagePolygon( gdImage, s_aCoords, gdColor ) )
gdImagePng( gdImage, IMAGES_OUT + cImageName )
gdImageDestroy( gdImage )
RETURN
PROCEDURE KochFlake( nDepth, s_nSideLen, lLeftFirst )
PROCEDURE KochFlake( nDepth, nSideLen, lLeftFirst )
IF nDepth == 0
AAdd( s_aCoords, {;
s_nCoordX += Cos( s_nAngle ) * s_nSideLen,;
s_nCoordY += Sin( s_nAngle ) * s_nSideLen;
s_nCoordX += Cos( s_nAngle ) * nSideLen,;
s_nCoordY += Sin( s_nAngle ) * nSideLen;
})
ELSE
KochFlake( nDepth - 1, s_nSideLen / 3, lLeftFirst )
KochFlake( nDepth - 1, nSideLen / 3, lLeftFirst )
IF lLeftFirst
TurnLeft( 1 )
ELSE
TurnRight( 1 )
ENDIF
KochFlake( nDepth - 1, s_nSideLen / 3, lLeftFirst )
KochFlake( nDepth - 1, nSideLen / 3, lLeftFirst )
IF lLeftFirst
TurnRight( 2 )
ELSE
TurnLeft( 2 )
ENDIF
KochFlake( nDepth - 1, s_nSideLen / 3, lLeftFirst )
KochFlake( nDepth - 1, nSideLen / 3, lLeftFirst )
IF lLeftFirst
TurnLeft( 1 )
ELSE
TurnRight( 1 )
ENDIF
KochFlake( nDepth - 1, s_nSideLen / 3, lLeftFirst )
KochFlake( nDepth - 1, nSideLen / 3, lLeftFirst )
ENDIF
RETURN