This page is for displaying my EGSL sample programs as I come up with them.


            egsl--circles-out-of-squares.php

            egsl-cloud-fractal.php

            egsl-star-art.php

            egsl-star-polygon.php

            egsl-star-polygon.php

            egsl-swirl.php

            fuzzy-fractals.php

 

  This first program is the beginning of a series of programs translated from the Scratch programming language .  It shows how to do functions and it displays a hexagon on a graphics screen.


  


screen (1000,600,32,"Hexagon")     -- Starts Program

pendown = 0  cnt = 0  PenX = 500  PenY = 10  Angle2 = 0  x2 = 0  y2 = 0  dx = 0

 dy = 0 Angle3 = 0 Angle4 =0 test = 0 d = 0 cnt2 = 0

                -- Create functions at start of program

                -- 1 Radian = 57.2958 Degrees.

                -- 1 degree = .0174532925 Radians

                -- math degrees = 450 - compass

function GotoXY(x,y)  PenX = x ; PenY = y end

function RotateRight(n) Angle = Angle + n end

function RadianToDegree(n) return n * 57.2958 end

function DegreeToRadian(n) return n * .0174532925 end

function GetAngle (n)   -- A function starts with "function" and ends with "end"

    n = 450 - n

    if n > 359.9999999 then n = n - 360 end

    return n

end

 function MoveSteps (n)                 -- move n steps using Angle

     Angle2 = GetAngle ( Angle )        -- The reason for all of this is because

     Angle3 = DegreeToRadian ( Angle2 ) --  I am converting angles from another language that

     dx = cos (Angle3)                  -- uses a turtle graphics type system. " Scratch "

     dy = sin (Angle3)

     x2 = PenX + dx * n

     y2 = PenY + dy * n

     if pendown == 1 then line(PenX,PenY,x2,y2) end

     PenX = x2 PenY = y2

     return PenX

 end


PenX = 400  PenY = 30

color (0,255,0)         -- sets color to green

backcolor (0,0,255)       -- sets background to blue

clearscreen()

redraw()

pendown = 1

Angle = 90

test = MoveSteps ( 20 )

drawtext (400,20,test)    -- variable "test" is used for debugging.

pendown = 0               -- simulates a Scratch " Penup " block

GotoXY(400,400)           -- simulates a Scratch "goto" block

d = 0


    while cnt2 < 100

    do

          while cnt < 6

          do                 -- the pair of keywords " do " and " end " are like brackets in c-language

          pendown = 1

          MoveSteps ( d )

          pendown = 0

          RotateRight(60)

          cnt = cnt + 1

          end

    cnt = 0;

    d = d + 1

    cnt2 = cnt2+1

    if d == 99 then color (0,0,0) end

    end

sync()

key = inkey()

closewindow()             -- This ends the program.





 

 

Make a free website with Yola