Author Topic: EGSL Samples  (Read 11862 times)

Rick3137

  • Guest
EGSL Samples
« 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)


Rick3137

  • Guest
Re: EGSL Samples
« Reply #1 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()   

     







Rick3137

  • Guest
Re: EGSL Samples
« Reply #2 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]

Tomaaz

  • Guest
Re: EGSL Samples
« Reply #3 on: May 25, 2013, 01:34:32 PM »
Hi Rick! Nice examples (especially the second one). You could use my turtle library 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. ;)
« Last Edit: May 25, 2013, 01:39:20 PM by Tomaaz »

Rick3137

  • Guest
Re: EGSL Samples
« Reply #4 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.

Rick3137

  • Guest
Re: EGSL Samples
« Reply #5 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.



















Rick3137

  • Guest
Re: EGSL Samples
« Reply #6 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.



















Rick3137

  • Guest
Re: EGSL Samples
« Reply #7 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.



















Rick3137

  • Guest
Re: EGSL Samples
« Reply #8 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.



















Mopz

  • Guest
Re: EGSL Samples
« Reply #9 on: May 31, 2013, 04:49:37 PM »
All these examples look great :)

Rick3137

  • Guest
Re: EGSL Samples
« Reply #10 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.





















Rick3137

  • Guest
Re: EGSL Samples
« Reply #11 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.



















Rick3137

  • Guest
Re: EGSL Samples
« Reply #12 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/

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.

















   

Aurel

  • Guest
Re: EGSL Samples
« Reply #13 on: July 14, 2013, 10:12:58 PM »
Hello Rick..
Do you maybe have in your 'fractal arsenal' something like minkowski fractal ?

Tomaaz

  • Guest
Re: EGSL Samples
« Reply #14 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()