История изменений
Исправление LINUX-ORG-RU, (текущая версия) :
Это не совсем для моделирования, на этом игры делают. Ну и физика Box2D
Просто даже такой грубой симуляции для как у вас называется «численного эксперимента» вроде. Ну когда там вещи симулируются в очень условных границах, но даже их хватает чтобы отразить суть. Вот тут так же получается.
Вот уж доделал, (нашёл API функцию получения текущей угловой скорости для палочек)
Ютуб блин принудительно shorts сделал….
local world = { }
local objects = { }
local function reset_scene(minlen,maxlen)
love.physics.setMeter(64)
world = love.physics.newWorld(0, 0.4*64, true)
---
objects.ground = { }
objects.ground.body = love.physics.newBody(world, 200, 800)
---
objects.ground.shape = love.physics.newRectangleShape(400, 50)
objects.ground.fixture =
love.physics.newFixture(objects.ground.body, objects.ground.shape)
local start = -2000
for i=1,12 do
objects['l_plank_'..i] = { }
objects['l_plank_'..i].body = love.physics.newBody(world,200,start+maxlen*i,'dynamic')
objects['l_plank_'..i].shape = love.physics.newRectangleShape(200,5)
love.physics.newFixture(objects['l_plank_'..i].body,
objects['l_plank_'..i].shape)
end
local cnt = 1
local l , r = minlen,maxlen
for i=1,11 do
objects['l_joint_'..cnt+0] =
love.physics.newRopeJoint(objects['l_plank_'..i+0].body,
objects['l_plank_'..i+1].body,
100,(start+maxlen*i),100,(start+maxlen*(i+1)),l,true)
objects['l_joint_'..cnt+1] =
love.physics.newRopeJoint(objects['l_plank_'..i+0].body,
objects['l_plank_'..i+1].body,
300,(start+maxlen*i),300,(start+maxlen*(i+1)),r,true)
cnt = cnt + 2
l , r = r, l
end
---
for i=1,12 do
objects['r_plank_'..i] = { }
objects['r_plank_'..i].body = love.physics.newBody(world,600,start+maxlen*i,'dynamic')
objects['r_plank_'..i].shape = love.physics.newRectangleShape(200,5)
love.physics.newFixture(objects['r_plank_'..i].body,
objects['r_plank_'..i].shape)
end
---
local cnt = 1
local l , r = maxlen, minlen
for i=1,11 do
objects['r_joint_'..cnt+0] =
love.physics.newRopeJoint(objects['r_plank_'..i+0].body,
objects['r_plank_'..i+1].body,
500,(start+maxlen*i),500,(start+maxlen*(i+1)),l,true)
objects['r_joint_'..cnt+1] =
love.physics.newRopeJoint(objects['r_plank_'..i+0].body,
objects['r_plank_'..i+1].body,
700,(start+maxlen*i),700,(start+maxlen*(i+1)),r,true)
cnt = cnt + 2
l , r = r, l
end
end
function love.load()
love.window.setTitle('#####')
love.window.setMode(800,1000)
---
reset_scene(50,200)
love.graphics.setLineWidth(1)
end
function love.update(dt)
world:update(dt)
end
function love.keypressed(key)
if key == '1' then
reset_scene(50,200)
end
if key == '2' then
reset_scene(200,200)
end
end
function love.draw()
love.graphics.polygon("fill",
objects.ground.body:getWorldPoints(objects.ground.shape:getPoints()))
for i=1,12 do
local w = math.abs(objects['l_plank_'..i].body:getAngularVelocity( ))
love.graphics.setColor(0.5+(w*2), 0.5-(w*2), 0.5-(w*2))
love.graphics.polygon("fill",
objects['l_plank_'..i].body:
getWorldPoints(objects['l_plank_'..i].shape:getPoints()))
end
for i=1,12 do
local w = math.abs(objects['r_plank_'..i].body:getAngularVelocity( ))
love.graphics.setColor(0.5+(w*2), 0.5-(w*2), 0.5-(w*2))
love.graphics.polygon("fill",
objects['r_plank_'..i].body:
getWorldPoints(objects['r_plank_'..i].shape:getPoints()))
end
love.graphics.setColor(0, 1, 0)
for i=1,22 do
love.graphics.line(objects['l_joint_'..i]:getAnchors())
end
for i=1,22 do
love.graphics.line(objects['r_joint_'..i]:getAnchors())
end
local x, y = objects['r_joint_1']:getAnchors()
love.graphics.line(0,y,800,y)
love.graphics.setColor(1, 1, 1)
love.graphics.print(
"Press 1 for variant 1\n\nPress 2 for variant 2",310,50,0,1.5,1.5)
end
Исправление LINUX-ORG-RU, :
Это не совсем для моделирования, на этом игры делают. Ну и физика Box2D
Просто даже такой грубой симуляции для как у вас называется «численного эксперимента» вроде. Ну когда там вещи симулируются в очень условных границах, но даже их хватает что-бы отразить суть. Вот тут так же получается.
Вот уж доделал, (нашёл API функцию получения текущей угловой скорости для палочек)
Ютуб блин принудительно shorts сделал….
local world = { }
local objects = { }
local function reset_scene(minlen,maxlen)
love.physics.setMeter(64)
world = love.physics.newWorld(0, 0.4*64, true)
---
objects.ground = { }
objects.ground.body = love.physics.newBody(world, 200, 800)
---
objects.ground.shape = love.physics.newRectangleShape(400, 50)
objects.ground.fixture =
love.physics.newFixture(objects.ground.body, objects.ground.shape)
local start = -2000
for i=1,12 do
objects['l_plank_'..i] = { }
objects['l_plank_'..i].body = love.physics.newBody(world,200,start+maxlen*i,'dynamic')
objects['l_plank_'..i].shape = love.physics.newRectangleShape(200,5)
love.physics.newFixture(objects['l_plank_'..i].body,
objects['l_plank_'..i].shape)
end
local cnt = 1
local l , r = minlen,maxlen
for i=1,11 do
objects['l_joint_'..cnt+0] =
love.physics.newRopeJoint(objects['l_plank_'..i+0].body,
objects['l_plank_'..i+1].body,
100,(start+maxlen*i),100,(start+maxlen*(i+1)),l,true)
objects['l_joint_'..cnt+1] =
love.physics.newRopeJoint(objects['l_plank_'..i+0].body,
objects['l_plank_'..i+1].body,
300,(start+maxlen*i),300,(start+maxlen*(i+1)),r,true)
cnt = cnt + 2
l , r = r, l
end
---
for i=1,12 do
objects['r_plank_'..i] = { }
objects['r_plank_'..i].body = love.physics.newBody(world,600,start+maxlen*i,'dynamic')
objects['r_plank_'..i].shape = love.physics.newRectangleShape(200,5)
love.physics.newFixture(objects['r_plank_'..i].body,
objects['r_plank_'..i].shape)
end
---
local cnt = 1
local l , r = maxlen, minlen
for i=1,11 do
objects['r_joint_'..cnt+0] =
love.physics.newRopeJoint(objects['r_plank_'..i+0].body,
objects['r_plank_'..i+1].body,
500,(start+maxlen*i),500,(start+maxlen*(i+1)),l,true)
objects['r_joint_'..cnt+1] =
love.physics.newRopeJoint(objects['r_plank_'..i+0].body,
objects['r_plank_'..i+1].body,
700,(start+maxlen*i),700,(start+maxlen*(i+1)),r,true)
cnt = cnt + 2
l , r = r, l
end
end
function love.load()
love.window.setTitle('#####')
love.window.setMode(800,1000)
---
reset_scene(50,200)
love.graphics.setLineWidth(1)
end
function love.update(dt)
world:update(dt)
end
function love.keypressed(key)
if key == '1' then
reset_scene(50,200)
end
if key == '2' then
reset_scene(200,200)
end
end
function love.draw()
love.graphics.polygon("fill",
objects.ground.body:getWorldPoints(objects.ground.shape:getPoints()))
for i=1,12 do
local w = math.abs(objects['l_plank_'..i].body:getAngularVelocity( ))
love.graphics.setColor(0.5+(w*2), 0.5-(w*2), 0.5-(w*2))
love.graphics.polygon("fill",
objects['l_plank_'..i].body:
getWorldPoints(objects['l_plank_'..i].shape:getPoints()))
end
for i=1,12 do
local w = math.abs(objects['r_plank_'..i].body:getAngularVelocity( ))
love.graphics.setColor(0.5+(w*2), 0.5-(w*2), 0.5-(w*2))
love.graphics.polygon("fill",
objects['r_plank_'..i].body:
getWorldPoints(objects['r_plank_'..i].shape:getPoints()))
end
love.graphics.setColor(0, 1, 0)
for i=1,22 do
love.graphics.line(objects['l_joint_'..i]:getAnchors())
end
for i=1,22 do
love.graphics.line(objects['r_joint_'..i]:getAnchors())
end
local x, y = objects['r_joint_1']:getAnchors()
love.graphics.line(0,y,800,y)
love.graphics.setColor(1, 1, 1)
love.graphics.print(
"Press 1 for variant 1\n\nPress 2 for variant 2",310,50,0,1.5,1.5)
end
Исправление LINUX-ORG-RU, :
Это не совсем для моделирования, на этом игры делают. Ну и физика Box2D
Просто даже такой грубой симуляции для как у вас называется «численного эксперимента» вроде. Ну когда там вещи симулируются в очень условных границах, но даже их хватает что-бы отразить суть. Вот тут так же получается.
Вот уж доделал, (нашёл API функцию получения текущей угловой скорости для палочек)
Ютуб казёл принудительно shorts сделал….
local world = { }
local objects = { }
local function reset_scene(minlen,maxlen)
love.physics.setMeter(64)
world = love.physics.newWorld(0, 0.4*64, true)
---
objects.ground = { }
objects.ground.body = love.physics.newBody(world, 200, 800)
---
objects.ground.shape = love.physics.newRectangleShape(400, 50)
objects.ground.fixture =
love.physics.newFixture(objects.ground.body, objects.ground.shape)
local start = -2000
for i=1,12 do
objects['l_plank_'..i] = { }
objects['l_plank_'..i].body = love.physics.newBody(world,200,start+maxlen*i,'dynamic')
objects['l_plank_'..i].shape = love.physics.newRectangleShape(200,5)
love.physics.newFixture(objects['l_plank_'..i].body,
objects['l_plank_'..i].shape)
end
local cnt = 1
local l , r = minlen,maxlen
for i=1,11 do
objects['l_joint_'..cnt+0] =
love.physics.newRopeJoint(objects['l_plank_'..i+0].body,
objects['l_plank_'..i+1].body,
100,(start+maxlen*i),100,(start+maxlen*(i+1)),l,true)
objects['l_joint_'..cnt+1] =
love.physics.newRopeJoint(objects['l_plank_'..i+0].body,
objects['l_plank_'..i+1].body,
300,(start+maxlen*i),300,(start+maxlen*(i+1)),r,true)
cnt = cnt + 2
l , r = r, l
end
---
for i=1,12 do
objects['r_plank_'..i] = { }
objects['r_plank_'..i].body = love.physics.newBody(world,600,start+maxlen*i,'dynamic')
objects['r_plank_'..i].shape = love.physics.newRectangleShape(200,5)
love.physics.newFixture(objects['r_plank_'..i].body,
objects['r_plank_'..i].shape)
end
---
local cnt = 1
local l , r = maxlen, minlen
for i=1,11 do
objects['r_joint_'..cnt+0] =
love.physics.newRopeJoint(objects['r_plank_'..i+0].body,
objects['r_plank_'..i+1].body,
500,(start+maxlen*i),500,(start+maxlen*(i+1)),l,true)
objects['r_joint_'..cnt+1] =
love.physics.newRopeJoint(objects['r_plank_'..i+0].body,
objects['r_plank_'..i+1].body,
700,(start+maxlen*i),700,(start+maxlen*(i+1)),r,true)
cnt = cnt + 2
l , r = r, l
end
end
function love.load()
love.window.setTitle('#####')
love.window.setMode(800,1000)
---
reset_scene(50,200)
love.graphics.setLineWidth(1)
end
function love.update(dt)
world:update(dt)
end
function love.keypressed(key)
if key == '1' then
reset_scene(50,200)
end
if key == '2' then
reset_scene(200,200)
end
end
function love.draw()
love.graphics.polygon("fill",
objects.ground.body:getWorldPoints(objects.ground.shape:getPoints()))
for i=1,12 do
local w = math.abs(objects['l_plank_'..i].body:getAngularVelocity( ))
love.graphics.setColor(0.5+(w*2), 0.5-(w*2), 0.5-(w*2))
love.graphics.polygon("fill",
objects['l_plank_'..i].body:
getWorldPoints(objects['l_plank_'..i].shape:getPoints()))
end
for i=1,12 do
local w = math.abs(objects['r_plank_'..i].body:getAngularVelocity( ))
love.graphics.setColor(0.5+(w*2), 0.5-(w*2), 0.5-(w*2))
love.graphics.polygon("fill",
objects['r_plank_'..i].body:
getWorldPoints(objects['r_plank_'..i].shape:getPoints()))
end
love.graphics.setColor(0, 1, 0)
for i=1,22 do
love.graphics.line(objects['l_joint_'..i]:getAnchors())
end
for i=1,22 do
love.graphics.line(objects['r_joint_'..i]:getAnchors())
end
local x, y = objects['r_joint_1']:getAnchors()
love.graphics.line(0,y,800,y)
love.graphics.setColor(1, 1, 1)
love.graphics.print(
"Press 1 for variant 1\n\nPress 2 for variant 2",310,50,0,1.5,1.5)
end
Исходная версия LINUX-ORG-RU, :
Это не совсем для моделирования, на этом игры делают. Ну и физика Box2D
Просто даже такой грубой симуляции для как у вас называется «численного эксперимента» вроде. Ну когда там вещи симулируются в очень условных границах, но даже их хватает что-бы отразить суть. Вот тут так же получается.
Вот уж доделал, (нашёл API функцию получения текущей угловой скорости для палочек)
local world = { }
local objects = { }
local function reset_scene(minlen,maxlen)
love.physics.setMeter(64)
world = love.physics.newWorld(0, 0.4*64, true)
---
objects.ground = { }
objects.ground.body = love.physics.newBody(world, 200, 800)
---
objects.ground.shape = love.physics.newRectangleShape(400, 50)
objects.ground.fixture =
love.physics.newFixture(objects.ground.body, objects.ground.shape)
local start = -2000
for i=1,12 do
objects['l_plank_'..i] = { }
objects['l_plank_'..i].body = love.physics.newBody(world,200,start+maxlen*i,'dynamic')
objects['l_plank_'..i].shape = love.physics.newRectangleShape(200,5)
love.physics.newFixture(objects['l_plank_'..i].body,
objects['l_plank_'..i].shape)
end
local cnt = 1
local l , r = minlen,maxlen
for i=1,11 do
objects['l_joint_'..cnt+0] =
love.physics.newRopeJoint(objects['l_plank_'..i+0].body,
objects['l_plank_'..i+1].body,
100,(start+maxlen*i),100,(start+maxlen*(i+1)),l,true)
objects['l_joint_'..cnt+1] =
love.physics.newRopeJoint(objects['l_plank_'..i+0].body,
objects['l_plank_'..i+1].body,
300,(start+maxlen*i),300,(start+maxlen*(i+1)),r,true)
cnt = cnt + 2
l , r = r, l
end
---
for i=1,12 do
objects['r_plank_'..i] = { }
objects['r_plank_'..i].body = love.physics.newBody(world,600,start+maxlen*i,'dynamic')
objects['r_plank_'..i].shape = love.physics.newRectangleShape(200,5)
love.physics.newFixture(objects['r_plank_'..i].body,
objects['r_plank_'..i].shape)
end
---
local cnt = 1
local l , r = maxlen, minlen
for i=1,11 do
objects['r_joint_'..cnt+0] =
love.physics.newRopeJoint(objects['r_plank_'..i+0].body,
objects['r_plank_'..i+1].body,
500,(start+maxlen*i),500,(start+maxlen*(i+1)),l,true)
objects['r_joint_'..cnt+1] =
love.physics.newRopeJoint(objects['r_plank_'..i+0].body,
objects['r_plank_'..i+1].body,
700,(start+maxlen*i),700,(start+maxlen*(i+1)),r,true)
cnt = cnt + 2
l , r = r, l
end
end
function love.load()
love.window.setTitle('#####')
love.window.setMode(800,1000)
---
reset_scene(50,200)
love.graphics.setLineWidth(1)
end
function love.update(dt)
world:update(dt)
end
function love.keypressed(key)
if key == '1' then
reset_scene(50,200)
end
if key == '2' then
reset_scene(200,200)
end
end
function love.draw()
love.graphics.polygon("fill",
objects.ground.body:getWorldPoints(objects.ground.shape:getPoints()))
for i=1,12 do
local w = math.abs(objects['l_plank_'..i].body:getAngularVelocity( ))
love.graphics.setColor(0.5+(w*2), 0.5-(w*2), 0.5-(w*2))
love.graphics.polygon("fill",
objects['l_plank_'..i].body:
getWorldPoints(objects['l_plank_'..i].shape:getPoints()))
end
for i=1,12 do
local w = math.abs(objects['r_plank_'..i].body:getAngularVelocity( ))
love.graphics.setColor(0.5+(w*2), 0.5-(w*2), 0.5-(w*2))
love.graphics.polygon("fill",
objects['r_plank_'..i].body:
getWorldPoints(objects['r_plank_'..i].shape:getPoints()))
end
love.graphics.setColor(0, 1, 0)
for i=1,22 do
love.graphics.line(objects['l_joint_'..i]:getAnchors())
end
for i=1,22 do
love.graphics.line(objects['r_joint_'..i]:getAnchors())
end
local x, y = objects['r_joint_1']:getAnchors()
love.graphics.line(0,y,800,y)
love.graphics.setColor(1, 1, 1)
love.graphics.print(
"Press 1 for variant 1\n\nPress 2 for variant 2",310,50,0,1.5,1.5)
end