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.
-- 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.