diff --git a/harbour/ChangeLog b/harbour/ChangeLog index f02c02d092..f544414e21 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -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. diff --git a/harbour/contrib/hbgd/tests/tpoly.prg b/harbour/contrib/hbgd/tests/tpoly.prg index 16075a0c8d..37c6920c6b 100644 --- a/harbour/contrib/hbgd/tests/tpoly.prg +++ b/harbour/contrib/hbgd/tests/tpoly.prg @@ -9,90 +9,110 @@ #include "gd.ch" #include "simpleio.ch" -#command TurnRight( ) => nAngle += M_PI / 3 * -#command TurnLeft( ) => nAngle -= M_PI / 3 * +#command TurnRight( ) => s_nAngle += M_PI / 3 * +#command TurnLeft( ) => s_nAngle -= M_PI / 3 * #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