Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
37
Task/Fractal-tree/Lua/fractal-tree-1.lua
Normal file
37
Task/Fractal-tree/Lua/fractal-tree-1.lua
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
g, angle = love.graphics, 26 * math.pi / 180
|
||||
wid, hei = g.getWidth(), g.getHeight()
|
||||
function rotate( x, y, a )
|
||||
local s, c = math.sin( a ), math.cos( a )
|
||||
local a, b = x * c - y * s, x * s + y * c
|
||||
return a, b
|
||||
end
|
||||
function branches( a, b, len, ang, dir )
|
||||
len = len * .76
|
||||
if len < 5 then return end
|
||||
g.setColor( len * 16, 255 - 2 * len , 0 )
|
||||
if dir > 0 then ang = ang - angle
|
||||
else ang = ang + angle
|
||||
end
|
||||
local vx, vy = rotate( 0, len, ang )
|
||||
vx = a + vx; vy = b - vy
|
||||
g.line( a, b, vx, vy )
|
||||
branches( vx, vy, len, ang, 1 )
|
||||
branches( vx, vy, len, ang, 0 )
|
||||
end
|
||||
function createTree()
|
||||
local lineLen = 127
|
||||
local a, b = wid / 2, hei - lineLen
|
||||
g.setColor( 160, 40 , 0 )
|
||||
g.line( wid / 2, hei, a, b )
|
||||
branches( a, b, lineLen, 0, 1 )
|
||||
branches( a, b, lineLen, 0, 0 )
|
||||
end
|
||||
function love.load()
|
||||
canvas = g.newCanvas( wid, hei )
|
||||
g.setCanvas( canvas )
|
||||
createTree()
|
||||
g.setCanvas()
|
||||
end
|
||||
function love.draw()
|
||||
g.draw( canvas )
|
||||
end
|
||||
15
Task/Fractal-tree/Lua/fractal-tree-2.lua
Normal file
15
Task/Fractal-tree/Lua/fractal-tree-2.lua
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
function Bitmap:tree(x, y, angle, depth, forkfn, lengfn)
|
||||
if depth <= 0 then return end
|
||||
local fork, leng = forkfn(), lengfn()
|
||||
local x2 = x + depth * leng * math.cos(angle)
|
||||
local y2 = y - depth * leng * math.sin(angle)
|
||||
self:line(math.floor(x), math.floor(y), math.floor(x2), math.floor(y2))
|
||||
self:tree(x2, y2, angle+fork, depth-1, forkfn, lengfn)
|
||||
self:tree(x2, y2, angle-fork, depth-1, forkfn, lengfn)
|
||||
end
|
||||
|
||||
bitmap = Bitmap(128*3,128)
|
||||
bitmap:tree( 64, 120, math.pi/2, 8, function() return 0.3 end, function() return 3 end)
|
||||
bitmap:tree(192, 120, math.pi/2, 8, function() return 0.6 end, function() return 2.5 end)
|
||||
bitmap:tree(320, 120, math.pi/2, 8, function() return 0.2+math.random()*0.3 end, function() return 2.0+math.random()*2.0 end)
|
||||
bitmap:render({[0x000000]='.', [0xFFFFFFFF]='█'})
|
||||
Loading…
Add table
Add a link
Reference in a new issue