RetroBASIC

Retrogamecoding(.org) => EGSL => Topic started by: Rick3137 on May 25, 2013, 12:59:44 pm

Title: EGSL Samples
Post by: Rick3137 on May 25, 2013, 12:59:44 pm
 I've just started using EGSL and I am starting a series of EGSL sample programs. I like script languages over compiled languages because they are so much more easy to use. You can trade them with your friends and not worry about having a virus hiding somewhere in the code where you can't find it.

  I am active on another website that uses building blocks instead of scripts. This is also a safe way to program. I am now busy trying to translate these programs to EGSL and other free scripting languages. The idea that we are pushing is called "Remixing" Anyone can take another users program, add to it and then repost it. I want to try and do the same with scripting languages.
    My website: http://rb23.yolasite.com        ( still being built)

Title: Re: EGSL Samples
Post by: Rick3137 on May 25, 2013, 01:02:20 pm
  This is the first sample:
Code: [Select]
      --  This program written by Auntiechristine and Rick3137 at
      --  Scratch.mit.edu
      --  See more programs like this at: http://rb23.yolasite.com/
screen (1000,600,32,"Template")     -- Starts Program
pendown = 0  cnt = 0  PenX = 0  PenY = 0  Angle2 = 0  x2 = 0  y2 = 0  dx = 0
 dy = 0 Angle3 = 0 Angle4 =0 test = 0 d = 0 cnt2 = 0 red =0 green = 0 blue = 0
 key = 0 x1 =0  y1=0
                -- Create functions at start of program
                -- 1 Radian = 57.2958 Degrees.
                -- 1 degree = .0174532925 Radians
                -- math degrees = 450 - compass
function SetColor() color (red,green,blue) end
function ChangeColor(n)
    blue = blue + n
    if blue > 255 then blue = 0 ; green = green + 1 end
    if green > 255 then green = 0 ; red = red + 1 end
    if red > 255 then green = 0 ; red = 0 blue =0 end
    color (red,green,blue)
 end
function GotoXY(x,y)  PenX = x ; PenY = y end
function RotateRight(n)
         Angle = Angle + n
        -- while (Angle > 360) do
               if  Angle > 360  then  Angle = Angle - 360 end
         --end


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 > 450 then n = n - 360 end
    if n == 450 then n = 90 end
    return n
end
 function MoveSteps (n)                 -- move n steps using Angle
     --Angle = floor(Angle)
     n=n*2
     x1 = 500 + PenX
     y1 = 300 - PenY
     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 "
      dx = dx* 10000  dx = floor(dx) dx = dx/10000
     dy = sin (Angle3) dy = dy* 10000  dy = floor(dy) dy = dy/10000
     x2 = x1 + dx * n
     y2 = y1 - dy * n
     x1=round(x1) y1=round(y1) x2=round(x2) y2=round(y2)
     if pendown == 1 then line(x1,y1,x2,y2) end
     PenX = PenX + dx * n   PenY = PenY + dy * n
     return PenX
 end

 function test()         -- Use for debugging
      PenX = 0  PenY = 0
      Angle = 90
      color (25,22,255)            -- sets color to green
      backcolor (0,0,50)          -- sets background to blue
      clearscreen()
      redraw()
      pendown = 1
      --line(PenX,PenY,x2,y2)
      MoveSteps (100)  RotateRight(90)    MoveSteps (100)   RotateRight(90) MoveSteps (100)   RotateRight(90) MoveSteps (100)
      drawtext(50,40," angles")   drawtext(200,40,Angle)    drawtext(350,40,Angle2)    drawtext(550,40,Angle3)
      drawtext(50,60,"x1,y1,x2,y2")     drawtext(200,60,x1)    drawtext(350,60,y1)   drawtext(550,60,x2)    drawtext(750,60,y2)
      drawtext(50,80,"PenX,PenY,dx,dy")     drawtext(200,80,PenX)    drawtext(350,80,PenY)  drawtext(550,80,dx)    drawtext(750,80,dy)
      q=round(5.6)
      q=math.deg(math.pi)

      drawtext (50,100,q)
      redraw()
  end

 pendown = 0
color (250,220,0)            -- sets color to green
backcolor (0,0,50)          -- sets background to blue
clearscreen()
redraw()
complexity = 20
size = 99
cnt = 0

    while cnt < 100 do
clearscreen()
complexity = complexity + 2
PenX =0  PenY = 0
                  Angle = 90
pendown = 1




          cnt2 = 0
                 while cnt2 < complexity  do
          cnt3 = 0
      while cnt3 < 4 do
MoveSteps (complexity)
RotateRight(90)
cnt3 = cnt3 + 1
                        redraw()

end
RotateRight( 360/complexity )
ChangeColor(199)
cnt2 = cnt2+1
                end
                redraw()
         
pendown = 0

PenX =0  PenY = 0
Angle = 90
middle = size / 2
color (255,255,255)
    pendown = 1
          cnt2 = 0
                 while cnt2 < 180 do
          cnt3 = 0
while cnt3 < 4  do
MoveSteps (middle)
RotateRight(90)
cnt3 = cnt3 + 1

redraw()
end
RotateRight( 360/complexity )
cnt2 = cnt2 + 1
                end

pendown = 0
PenX =0  PenY = 0
Angle = 90
color (255,255,255)
    pendown = 1
cnt2 = 0
                 while cnt2 < 8   do
          cnt3 = 0
while cnt3 < 15  do
MoveSteps (3)
RotateRight( 24 )
cnt3 = cnt3+1
                        ChangeColor(128)
redraw()
end

RotateRight( 360/8 )
cnt2 = cnt2 + 1
                end

    pendown = 0
    PenX =  - 210
    PenY =  - 150
    redraw()
   cnt = cnt + 1
   wait (200)
   key = getkey()
   if (key > 31 ) then closewindow() end
   end


   
inkey()
closewindow()   

     






Title: Re: EGSL Samples
Post by: Rick3137 on May 25, 2013, 01:05:09 pm
  Second sample:  SWIRL
Code: [Select]
      --  This program written by Hust and Rick3137 at
      --  Scratch.mit.edu
       --  See more at: http://rb23.yolasite.com/
screen (1360,700,16,"Template")     -- Starts Program
alphachannel (100)
pendown = 0  cnt = 0  PenX = 0  PenY = 0  Angle = 0 Angle2 = 0  x2 = 0  y2 = 0  dx = 0
 dy = 0 Angle3 = 0 Angle4 =0 test = 0 d = 0 cnt2 = 0 cnt3 = 0 red =0 green = 0 blue = 0
 key = 0 x1 =0  y1=0
                -- Create functions at start of program
                -- 1 Radian = 57.2958 Degrees.
                -- 1 degree = .0174532925 Radians
                -- math degrees = 450 - compass
function SetColor(r,g,b) color (r,g,b) red=r ; green = g ; blue = b  end
function ChangeColor(n)
    blue = blue + n
    if blue > 255 then blue = n-255 ; green = green + 1 end
    if green > 255 then green = 0 ; red = red + 1 end
    if red > 255 then  red = 0  end
    SetColor (red,green,blue)
 end
function GotoXY(x,y)  PenX = x ; PenY = y end
function RotateRight(n)
         Angle = Angle + n
        -- while (Angle > 360) do
               if  Angle > 360  then  Angle = Angle - 360 end
         --end


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 > 450 then n = n - 360 end
    if n == 450 then n = 90 end
    return n
end
 function MoveSteps (n)                 -- move n steps using Angle
  --n = n * 1.5
     --Angle = floor(Angle)
     x1 = 680 + PenX
     y1 = 350 - PenY
     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 "
      dx = dx* 10000  dx = floor(dx) dx = dx/10000
     dy = sin (Angle3) dy = dy* 10000  dy = floor(dy) dy = dy/10000
     x2 = x1 + dx * n
     y2 = y1 - dy * n
     x1=round(x1) y1=round(y1) x2=round(x2) y2=round(y2)
     if pendown == 1 then line(x1,y1,x2,y2) end
     PenX = PenX + dx * n   PenY = PenY + dy * n
     return PenX
 end

 function test()         -- Use for debugging
      PenX = 0  PenY = 0
      Angle = 90
      SetColor (250,0,200)            -- sets color to green
      backcolor (0,0,20)          -- sets background to blue
      clearscreen()
      redraw()
      pendown = 1
      --line(PenX,PenY,x2,y2)
      MoveSteps (100)  RotateRight(90)    MoveSteps (100)   RotateRight(90) MoveSteps (100)   RotateRight(90) MoveSteps (100)
      drawtext(50,40," angles")   drawtext(200,40,Angle)    drawtext(350,40,Angle2)    drawtext(550,40,Angle3)
      drawtext(50,60,"x1,y1,x2,y2")     drawtext(200,60,x1)    drawtext(350,60,y1)   drawtext(550,60,x2)    drawtext(750,60,y2)
      drawtext(50,80,"PenX,PenY,dx,dy")     drawtext(200,80,PenX)    drawtext(350,80,PenY)  drawtext(550,80,dx)    drawtext(750,80,dy)
      q=round(5.6)
      q=math.deg(math.pi)

      drawtext (50,100,q)
      redraw()
  end


backcolor (0,0,30)          -- sets background to blue
clearscreen()
         SetColor (251,100,0)
redraw()
pendown = 0       
        sAngle = 18
        cnt=0 sx = 0
    while cnt < 200
    do
    pendown = 0
    clearscreen()
    PenX = 0  PenY = 0
    sx = 2
    pendown = 1
            while sx < 150
            do
            ChangeColor( 240 )
                         cnt2 = 0
                         while cnt2 < 6
                         do
                               cnt3 = 0
                               while cnt3 < 2
                               do
                                     cnt4 = 0
                                     while cnt4 < 9
                                     do
                                       RotateRight( sAngle )
                                       MoveSteps ( sx )
                                       RotateRight( sAngle )
                                     cnt4 = cnt4 + 1
                                     end
                               RotateRight( 90 )
                               cnt3 = cnt3 + 1
                               end
                         redraw()
                         RotateRight( 30 )
                         cnt2 = cnt2 +1
                         end
            sx = sx + 4
            end
    sAngle = sAngle + 1
    redraw()
    wait(2000)
    cnt = cnt + 1

    key = getkey()
    if key == 32 then cnt2 = 70 end
    end

closewindow()             -- This ends the program.




[code]
[/code]
Title: Re: EGSL Samples
Post by: Tomaaz on May 25, 2013, 01:34:32 pm
Hi Rick! Nice examples (especially the second one). You could use my turtle library (http://retrogamecoding.org/board/index.php?topic=9.0) for them. Myself, I'll try to experiment with your second code and flood fill to get some nice results.

I hope you will stay here and be an active member. This place really needs new cool code examples. ;)
Title: Re: EGSL Samples
Post by: Rick3137 on May 27, 2013, 01:06:34 pm
  Hey Tomaaz
      I like your Turtle library. I needed it 6 weeks ago. The functions I now use are designed to fit the Scratch programming language, so I will need to stay with those. Thanks.
Title: Re: EGSL Samples
Post by: Rick3137 on May 28, 2013, 03:49:02 pm
 Here is my version of the Koch snowflake with some code borrowed from Tomaaz





Code: [Select]
-- Koch Snowflake
 -- Thanks to Tomaas for the piece of code
--  http://rb23.yolasite.com/
pendown = 0  cnt = 0  PenX = 0  PenY = 0  Angle2 = 0  x2 = 0  y2 = 0  dx = 0
 dy = 0 Angle3 = 0 Angle4 =0 test = 0 d = 0 cnt2 = 0 red =0 green = 0 blue = 0
 key = 0 x1 =0  y1=0
                -- Create functions at start of program
                -- 1 Radian = 57.2958 Degrees.
                -- 1 degree = .0174532925 Radians
                -- math degrees = 450 - compass
function SetColor() color (red,green,blue) end
function ChangeColor(n)
    blue = blue + n
    if blue > 255 then blue = 0 ; green = green + 1 end
    if green > 255 then green = 0 ; red = red + 1 end
    if red > 255 then green = 0 ; red = 0 blue =0 end
    color (red,green,blue)
 end
function GotoXY(x,y)  PenX = x ; PenY = y end
function RotateRight(n)
         Angle = Angle + n

               if  Angle > 360  then  Angle = Angle - 360   end
               if Angle == 360 then Angle = 0 end


end
function RotateLeft(n)
         if  Angle == n  then Angle = 0  n = 0 end
         if Angle > n  then
         Angle = Angle - n

         else  Angle = n - Angle  Angle = 360 - Angle

         end





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 == 450 then n = 90 end
    if n > 450 then n = n - 360 end

    return n
end
 function MoveSteps (n)                 -- move n steps using Angle
     Angle = floor(Angle)
     x1 = 500 + PenX
     y1 = 300 - PenY
     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 "
      dx = dx* 10000  dx = floor(dx) dx = dx/10000
     dy = sin (Angle3) dy = dy* 10000  dy = floor(dy) dy = dy/10000
     x2 = x1 + dx * n
     y2 = y1 - dy * n
     x1=round(x1) y1=round(y1) x2=round(x2) y2=round(y2)
     if pendown == 1 then line(x1,y1,x2,y2) end
     PenX = PenX + dx * n   PenY = PenY + dy * n
     return PenX
 end

 function test( a1,a2)         -- Use for debugging
       MoveSteps (100)  RotateLeft(90)  MoveSteps (100)   RotateLeft(90)  MoveSteps (100)  RotateLeft(90)  MoveSteps (100)  RotateLeft(90)
        MoveSteps (100)  RotateLeft(90)  MoveSteps (100)
      drawtext( 50,40,"lp,st ")  drawtext(200,40,"                " ) drawtext(210,40,a1 )    drawtext(350,40,"              ")    drawtext(370,40,a2 )
      drawtext(50,60,"lp,st ")     drawtext(200,60,"     ")    drawtext(350,60,"      ")   drawtext(200,60,lp)    drawtext(350,60,st)
      drawtext(50,80,"PenX,PenY ")     drawtext(200,80,"      ")    drawtext(350,80,"       ")  drawtext(200,80, PenX )    drawtext(350,80, PenY )
      drawtext (50,100, Angle )
      drawtext (50,120, Angle2 )


  end
  function Fractal (Distance, Loop)
if Loop > 0 then
Loop = Loop - 1
Distance = Distance / 3
Fractal (Distance, Loop)
RotateLeft(60)
Fractal (Distance, Loop)
RotateRight(120)
Fractal (Distance, Loop)
RotateLeft(60)
Fractal (Distance, Loop)
else
MoveSteps (3 * Distance)


end

   end



      -- Starts Program
      screen (1200,700,32," Fractal ")

      d = 135
      PenX = -150  PenY = 165
      Angle = 90
      color (25,22,255)
      backcolor (0,0,50)
      clearscreen()
      redraw()

            pendown = 1
            Fractal( d , 6 )
            RotateRight(90)
            Fractal( d , 6 )
            RotateRight(90)
            Fractal( d , 6 )
            RotateRight(90)
            Fractal( d , 6 )



      pendown = 0
      redraw()
      wait(1000)


      inkey()
      closewindow()     -- This ends the program.


















Title: Re: EGSL Samples
Post by: Rick3137 on May 29, 2013, 01:38:08 pm
                                      Fuzzy Fractals

Code: [Select]
      --  This program written by        and Rick3137 at
      --  Scratch.mit.edu

pendown = 0  cnt = 0  PenX = 0  PenY = 0  Angle2 = 0  x2 = 0  y2 = 0  dx = 0
 dy = 0 Angle3 = 0 Angle4 =0 test = 0 d = 0 cnt2 = 0 red =0 green = 0 blue = 0
 key = 0 x1 =0  y1=0
                -- Create functions at start of program
                -- 1 Radian = 57.2958 Degrees.
                -- 1 degree = .0174532925 Radians
                -- math degrees = 450 - compass
function SetColor() color (red,green,blue) end
function ChangeColor(n)
    blue = blue + n
    if blue > 255 then blue =50 ; green = green + 1 end
    if green > 255 then green = 50 ; red = red + 1 end
    if red > 255 then green = 0 ; red = 50 blue = 0 end
    color (red,green,blue)
 end
function GotoXY(x,y)  PenX = x ; PenY = y end
function RotateRight(n)
         Angle = Angle + n

               if  Angle > 360  then  Angle = Angle - 360   end
               if Angle == 360 then Angle = 0 end


end
function RotateLeft(n)
         if  Angle == n  then Angle = 0  n = 0 end
         if Angle > n  then
         Angle = Angle - n

         else  Angle = n - Angle  Angle = 360 - Angle

         end





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 == 450 then n = 90 end
    if n > 450 then n = n - 360 end

    return n
end
 function MoveSteps (n)                 -- move n steps using Angle
     x1 = 500 + PenX
     y1 = 300 - PenY
     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 = x1 + dx * n
     y2 = y1 - dy * n
     if pendown == 1 then line(x1,y1,x2,y2) end
     PenX = PenX + dx * n   PenY = PenY + dy * n
 end

 function test( a1,a2)         -- Use for debugging
       MoveSteps (100)  RotateLeft(90)  MoveSteps (100)   RotateLeft(90)  MoveSteps (100)  RotateLeft(90)  MoveSteps (100)  RotateLeft(90)
        MoveSteps (100)  RotateLeft(90)  MoveSteps (100)
      drawtext( 50,40,"lp,st ")  drawtext(200,40,"                " ) drawtext(210,40,a1 )    drawtext(350,40,"              ")    drawtext(370,40,a2 )
      drawtext(50,60,"lp,st ")     drawtext(200,60,"     ")    drawtext(350,60,"      ")   drawtext(200,60,lp)    drawtext(350,60,st)
      drawtext(50,80,"PenX,PenY ")     drawtext(200,80,"      ")    drawtext(350,80,"       ")  drawtext(200,80, PenX )    drawtext(350,80, PenY )
      drawtext (50,100, Angle )
      drawtext (50,120, Angle2 )


  end
  function Fractal ( Loop , Distance )
   local cnt = 0
if Loop > 0 then

            while cnt < c2
            do
                MoveSteps ( Distance )
        RotateRight( AngleR )
Fractal (Loop - 1 , Distance / n1 )
                cnt = cnt + 1
            end
         Loop = Loop - 1
end
   ChangeColor(20)
   end

      -- Starts Program
      screen (1200,700,32," Fuzzy Fractals ")

      d = 600  c1 = 7  c2 = 6  n1 = 2  Angle = 270  AngleR = 120
      PenX = 350  PenY = -300
      color (100,0,200)
      backcolor (0,0,20)
      clearscreen()
      redraw()
      pendown = 1
      Fractal( c1 , d )    redraw() inkey() clearscreen() redraw()
      d = 300  c1 = 4  c2 = 6  n1 = 3  Angle = 270  AngleR = 60
      PenX = 100  PenY = -300  Fractal( c1 , d ) redraw() inkey() clearscreen() redraw()
      d = 300  c1 = 6  c2 = 6  n1 = 3  Angle = 270  AngleR = 90
      PenX = 300  PenY = 100  Fractal( c1 , d )redraw()  inkey() clearscreen() redraw()
      d = 500  c1 = 6  c2 = 8  n1 = 2.2  Angle = 270  AngleR = 90
      PenX = 300  PenY = -300  Fractal( c1 , d )redraw() inkey() clearscreen() redraw()
      d = 500  c1 = 4  c2 = 12  n1 = 1.5  Angle = 270  AngleR = 150
      PenX = 200  PenY = -100  Fractal( c1 , d ) redraw() inkey() clearscreen() redraw()
      d = 600  c1 = 4  c2 = 15  n1 = 1.5  Angle = 270  AngleR = 150
      PenX = 200  PenY = 0  Fractal( c1 , d ) redraw() inkey() clearscreen() redraw()
      d = 600  c1 = 5  c2 = 8  n1 = 3  Angle = 270  AngleR = 150
      PenX = 300  PenY = -100  Fractal( c1 , d ) redraw() inkey() clearscreen() redraw()
        d = 300  c1 = 6  c2 = 6  n1 = 2  Angle = 270  AngleR = 264
        PenX = 200  PenY = 100  Fractal( c1 , d ) redraw() inkey() clearscreen() redraw()
        d = 600  c1 = 4  c2 = 15  n1 = 2.5  Angle = 270  AngleR = 150
        PenX = 300  PenY = 100  Fractal( c1 , d ) redraw() inkey() clearscreen() redraw()
        d = 200  c1 = 4  c2 = 15  n1 = 2.5  Angle = 270  AngleR = 278
         PenX = 300  PenY = -100  Fractal( c1 , d ) redraw() inkey() clearscreen() redraw()
        d = 200  c1 = 5  c2 = 8  n1 = 2.5  Angle = 270  AngleR = 45
        PenX = 200  PenY = -300  Fractal( c1 , d ) redraw() inkey() clearscreen() redraw()
        d = 600  c1 = 4  c2 = 15  n1 = 3.5  Angle = 270  AngleR = 150
        PenX = 300  PenY = 100  Fractal( c1 , d ) redraw() inkey() clearscreen() redraw()
        d = 600  c1 = 4  c2 = 15  n1 = 2.6  Angle = 270  AngleR = 150
        PenX = 300  PenY = 100  Fractal( c1 , d ) redraw() inkey() clearscreen() redraw()

      closewindow()     -- This ends the program.


















Title: Re: EGSL Samples
Post by: Rick3137 on May 29, 2013, 01:44:15 pm
                                     Cloud Fractal

 
Code: [Select]
      --  This program written by    Rick3137
      --  http://rb23.yolasite.com/

pendown = 0  cnt = 0  PenX = 0  PenY = 0  Angle2 = 0  x2 = 0  y2 = 0  dx = 0
 dy = 0 Angle3 = 0 Angle4 =0 test = 0 d = 0 cnt2 = 0 red =0 green = 0 blue = 0
 key = 0 x1 =0  y1=0
                -- Create functions at start of program
                -- 1 Radian = 57.2958 Degrees.
                -- 1 degree = .0174532925 Radians
                -- math degrees = 450 - compass
function SetColor() color (red,green,blue) end
function ChangeColor(n)
    blue = blue + n
    if blue > 255 then blue =50 ; green = green + 1 end
    if green > 255 then green = 50 ; red = red + 1 end
    if red > 255 then green = 0 ; red = 50 blue = 0 end
    color (red,green,blue)
 end
function GotoXY(x,y)  PenX = x ; PenY = y end
function RotateRight(n)
         Angle = Angle + n

               if  Angle > 360  then  Angle = Angle - 360   end
               if Angle == 360 then Angle = 0 end


end
function RotateLeft(n)
         if  Angle == n  then Angle = 0  n = 0 end
         if Angle > n  then
         Angle = Angle - n

         else  Angle = n - Angle  Angle = 360 - Angle

         end





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 == 450 then n = 90 end
    if n > 450 then n = n - 360 end

    return n
end
 function MoveSteps (n)                 -- move n steps using Angle
     x1 = 500 + PenX
     y1 = 300 - PenY
     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 = x1 + dx * n
     y2 = y1 - dy * n
     if pendown == 1 then line(x1,y1,x2,y2) end
     PenX = PenX + dx * n   PenY = PenY + dy * n
 end

 function test( a1,a2)         -- Use for debugging
       MoveSteps (100)  RotateLeft(90)  MoveSteps (100)   RotateLeft(90)  MoveSteps (100)  RotateLeft(90)  MoveSteps (100)  RotateLeft(90)
        MoveSteps (100)  RotateLeft(90)  MoveSteps (100)
      drawtext( 50,40,"lp,st ")  drawtext(200,40,"                " ) drawtext(210,40,a1 )    drawtext(350,40,"              ")    drawtext(370,40,a2 )
      drawtext(50,60,"lp,st ")     drawtext(200,60,"     ")    drawtext(350,60,"      ")   drawtext(200,60,lp)    drawtext(350,60,st)
      drawtext(50,80,"PenX,PenY ")     drawtext(200,80,"      ")    drawtext(350,80,"       ")  drawtext(200,80, PenX )    drawtext(350,80, PenY )
      drawtext (50,100, Angle )
      drawtext (50,120, Angle2 )


  end
  function Fractal ( Loop , Distance )
   local cnt = 0
if Loop > 0 then

            while cnt < c2
            do

                MoveSteps ( Distance/5 )
        RotateRight( 90 )
                MoveSteps ( Distance* .40 )
                Fractal (Loop - 1 , Distance /2)
                MoveSteps ( Distance* .40 )
                RotateLeft(90)
                MoveSteps ( Distance/3 )
                RotateRight( 90 )

                MoveSteps ( Distance/5 )  Fractal (Loop - 1 , Distance /3)
                RotateRight( 90 )
                MoveSteps ( Distance/3 )
                RotateLeft(90)

                MoveSteps ( Distance/3 )
                RotateRight( 90 )
                MoveSteps ( Distance/5 )   Fractal (Loop - 1 , Distance /3)
                RotateRight( 90 )
                MoveSteps ( Distance/3 )
                RotateLeft(90)

                MoveSteps ( Distance/3 )
                RotateRight( 90 )
                MoveSteps ( Distance/5 )   Fractal (Loop - 1 , Distance /3)
                RotateRight( 90 )
                MoveSteps ( Distance/3 )
                RotateLeft(90)
                MoveSteps ( Distance* .40 )
                Fractal (Loop - 1 , Distance /2)
                MoveSteps ( Distance* .40 )
                RotateRight( 90 )

                cnt = cnt + 1
                RotateRight( 90 )
            end
         Loop = Loop - 1
end
   ChangeColor(10)
   end

      -- Starts Program
      screen (1200,700,32," Fuzzy Fractals ")

      d = 200  c1 = 4  c2 = 4    Angle = 270
      PenX = 0  PenY =-100
      color (100,100,200)
      backcolor (0,0,20)
      clearscreen()
      redraw()
      pendown = 1
      Fractal( c1 , d )    redraw() inkey() clearscreen() redraw()




      closewindow()     -- This ends the program.


















Title: Re: EGSL Samples
Post by: Rick3137 on May 30, 2013, 12:07:53 am
                                          Star Polygon

Code: [Select]
      --  This program written by  leszpio and  Rick3137 at
      --  Scratch.mit.edu

pendown = 0  cnt = 0  PenX = 0  PenY = 0  Angle2 = 0  x2 = 0  y2 = 0  dx = 0
 dy = 0 Angle3 = 0 Angle4 =0 test = 0 d = 0 cnt2 = 0 red =0 green = 0 blue = 0
 key = 0 x1 =0  y1=0
                -- Create functions at start of program
                -- 1 Radian = 57.2958 Degrees.
                -- 1 degree = .0174532925 Radians
                -- math degrees = 450 - compass
function SetColor() color (red,green,blue) end
function SetColor2(n)
         red = n * 10
         green = n * 12
         blue = n * 14


color (red,green,blue)
end
function ChangeColor(n)
    blue = blue + n
    if blue > 255 then blue =50 ; green = green + 1 end
    if green > 255 then green = 50 ; red = red + 1 end
    if red > 255 then green = 0 ; red = 50 blue = 0 end
    color (red,green,blue)
 end
function GotoXY(x,y)  PenX = x ; PenY = y end
function RotateRight(n)
         Angle = Angle + n

               if  Angle > 360  then  Angle = Angle - 360   end
               if Angle == 360 then Angle = 0 end


end
function RotateLeft(n)
         if  Angle == n  then Angle = 0  n = 0 end
         if Angle > n  then
         Angle = Angle - n

         else  Angle = n - Angle  Angle = 360 - Angle

         end





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 == 450 then n = 90 end
    if n > 450 then n = n - 360 end

    return n
end
 function MoveSteps (n)                 -- move n steps using Angle
     x1 = 600 + PenX
     y1 = 350 - PenY
     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 = x1 + dx * n
     y2 = y1 - dy * n
     if pendown == 1 then line(x1,y1,x2,y2) end
     PenX = PenX + dx * n   PenY = PenY + dy * n
 end

 function test( a1,a2)         -- Use for debugging
       MoveSteps (100)  RotateLeft(90)  MoveSteps (100)   RotateLeft(90)  MoveSteps (100)  RotateLeft(90)  MoveSteps (100)  RotateLeft(90)
        MoveSteps (100)  RotateLeft(90)  MoveSteps (100)
      drawtext( 50,40,"lp,st ")  drawtext(200,40,"                " ) drawtext(210,40,a1 )    drawtext(350,40,"              ")    drawtext(370,40,a2 )
      drawtext(50,60,"lp,st ")     drawtext(200,60,"     ")    drawtext(350,60,"      ")   drawtext(200,60,lp)    drawtext(350,60,st)
      drawtext(50,80,"PenX,PenY ")     drawtext(200,80,"      ")    drawtext(350,80,"       ")  drawtext(200,80, PenX )    drawtext(350,80, PenY )
      drawtext (50,100, Angle )
      drawtext (50,120, Angle2 )


  end


      -- Starts Program
      screen (1200,700,32," Fuzzy Fractals ")

      n = 1  Angle = 270  AngleR = 120 k = 0  i = 6
      PenX = 0  PenY = 0 cnt = 0 cnt2 = 0 cnt3 = 0
      color (100,0,200)
      backcolor (0,0,20)
      clearscreen()
      redraw()
      pendown = 1
      while cnt < 6
      do
            clearscreen()
            redraw()
            k =  4 * n + 3
            cnt2 = 0
                 while cnt2 < 360/ i
                 do
                 cnt3 = 0
                       while cnt3 < k
                       do
                       MoveSteps(280)
                       RotateRight( 180 - 180 / k )
                       cnt3 = cnt3 + 1
                       redraw()
                       end
                 RotateLeft( i )
                 --ChangeColor( 200 )
                 SetColor2(cnt2)
                 cnt2 = cnt2 + 1
                 end
            wait(2000)
            i = i - 1
            n = n + 1
            cnt = cnt + 1
      end
      inkey()
      closewindow()     -- This ends the program.


















Title: Re: EGSL Samples
Post by: Mopz on May 31, 2013, 04:49:37 pm
All these examples look great :)
Title: Re: EGSL Samples
Post by: Rick3137 on June 01, 2013, 03:12:29 pm
                                       Board game and 2d array demo

  This demo shows how to build a game board and keeps track of which column and row the mouse is pointing at.
  It also shows how to build a 2d array to keep track of board data. EGSL does not have built-in arrays like other languages . You have to build your own.

Code: [Select]
      -- By Rick3137  http://rb23.yolasite.com/

      function MakeSquare( row , column )

       local x = 200 local y = -40 local x2 = 0 local y2 = 0
       color (25,225,200)
       x = x + column * 70    y = y + row * 70  x2 = x + 67 y2 = y + 67
       fillbox (x,y,x2,y2)
       color (25,150,150)
       line (x,y,x2,y)  line (x2,y,x2,y2)  line (x2,y2,x,y2)  line (x+1,y2,x+1,y)
       line (x+3,y2,x+3,y)
        for a = 1 , 18 do
          x=x+2 y=y+2 x2 = x2-2 y2 = y2-2
          line (x,y,x2,y)  line (x2,y,x2,y2)  line (x2,y2,x+3,y2)  line (x+3,y2,x+3,y+3)
        end
      end

      function DisplaySquares()
         local a = 0
         for row = 1,10 do
           for column = 1,10 do
               a =  BoardArray [ row ][ column ]
               if a == 0 then MakeSquare ( row , column ) end
           end
         end
      end

      function MakeBoard()
                     color (0,0,0)
                     fillbox(250,20,980,740   )
                     color (0,100,100)
                     fillbox(260,25,975,735   )

      end



  -- Starts Program
     cnt = 0 x = 0 y = 0 key = 0 col = 0 rw = 0 x2 = 0 y2 = 0
    screen (1380,760,32," Board Array Demo ")

      backcolor (0,0,80)
      clearscreen()
         BoardArray  = {}          -- create the Array
    for row = 1,10 do
         BoardArray [ row ] = {}     -- create a new row
         for column = 1,10 do
            BoardArray [ row ][ column ] = 0
         end
    end
    -- you now have a 2d array with 100 elements, ready to use.
    for row = 1,10 do
         for column = 1,10 do
            BoardArray [ row ][ column ] = 0
         end
    end
      MakeBoard()
      DisplaySquares()



        while cnt < 10000
          do
             x = mousex() x2 = x - 270
             y = mousey() y2 = y - 30
             col = floor( x2/70 ) + 1
             rw = floor ( y2/70 ) + 1
              clearscreen()
             drawtext (200,100,x)
             drawtext (200,120,y)
             drawtext (200,140,col)
             drawtext (200,160,rw)
             drawtext (100,100,"x")
             drawtext (100,120,"y")
             drawtext (100,140,"column")
             drawtext (100,160,"row")
             drawtext (40,200,"Hold down Spacebar to end ")
             MakeBoard()
             DisplaySquares()
             redraw()
             wait (100)
             key = getkey()
             if key == 32 then break end
             cnt = cnt + 1
          end

    --  redraw()
      inkey()
      closewindow()     -- This ends the program.




















Title: Re: EGSL Samples
Post by: Rick3137 on June 08, 2013, 12:06:53 am
                                          Explore Fractals
 What makes this program so interesting, is that every time you change a number, you get another fractal you have not seen before. It is possible to spend hours looking for new ones.
 Change the variables d,c1,c2,n1,and AngleR to see new fractals. I throw most away, but some can be interesting.

Code: [Select]
      --  This program written by       Rick3137
      --   http://rb23.yolasite.com/

pendown = 0  cnt = 0  PenX = 0  PenY = 0  Angle2 = 0  x2 = 0  y2 = 0  dx = 0
 dy = 0 Angle3 = 0 Angle4 =0 test = 0 d = 0 cnt2 = 0 red =0 green = 0 blue = 0
 key = 0 x1 =0  y1=0
                -- Create functions at start of program
                -- 1 Radian = 57.2958 Degrees.
                -- 1 degree = .0174532925 Radians
                -- math degrees = 450 - compass
function SetColor() color (red,green,blue) end
function ChangeColor(n)
    blue = blue + n
    if blue > 255 then blue =50 ; green = green + 1 end
    if green > 255 then green = 50 ; red = red + 1 end
    if red > 255 then green = 0 ; red = 50 blue = 0 end
    color (red,green,blue)
 end
function GotoXY(x,y)  PenX = x ; PenY = y end
function RotateRight(n)
         Angle = Angle + n

               if  Angle > 360  then  Angle = Angle - 360   end
               if Angle == 360 then Angle = 0 end


end
function RotateLeft(n)
         if  Angle == n  then Angle = 0  n = 0 end
         if Angle > n  then
         Angle = Angle - n

         else  Angle = n - Angle  Angle = 360 - Angle

         end





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 == 450 then n = 90 end
    if n > 450 then n = n - 360 end

    return n
end
 function MoveSteps (n)                 -- move n steps using Angle
     x1 = 500 + PenX
     y1 = 300 - PenY
     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 = x1 + dx * n
     y2 = y1 - dy * n
     if pendown == 1 then line(x1,y1,x2,y2) end
     PenX = PenX + dx * n   PenY = PenY + dy * n
 end

 function test( a1,a2)         -- Use for debugging
       MoveSteps (100)  RotateLeft(90)  MoveSteps (100)   RotateLeft(90)  MoveSteps (100)  RotateLeft(90)  MoveSteps (100)  RotateLeft(90)
        MoveSteps (100)  RotateLeft(90)  MoveSteps (100)
      drawtext( 50,40,"lp,st ")  drawtext(200,40,"                " ) drawtext(210,40,a1 )    drawtext(350,40,"              ")    drawtext(370,40,a2 )
      drawtext(50,60,"lp,st ")     drawtext(200,60,"     ")    drawtext(350,60,"      ")   drawtext(200,60,lp)    drawtext(350,60,st)
      drawtext(50,80,"PenX,PenY ")     drawtext(200,80,"      ")    drawtext(350,80,"       ")  drawtext(200,80, PenX )    drawtext(350,80, PenY )
      drawtext (50,100, Angle )
      drawtext (50,120, Angle2 )


  end
  function Fractal ( Loop , Distance )
   local cnt = 0
if Loop > 0 then

            while cnt < c2
            do
                MoveSteps ( Distance )
        RotateRight( AngleR )
Fractal (Loop - 1 , Distance / n1 )
                cnt = cnt + 1
            end
         Loop = Loop - 1
end
   ChangeColor(20)

   end

      -- Starts Program
      screen (1200,700,32," Explore Fractals ")

      d = 250  c1 = 6  c2 = 5  n1 = 2  Angle = 270  AngleR = 45
      PenX = 250  PenY = -150
      color (100,0,200)
      backcolor (0,0,20)
      clearscreen()
      redraw()
      pendown = 1
      Fractal( c1 , d )    drawtext (10,120, " HIT SPACEBAR TO SEE NEXT FRACTAL " )  redraw() inkey() clearscreen() redraw()
      d = 300  c1 = 4  c2 = 10  n1 = 1.5  Angle = 270  AngleR = 160
      PenX = 150  PenY = 50  Fractal( c1 , d )  drawtext (10,120, " HIT SPACEBAR TO SEE NEXT FRACTAL " )
       redraw() inkey() clearscreen() redraw()
      d = 350  c1 = 6  c2 = 8  n1 = 2  Angle = 270  AngleR = 290
      PenX = 200  PenY = -20  Fractal( c1 , d )  drawtext (10,120, " HIT SPACEBAR TO SEE NEXT FRACTAL " )
      redraw() inkey() clearscreen() redraw()
      d = 600  c1 = 4  c2 = 15  n1 = 2  Angle = 270  AngleR = 150
      PenX = 400  PenY = 50  Fractal( c1 , d )  drawtext (10,120, " HIT SPACEBAR TO SEE NEXT FRACTAL " )
      redraw() inkey() clearscreen() redraw()
      d = 200  c1 = 4  c2 = 8  n1 = 2  Angle = 270  AngleR = 293
      PenX = 300  PenY = -200  Fractal( c1 , d )  drawtext (10,120, " HIT SPACEBAR TO SEE NEXT FRACTAL " )
      redraw()  inkey() clearscreen() redraw()
      d = 500  c1 = 4  c2 = 8  n1 = 2  Angle = 270  AngleR = 150
      PenX = 300  PenY = 50  Fractal( c1 , d )  drawtext (10,120, " HIT SPACEBAR TO SEE NEXT FRACTAL " )
      redraw() inkey() clearscreen() redraw()

      d = 600  c1 = 3  c2 = 15  n1 = 1.5  Angle = 270  AngleR = 150
      PenX = 300  PenY = -100  Fractal( c1 , d )   drawtext (10,120, " HIT SPACEBAR TO SEE NEXT FRACTAL " )
      redraw() inkey() clearscreen() redraw()
      d = 600  c1 = 5  c2 = 8  n1 = 3  Angle = 270  AngleR = 150
      PenX = 300  PenY = -100  Fractal( c1 , d )  drawtext (10,120, " HIT SPACEBAR TO SEE NEXT FRACTAL " )
       redraw() inkey() clearscreen() redraw()
        d = 300  c1 = 6  c2 = 6  n1 = 2  Angle = 270  AngleR = 264
        PenX = 200  PenY = 100  Fractal( c1 , d )   drawtext (10,120, " HIT SPACEBAR TO SEE NEXT FRACTAL " )
         redraw() inkey() clearscreen() redraw()
        d = 600  c1 = 4  c2 = 15  n1 = 2.5  Angle = 270  AngleR = 150
        PenX = 300  PenY = 100  Fractal( c1 , d )  drawtext (10,120, " HIT SPACEBAR TO SEE NEXT FRACTAL " )
         redraw() inkey() clearscreen() redraw()
        d = 200  c1 = 4  c2 = 15  n1 = 2.5  Angle = 270  AngleR = 278
         PenX = 300  PenY = -100  Fractal( c1 , d )  drawtext (10,120, " HIT SPACEBAR TO SEE NEXT FRACTAL " )
         redraw() inkey() clearscreen() redraw()
        d = 200  c1 = 5  c2 = 8  n1 = 2.5  Angle = 270  AngleR = 45
        PenX = 200  PenY = -300  Fractal( c1 , d )  drawtext (10,120, " HIT SPACEBAR TO SEE NEXT FRACTAL " )
         redraw() inkey() clearscreen() redraw()
        d = 600  c1 = 4  c2 = 15  n1 = 3.5  Angle = 270  AngleR = 150
        PenX = 300  PenY = 100  Fractal( c1 , d )  drawtext (10,120, " HIT SPACEBAR TO SEE NEXT FRACTAL " )
         redraw() inkey() clearscreen() redraw()
        d = 600  c1 = 4  c2 = 15  n1 = 2.6  Angle = 270  AngleR = 150
        PenX = 300  PenY = 100  Fractal( c1 , d )  drawtext (10,120, " HIT SPACEBAR TO SEE NEXT FRACTAL " )
         redraw() inkey() clearscreen() redraw()

      closewindow()     -- This ends the program.


















Title: Re: EGSL Samples
Post by: Rick3137 on July 04, 2013, 01:42:30 pm
    This is an example of a simple paint algorithm for painting with EGSL. If it looks too complicated
it is because of my bad programming style. I have a relative, who is a professional C-sharp
programmer who says that my style is too messy.

   It may need touching up . If you fill like fixing it , please post a copy for me to see.

   The program first draws a simple pentagon fractal, that you can paint by clicking with the mouse
button. Left and right arrow keys change the color.

My website:http://rb23.yolasite.com/ (http://rb23.yolasite.com/)

Code: [Select]
      --  This program written by       Rick3137
      --   http://rb23.yolasite.com/

pendown = 0  cnt = 0  PenX = 0  PenY = 0  Angle2 = 0  x2 = 0  y2 = 0  dx = 0
 dy = 0 Angle3 = 0 Angle4 =0 test = 0 d = 0 cnt2 = 0
 key = 0 x1 =0  y1=0   Gcolor = 1  level = 1  mx =1 my = 1  DrawColor = 1
                -- Create functions at start of program
                -- 1 Radian = 57.2958 Degrees.
                -- 1 degree = .0174532925 Radians
                -- math degrees = 450 - compass
function SetColor(clr)
if clr > 99 then clr = 1 end
if clr == 0 then clr = 1 end
                                if clr < 0 then clr = 1 end
if clr == 1 then  color (10, 10, 255) end
if clr == 2 then  color (60, 60, 255) end
if clr == 3 then  color (30, 60, 250) end
if clr == 4 then  color (40, 80, 240) end
if clr == 5 then  color (50, 100, 230) end
if clr == 6 then  color (60, 120, 230) end
if clr == 7 then  color (70, 140, 220) end
if clr == 8 then  color (80, 160, 220) end
if clr == 9 then  color (90, 180, 200) end
if clr == 10 then color (150, 255, 255) end
if clr == 11 then color (120, 230, 255) end
if clr == 12 then color (120, 210, 255) end
if clr == 13 then color (120, 180, 255) end
if clr == 14 then color (120, 160, 255) end
if clr == 15 then color (20, 140, 255) end
if clr == 16 then color (20, 255, 230) end
if clr == 17 then color (20, 255, 190) end
if clr == 18 then color (20, 255, 170) end
if clr == 19 then color (20, 255, 140) end
if clr == 20 then color (20, 255, 120) end
if clr == 21 then color (0, 255, 100)  end
if clr == 22 then color (0, 255, 90)   end
if clr == 23 then color (0, 235, 80)   end
if clr == 24 then color (0, 205, 70)   end
if clr == 25 then color (0, 90, 60)   end
if clr == 26 then color (0, 255, 50)   end
if clr == 27 then color (0, 245, 40)   end
if clr == 28 then color (0, 225, 30)   end
if clr == 29 then color (0, 215, 20)   end
if clr == 30 then color (0, 205, 10)   end
if clr == 31 then color (235, 255, 10) end
if clr == 32 then color (215, 255, 20) end

if clr == 33 then color (95, 255, 30)  end
if clr == 34 then color (255, 235, 40)  end
if clr == 35 then color (255, 215, 50)  end
if clr == 36 then color (255, 95, 60)  end
if clr == 37 then color (255, 85, 70)  end
if clr == 38 then color (255, 75, 80)  end
if clr == 39 then color (155, 155, 90)  end
if clr == 40 then color (155, 255, 100) end
if clr == 41 then color (255, 10, 255)  end
if clr == 42 then color (255, 40, 255)  end
if clr == 43 then color (255, 60, 255)  end
if clr == 44 then color (255, 80, 255)  end
if clr == 45 then color (255, 110, 255)  end
if clr == 46 then color (235, 60, 235)  end
if clr == 47 then color (215, 70, 215)  end
if clr == 48 then color (195, 80, 255)  end
if clr == 49 then color (255, 90, 195)  end
                                if clr == 50 then color (165, 90, 165)  end
                                if clr == 51 then  color (10, 20, 255) end
if clr == 52 then  color (40, 40, 255) end
if clr == 53 then  color (80, 80, 255) end
if clr == 54 then  color (40, 80, 255) end
if clr == 55 then  color (50, 100, 255) end
if clr == 56 then  color (60, 120, 255) end
if clr == 57 then  color (70, 140, 255) end
if clr == 58 then  color (80, 160, 255) end
if clr == 59 then  color (90, 180, 255) end
if clr == 60 then color (150, 200, 255) end
if clr == 61 then color (10, 255, 255) end
if clr == 62 then color (20, 235, 235) end
if clr == 63 then color (30, 215, 215) end
if clr == 64 then color (40, 255, 215) end
if clr == 65 then color (50, 215, 255) end
if clr == 66 then color (60, 95, 95) end
if clr == 67 then color (70, 255, 95) end
if clr == 68 then color (80, 95, 255) end
if clr == 69 then color (90, 155, 155) end
if clr == 70 then color (100, 255, 255) end
if clr == 71 then color (0, 255, 200)  end
if clr == 72 then color (0, 255, 180)   end
if clr == 73 then color (0, 255, 160)   end
if clr == 74 then color (0, 255, 140)   end
if clr == 75 then color (0, 255, 120)   end
if clr == 76 then color (0, 255, 50)   end
if clr == 77 then color (0, 215, 40)   end
if clr == 78 then color (50, 255, 30)   end
if clr == 79 then color (90, 255, 20)   end
if clr == 80 then color (110, 255, 10)   end
if clr == 81 then color (255, 255, 10) end
if clr == 82 then color (255, 255, 20) end

if clr == 83 then color (255, 255, 30)  end
if clr == 84 then color (255, 255, 40)  end
if clr == 85 then color (255, 255, 50)  end
if clr == 86 then color (255, 255, 60)  end
if clr == 87 then color (255, 255, 70)  end
if clr == 88 then color (255, 255, 80)  end
if clr == 89 then color (255, 255, 90)  end
if clr == 90 then color (255, 255, 100) end
if clr == 91 then color (255, 10, 255)  end
if clr == 92 then color (255, 20, 255)  end
if clr == 93 then color (255, 30, 255)  end
if clr == 94 then color (255, 40, 255)  end
if clr == 95 then color (255, 50, 255)  end
if clr == 96 then color (255, 60, 255)  end
if clr == 97 then color (255, 70, 255)  end
if clr == 98 then color (255, 80, 255)  end
if clr == 99 then color (255, 90, 255)  end


end

function ChangeColor(n)
     Gcolor = Gcolor + n
     if Gcolor > 99 then Gcolor = 1 end
     SetColor (Gcolor)
 end
function GotoXY(x,y)  PenX = x ; PenY = y end
function RotateRight(n)
         Angle = Angle + n

               if  Angle > 360  then  Angle = Angle - 360   end
               if Angle == 360 then Angle = 0 end


end
function RotateLeft(n)
         if  Angle == n  then Angle = 0  n = 0 end
         if Angle > n   then
         Angle = Angle - n

         else  Angle = n - Angle  Angle = 360 - Angle

         end





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 == 450 then n = 90 end
    if n > 450 then n = n - 360 end

    return n
end
 function MoveSteps (n)                 -- move n steps using Angle
     x1 = 500 + PenX
     y1 = 300 - PenY
     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 = x1 + dx * n
     y2 = y1 - dy * n
     if pendown == 1 then line(x1,y1,x2,y2) end
     PenX = PenX + dx * n   PenY = PenY + dy * n
 end


  function Fractal ( Distance )
            local cnt = 0

            while cnt < c2
            do
                MoveSteps ( Distance )
        RotateRight( AngleR )
Fractal2 ( Distance / n1 )
                cnt = cnt + 1
            end


   end
   function Fractal2 ( Distance )
            local cnt = 0

            while cnt < c2
            do
                MoveSteps ( Distance )
        RotateRight( AngleR )
-- Fractal ( Distance / n1 )
                cnt = cnt + 1
            end


   end
     function Fractal3 ( Distance )
            local cnt = 0

            while cnt < c2
            do
                MoveSteps ( Distance )
        RotateRight( AngleR )
-- Fractal ( Distance / n1 )
                cnt = cnt + 1
            end


   end
     function Fractal4 ( Distance )
            local cnt = 0

            while cnt < c2
            do
                MoveSteps ( Distance )
        RotateRight( AngleR )
-- Fractal ( Distance / n1 )
                cnt = cnt + 1
            end



   end
     function Paint( x1,y1 )
        local x2 = x1
        Paint2(x1,y1)
              while x1 < 1200
              do
                x1 = x1 + 1
                red = screenred ( x1,y1 )
                if red == 100 then break end
                dot (x1,y1)
                Paint2(x1,y1)

              end
              Paint3(x1-1,y1)
               while x2 > 0
              do
                x2 = x2 - 1
                red = screenred ( x2,y1 )
                if red == 100 then break end
                dot (x2,y1)
                Paint2(x2,y1)
              end
              Paint3(x2+1,y1)

     end
     function Paint2( x1,y1 )
        local y2 = y1
              while y1 < 700
              do

                red = screenred ( x1,y1 )
                if red == 100 then break end
                dot (x1,y1)
                 y1 = y1 + 1
              end
               while y2 > 0
              do

                red = screenred ( x1,y2 )
                if red == 100 then break end
                dot (x1,y2)
                y2 = y2 - 1
              end


     end

     function Paint3( x1,y1)
            local y2 = y1
            while y1 < 700
              do
                Paint4(x1,y1)
                red = screenred ( x1,y1 )
                if red == 100 then break end
                dot (x1,y1)
                 y1 = y1 + 1
              end

                while y2 > 0
              do
                Paint4(x1,y2)
                red = screenred ( x1,y2 )
                if red == 100 then break end
                dot (x1,y2)
                y2 = y2 - 1
              end
     end
      function Paint4( x1,y1 )
        local x2 = x1

              while x1 < 1200
              do
                red = screenred ( x1,y1 )
                if red == 100 then break end
                x1 = x1 + 1
                red = screenred ( x1,y1 )
                if red == 100 then break end
                dot (x1,y1)
              end

               while x2 > 0
              do
                red = screenred ( x2,y1 )
                if red == 100 then break end
                x2 = x2 - 1
                red = screenred ( x2,y1 )
                if red == 100 then break end
                dot (x2,y1)

              end

     end

     function SetColorBox (clr)
         SetColor(clr)
         fillbox (10,250,110,350)  -- x,y,x2,y2
         DrawColor = clr
     end

      -- Starts Program
      screen (1200,700,32," Pentagon ")

      d = 400   c2 = 5  n1 = 2  Angle = 270  AngleR = 72
      PenX = 250  PenY = -350
      color (100,150,255)
      backcolor (23,0,40)
      clearscreen()
      redraw()
      pendown = 1
      Fractal( d )
      SetColorBox(1)

     repeat

        key=getkey()
        if key > 0 then key2 = key end
        if key == 275 then
            DrawColor = DrawColor + 1
            SetColorBox (DrawColor)
            end
        if key == 276 then
            DrawColor = DrawColor - 1
            SetColorBox (DrawColor)
            end
        mx=mousex()
        my=mousey()
        red=screenred (mx,my)
        SetColor( DrawColor )
        if mouseb()==1 then
            dot (mx,my) ;
            Paint ( mx,my )

        end
        color (0,0,30)
        fillbox (10,10,100,200)
        color (255,255,255)
        drawtext (50,100, mx )
        drawtext (50,120, my )
        drawtext (50,140, red )
        drawtext (50,160, mouseb())
        drawtext (50,180, key2 )

         wait (1)
         redraw()
     until key==27



      closewindow()     -- This ends the program.

















   
Title: Re: EGSL Samples
Post by: Aurel on July 14, 2013, 10:12:58 pm
Hello Rick..
Do you maybe have in your 'fractal arsenal' something like minkowski fractal ?
Title: Re: EGSL Samples
Post by: Tomaaz on July 14, 2013, 11:39:05 pm
Do you maybe have in your 'fractal arsenal' something like minkowski fractal ?

It's another fractal you can draw using recursion:

Code: [Select]
require "turtle"
openwindow (580, 460, 0, "Minkowski Fractal")
setbgcolour("grey")
goxy (50, 200)
turnright(90)
function mink(x, t)
if t > 0 then
t=t-1
x=x/8
mink(x, t)
turnleft(90)
mink(x, t)
turnright(90)
mink(x, t)
turnright(90)
mink(x, t)
mink(x, t)
turnleft(90)
mink(x, t)
turnleft(90)
mink(x, t)
turnright(90)
mink(x, t)
else
forward(50*x)
end
end
setcolour("white")
mink(150, 4)
inkey()
Title: Re: EGSL Samples
Post by: Aurel on July 15, 2013, 05:44:17 am
Hej Tomek ;D
But this is not a Minkowski which i need for my fractal antenna research .
It looks similar but i need something like is presented on wikipedia....hmmmmm
Title: Re: EGSL Samples
Post by: Tomaaz on July 15, 2013, 07:23:45 pm
Hej Tomek ;D
But this is not a Minkowski which i need for my fractal antenna research .
It looks similar but i need something like is presented on wikipedia....hmmmmm

http://en.wikipedia.org/wiki/List_of_fractals_by_Hausdorff_dimension . The only one Minkowski Fractal is Minkowski Sausage that looks like... my example. Could you post an image?
Title: Re: EGSL Samples
Post by: Aurel on July 15, 2013, 07:33:53 pm
There are images of created antenna and minkowski fractal from wikipedia...
Yes i see,your image present hausdorf fractal 'so called minkowski sousage'.right?
Title: Re: EGSL Samples
Post by: Aurel on July 15, 2013, 08:47:25 pm
Tomek
something is wrong with egsl or with your turtle lib...
egsl run code but i see just a flash of window and then is window closed ..
what is this ???

i receive this errors:
Quote
C:\Program Files\EGSL\minkowski.lua:3: attempt to call global 'setbgcolour' (a nil value)
C:\Program Files\EGSL\minkowski.lua:3: attempt to call global 'setbgcolour' (a nil value)
C:\Program Files\EGSL\minkowski.lua:3: attempt to call global 'setbgcolour' (a nil value)
C:\Program Files\EGSL\minkowski.lua:3: unfinished string near ''setbgcolour("grey")'
C:\Program Files\EGSL\minkowski.lua:28: attempt to call global 'setcolour' (a nil value)
Title: Re: EGSL Samples
Post by: Tomaaz on July 15, 2013, 10:40:55 pm
Tomek
something is wrong with egsl or with your turtle lib...
egsl run code but i see just a flash of window and then is window closed ..
what is this ???

You probably have an old version of the library. The new one is attached.

I will have a look at the fractal and let you know soon.

Title: Re: EGSL Samples
Post by: Tomaaz on July 16, 2013, 12:06:11 am
Something like this?

Code: [Select]
require "turtle"
openwindow (500, 500, 0, "Minkowski Fractal")
setbgcolour("grey")
goxy (20, 20)
turnright(90)
function mink(x, t)
if t > 0 then
t=t-1
x=x/3
mink(x, t)
turnright(90)
mink(x, t)
turnleft(90)
mink(x, t)
turnleft(90)
mink(x, t)
turnright(90)
mink(x, t)
else
forward(x * 3)
end
end
setcolour("white")

for x = 1, 4 do
mink(150, 5)
turnright(90)
end
inkey()

Change values in line 26
Quote
mink(150, 5)
to get different size (the first parameter) and depth (the second). You can also use setredraw() function to make the program work much faster.
Title: Re: EGSL Samples
Post by: Aurel on July 16, 2013, 06:10:36 am
Yes i see...
It work great...
i will try translate this to Oxygen that i see is it little bit faster maybe..
thanks Tomek ;)
Title: Re: EGSL Samples
Post by: Tomaaz on July 16, 2013, 09:51:09 am
.
i will try translate this to Oxygen that i see is it little bit faster maybe..

Try this version. It's much faster.

Code: [Select]
require "turtle"
openwindow (500, 500, 0, "Minkowski Fractal")
setbgcolour("grey")
goxy (20, 20)
turnright(90)
setredraw(0)
function mink(x, t)
if t > 0 then
t=t-1
x=x/3
mink(x, t)
turnright(90)
mink(x, t)
turnleft(90)
mink(x, t)
turnleft(90)
mink(x, t)
turnright(90)
mink(x, t)
else
forward(x * 3)
end
end
setcolour("white")

for x = 1, 4 do
mink(150, 5)
turnright(90)
end
redraw()
inkey()
Title: Re: EGSL Samples
Post by: Aurel on July 16, 2013, 06:15:02 pm
Tomek...
I have EGSL 1.6.0
but i don't know why command setredraw() not work ???
Title: Re: EGSL Samples
Post by: Tomaaz on July 16, 2013, 06:57:41 pm
I have EGSL 1.6.0
but i don't know why command setredraw() not work ???

It's part of my turtle library, not EGSL itself, so make sure that you have the last version of the library (I attached it to the one of my previous posts in this topic). setredraw(0) disables automatic refreshing screen after forward() or fill() is called (you do it manually by using EGSL refresh() function whenever you want), setredraw(1) enables it.
Title: Re: EGSL Samples
Post by: Aurel on July 17, 2013, 05:47:13 am
Ahhh finaly work, yeah i see what for u use setredraw, for me is more cool setredraw(1)  ;)
anyway lua is fast enough.

BUT one thing really pissed me off everytime when i use EGSL IDE,it automaticaly
put me on 'My Documents' folder and this thing repeat all the time when user open new
file from disk...this is a really annoying.
I will make my own editor for EGSL because this one really drive me crazy ::)
Title: Re: EGSL Samples
Post by: Tomaaz on July 17, 2013, 10:37:03 am
...for me is more cool setredraw(1)  ;)

I made it default option, because this is what Logo should be about. ;)

BUT one thing really pissed me off everytime when i use EGSL IDE,it automaticaly
put me on 'My Documents' folder and this thing repeat all the time when user open new
file from disk...this is a really annoying.
I will make my own editor for EGSL because this one really drive me crazy ::)

Just use Geany. Syntax highlighting, code folding, side panel with functions and variables and many more.
Title: Re: EGSL Samples
Post by: Aurel on July 17, 2013, 05:08:48 pm
Tomek
sorry and don't get me wrong again ;)
You know that i hate this Geany editor, i have this editor by default on my SliTaz computer
and i quickly switch to gVim, maybe for you it is a great solution ,but for me is not.
Anyway i don't know that Cyb add source code written in Lazarus for EGSL IDE
in repo,maybe i can do something there ..i will see.
Title: Re: EGSL Samples
Post by: Tomaaz on July 17, 2013, 06:54:51 pm
You know that i hate this Geany editor...

I know. I just don't know why. ;)

Anyway i don't know that Cyb add source code written in Lazarus for EGSL IDE
in repo,maybe i can do something there ..i will see.

You can download source code from there (http://www.egsl.retrogamecoding.org//modules/download_gallery/dlc.php?file=27).
Title: Re: EGSL Samples
Post by: Aurel on July 17, 2013, 07:06:33 pm
Yes i know...
hmm i see EGSL IDE is based on LazEdit, looks interesting ...
hmm so if i want to fix this 'open' problem i must download Lazarus
eeehhh, ok i will see... ;)
Title: Re: EGSL Samples
Post by: Aurel on July 21, 2013, 06:06:59 pm
Ok
I finally made Oxygen version.
I try to use turtle lib as include file but it looks that i can't
becuse lib must have drawline() api call in my case ,so i add
turtle functions as part of program.
As you may see complete code is only with native Windows GDI api.
Hmm speed of ececution is almost same as with lua api.

Code: [Select]
include "awinh.inc"
#lookahead
INT win
'GLOBALS for drawing to DC -------------------------------------------- 
INT hdc, hdcMem, hbmMem,   oldBmp, oldBrush, oldPen, oldFont, fColor,bColor
INT textX,textY,hBrush
INT ww,hh
INT wstyle = WS_MINMAXSIZE Or WS_CLIPCHILDREN
'create main window ****************************************************
win = SetWindow("Minkowski",40,40,600,550,0,wstyle)
InitDrawing(win)

sys k, posx, posy

goxy (20, 20)
turnright(90)

Function Mink(sys x, t) as sys
    if t > 0.2
t=t-1
x=x/3

TextColor win,RGB(x,130,190)
Mink(x, t)
turnright(90)

Mink(x, t)
turnleft(90)

TextColor win,RGB(150,x,180)
Mink(x, t)
turnleft(90)

    Mink(x,t)
    turnright(90)

Mink(x, t)
     else
  forward(x*6)
     end if
End Function

for x = 1 to 4
    Mink(140,4)
    turnright(90)
next

'------------------------------------------------------------------------
Wait()
'------------------------------------------------------------------------
Function WndProc (byval hwnd as long,byval wMsg as long, byval wParam as long,byval lparam as long) as long callback

Select hwnd
'>>>>>>>>>>>>>>>>>>>>>>>>>

Case win
'>>>>>>>>>>>>>>>>>>>><<<
Select wMsg
'----------------------------
CASE WM_PAINT
BitBlt(hDC, 0, 0, ww, hh, hdcMem, 0, 0, SRCCOPY)
'----------------------------
Case WM_CLOSE
If win <> 0
     CleanUp()
CloseWindow(win)
EndProgram
End If
End Select

End Select

Return Default

End Function

'-------------------------------------------------------------------------
'================================================
SUB InitDrawing(byval wnd as INT)
'INT ww,hh
''get current size of window
GetSize(wnd,0,0,ww,hh)
'get window DC
hdc=GetDC(wnd)
hdcMem = CreateCompatibleDC(0)
hbmMem = CreateCompatibleBitmap(hdc, ww, hh)
oldBmp = SelectObject( hdcMem, hbmMem )
oldBrush = SelectObject(hdcMem, CreateSolidBrush( RGB(231,223,231)) )
oldPen = SelectObject(hdcMem, CreatePen(PS_SOLID,1,RGB(231,223,231)))
'fill rectangle memDC with brush color
FillRect ( hdcMem,rc, oldBrush)
SetTextColor( hDC,RGB(0,0,0))
SetBkColor( hDC, RGB(231,223,231))
'blit to memDC
BitBlt(hDCmem, 0, 0, ww, hh, hdc, 0, 0, SRCCOPY)

ReleaseDC( wnd, hdc)
End SUB

'=================================================
SUB TextColor (wID as INT,byval frontColor as sys)
hdc = GetDC(wID)
sys bColor
fColor=frontColor
bColor = RGB(231,223,231)
SetTextColor( hDC, frontColor)
SetBkColor( hDC, bColor)

BitBlt(hDCmem, 0, 0, ww, hh, hdc, 0, 0, SRCCOPY)

ReleaseDC( wID, hdc)

End SUB
'=================================================
Sub TextOn( int wnd,sys x, y, string txt)
'INT ww,hh
hdc=GetDC(wnd)
GetSize(wnd,0,0,ww,hh)
TextOut sys_hdc,x,y,txt,Len(txt)
BitBlt(hDCmem, 0, 0, ww, hh, hdc, 0, 0, SRCCOPY)
ReleaseDC(wnd,Hdc)
End Sub

'=================================================
SUB LineXY (wID as INT,Lx as INT,Ly as INT,Lx1 as INT,Ly1 as INT)

hdc = GetDC(wID)
GetSize(wID,0,0,ww,hh)
SelectObject(hdc, CreatePen(PS_SOLID,1,fColor))

MoveToEx hdc,Lx,Ly,Byval 0
LineTo hdc,Lx1,Ly1

BitBlt(hDCmem, 0, 0, ww, hh, hdc, 0, 0, SRCCOPY)
ReleaseDC( wID, hdc)
End SUB
'=================================================
SUB Pset (wID as int , px as int ,py as int)
hdc = GetDC(wID)
'GetSize(wID,0,0,ww,hh)
SetPixel ( hdc, px, py, fColor)

BitBlt(hDCmem, 0, 0, ww, hh, hdc, 0, 0, SRCCOPY)

ReleaseDC( wID, hdc)

End SUB
'//////////////////////////////////////////////
SUB CleanUp
DeleteDC(hdcMem)
DeleteObject(SelectObject(hdcMem, oldBrush))
DeleteObject(SelectObject(hdcMem, oldPen))
DeleteObject(SelectObject(hdcMem, oldBmp))
End SUB
'/////////////////////////////////////////////

'************************************
'    TURTLE FUNCTIONS               
'************************************
Function forward(sys d) as sys
    sys a, b, x, y
    a = sin(k * pi / 180) * d
    b = cos(k * pi / 180) * d
    x = posx + a
    y = posy - b
    LineXY (win,posx, posy, x, y)
    posx = x
    posy = y
End Function
'------------------------------------------
Function backward(sys d) as sys
    sys a, b, x, y
    a = sin(k * pi / 180) * d
    b = cos(k * pi / 180) * d
    x = posx - a
    y = posy + b
    LineXY(win,posx, posy, x, y)
    posx = x
    posy = y
End Function
'-------------------------------------------
Function turnright(sys z) as sys
    k = k + z
    if k > 360
        k = k - 360
    end if
    if k < 0
        k = k + 360
    end if
End Function
'---------------------------------------------
Function turnleft(sys z) as sys
    k = k - z
    if k > 360
        k = k - 360
    end if
    if k < 0
        k = k + 360
    end if
End Function
'----------------------------------------------
Function penup(sys drawing) as sys
    return drawing
End Function
'----------------------------------------------
Function goxy(sys zx, zy) as sys
    posx=zx
    posy=zy
End Function
'----------------------------------------------