Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Jim Bauwens

Pages: 1 ... 22 23 [24] 25 26 ... 125
346
TI-Nspire / Re: Early beta of nspire version string patcher
« on: August 07, 2012, 09:02:42 am »
Glad to see you're still having fun with the Nspire :)
Also, nice application. I wonder, can you spoof the version number that the Student software detects ?
That would be even cooler as you could trick the software that you have a newer version of the OS installed.

347
OmnomIRC Development / Re: Sorunome bug
« on: August 07, 2012, 08:06:37 am »
I think the best would be to fix the bug :P

348
Ndless / Re: General Ndless Questions and Support
« on: August 07, 2012, 06:49:52 am »
Yup.
libndls, the Nspire specific C library: http://hackspire.unsads.com/wiki/index.php/Libndls
The standard C functions that are included: http://hackspire.unsads.com/wiki/index.php/Syscalls

For graphics you can use nSDL or nRGBlib. nRGBlib might be the easiest to use.

349
Other / Re: Arduino's Game of Life
« on: August 07, 2012, 04:01:50 am »
Very nice Nick :)

350
OmnomIRC Development / Re: Spying OmnomIRC PMs
« on: August 03, 2012, 03:21:33 pm »
There shouldn't be a problem anymore, I think I fixed everything.
So go everyone, and share your passwords in peace. Just keep in mind that I can see them anyway.
* Jim Bauwens runs

351
OmnomIRC Development / Re: Spying OmnomIRC PMs
« on: August 03, 2012, 02:08:47 pm »
As far as I can see the bugs are now fixed :)

352
OmnomIRC Development / Re: Spying OmnomIRC PMs
« on: August 03, 2012, 01:13:57 pm »
So you are saying that if you query everyone on OmnomIRC, and some of them start talking together you can view their convo ?
Pretty bad. I'll see if I can understand Netham's code enough in order to create a fix.

353
News / Re: Bust-a-move on PRIZM, Bloxorz on 9860G
« on: August 02, 2012, 04:26:05 am »
Here is the code I found for it:

Spoiler For Code:


-- Bloxorz by Purobaz
-- 48h CPC #4
-- Planete-Casio.fr
-- Thanks to Vebveb for LuaFX
-- useful functions
local prt=graydraw.text
local sub=string.sub
local tonb=base.tonumber
local tostr=misc.tostring2
local wait=misc.wait
-- variables
local level=1
local loop,choice
local nb
local i,j,k
   -- map
local map
local map_info={} -- width, height, x, y
local map_end={}
   -- block
local block={} -- x, y, position (1~3)
local block_move={ -- depend on keys
      {0,-1,1},
      {2,0,3},
      {0,1,1},
      {-1,0,3}
      {0,-2,3},
      {1,0,2},
      {0,1,3},
      {-1,0,2}
      {0,-1,2},
      {1,0,1},
      {0,2,2},
      {-2,0,1}
local block_pst={
   {1,0},
   {0,-1},
   {0,0}
local block_size={
   {0,-6},
   {-3,-6},
   {0,-8}
-- sprites
local sprite_map={
local sprite_block={
--functions
function load_map()
   if level==1 then
      map="111114352333350511111233"
      map_info={8,3,25,30}
      block={1,2,3}
   elseif level==2 then
      map="111114511455555555435335555404114555233112333"
      map_info={9,5,25,30}
      block={6,1,1}
   elseif level==3 then
      map="111111111143555455111111145533404533333333311233311111111111"
      map_info={15,4,25,42}
      block={12,2,2}
   elseif level==4 then
      map="1145511455435334043123311"
      map_info={5,5,25,30}
      block={5,2,3}
   elseif level==5 then
      map="45555433334111141111411112553512504112333"
      map_info={5,8,25,30}
      block={5,2,2}
   elseif level==6 then
      map="1455514043143311411123333"
      map_info={5,5,25,30}
      block={5,5,3}
   elseif level==7 then
      map="455111111145555511112555555551123335535511111250431111112331"
      map_info={10,6,25,30}
      block={2,2,3}
   elseif level==8 then
      map="111111455335511455511455114511455533333114555455511111114504233311111112555111111111111233"
      map_info={15,6,25,40}
      block={2,3,3}
   elseif level==9 then
      map="1411111114111111455114554553350423311233"
      map_info={8,5,25,30}
      block={2,1,3}
   end
function draw_map()
   for j=1,map_info[2],1 do
      for i=1,map_info[1],1 do
         nb=tonb(sub(map,((j-1)*map_info[1]+i),((j-1)*map_info[1]+i)))
         if nb==0 then map_end={i,j}
         elseif nb>1 then
            spritexy map_info[3]+4*i+4*j,map_info[4]+4*j-3*i,sprite_map[nb-1]
            refresh
            wait(1)
         end
      end
   end
function intro()
local stage="
8p8p
8p8p
8p8p
?p?p
?p?p
?p?p
p80( (
P( (`
 0P8p
local number={
`5@=@
`5P=P
`5@=@
`5@=@
   clear nil
   spritexy 14, 20, stage
   spritexy 87, 20, number[int(level/10)+1]
   spritexy 100, 20, number[int(level%10)+1]
   refresh
   wait(30)
function menu()
local menu="
8888(
8888
8888(
@@@@
local cursor="
   clear nil
   spritexy 10, 2, menu
   state(false)
   choice=0
   i=1
   repeat
      clear nil
      state(true)
      spritexy 33, 13+13*i, cursor
      refresh
      repeat
         wait(5)
      until key(5) or key(39) or key(38) or key(36) or key(44)
      if key(39) and i>1 then i=i-1
      elseif key(38) and i<3 then i=i+1
      elseif key(5) then choice=i
      elseif key(36) or key(44) then choice=4
      end
   until choice~=0 -- end of the menu
-- game
function game()
   repeat
      intro()
      load_map()
      clear nil
      draw_map()
      state(false)
      loop=0
      repeat
         clear nil
         state(true)
         spritexy map_info[3]+4*block[1]+4*block[2]+block_size[block[3]][1],map_info[4]+4*block[2]-3*block[1]+block_size[block[3]][2],sprite_block[block[3]]
         refresh
         repeat
            wait(5)
         until key(39) or key(40) or key(38) or key(37) or key(36) or key(44) or key(1)
         if key(1) then
         level=level+1
         loop=1
         elseif key(36) or key(44) then -- exit or menu
            loop=3
         else
            if key(39) then k=1
            elseif key(40) then k=2
            elseif key(38) then k=3
            elseif key(37) then k=4
            end
            block={block[1]+block_move[block[3]][k][1],block[2]+block_move[block[3]][k][2],block_move[block[3]][k][3]} -- move the block
            
            if block[1]==map_end[1] and block[2]==map_end[2] and block[3]==3 then -- winner
               level=level+1
               loop=1
               if level>9 then loop=3 end
            elseif ((block[2]-1)*map_info[1]+block[1])>=1 and ((block[2]-1)*map_info[1]+block[1])<=#map  -- looser
               and ((block[2]-1+block_pst[block[3]][2])*map_info[1]+block[1]+block_pst[block[3]][1])>=1
               and ((block[2]-1+block_pst[block[3]][2])*map_info[1]+block[1]+block_pst[block[3]][1])<=#map then
               if tonb(sub(map,((block[2]-1)*map_info[1]+block[1]),((block[2]-1)*map_info[1]+block[1])))==1
               or tonb(sub(map,((block[2]+block_pst[block[3]][2]-1)*map_info[1]+block[1]+block_pst[block[3]][1]),((block[2]+block_pst[block[3]][2]-1)*map_info[1]+block[1]+block_pst[block[3]][1])))==1 then
                  loop=2
               end
            else loop=2
            end
         end
      until loop~=0 -- end of the stage
      clear nil
      state(true)
      spritexy map_info[3]+4*block[1]+4*block[2]+block_size[block[3]][1],map_info[4]+4*block[2]-3*block[1]+block_size[block[3]][2],sprite_block[block[3]]
      refresh
      wait(10)
   until loop==3 -- end of the game
-- main
graydraw.setcolor(true)
repeat
   menu()
   wait(5)
   if choice==1 then
      level=1
      game()
   --elseif choice==2 then
   --elseif choice==3 then
   end
until choice==4
graydraw.setcolor(false)


It might be a bit corrupted ^^
Anything you recognize ?

354
News / Re: Bust-a-move on PRIZM, Bloxorz on 9860G
« on: August 02, 2012, 04:09:42 am »
I wonder if that Bloxorg clone shares any code with the TI-Nspire Lua version.
Anyway cool :D

355
Other Calculators / Re: Nspire diagnostic software dumper
« on: July 27, 2012, 03:26:30 pm »
Nice find critor :)

356
Lua / Re: Chipmunk Physics
« on: July 26, 2012, 04:08:13 pm »
Yeah, it's indeed a very nice addition :)

However, don't expect super complex and graphically advanced games to be possible :P
It's still a calculator, and the Lua bindings are of course a bit slower than the C one. (This is why Ndless 3.2 will be awesome :D).
But a (good functioning) Angry Birds clone should be possible.

357
Lua / Chipmunk Physics
« on: July 26, 2012, 03:59:10 pm »
Hi all.

3.2 integrates the Chipmunk physics engine with Lua bindings. This allows us create fun games with the physics.
However there is just one problem. It's pretty complex.
So here is some useful info if you want to start programming.

1. The API documentation for 3.2
Download it at http://education.ti.com/nspire/scripting-api .
It's a must have in order to find all the API function names (duh :P )

2. The online chipmunk docs
http://chipmunk-physics.net/release/Chipmunk-5.x/Chipmunk-5.3.4-Docs/
Even though it describes the C API, it shows how the concepts of the engine and how it's structured.
And most Lua functions have similar names to the C ones.
You will find yourself checking this resource often when you start programming with the engine ;)

3. A tutorial (although for the C API)
http://www.alexandre-gomes.com/articles/chipmunk/
This tutorial helps you understand the concepts and inner workings of the physics engine.

4. Example code (by me)
Spoiler For Basic start:


platform.apilevel = '2.0'
require 'physics'


LARGE=physics.misc.INFINITY()
ZERO =physics.Vect(0,0)
------------------
-- Space Object --
------------------

pSpace   = class()

function pSpace:init(gravity)
   self.space = physics.Space()
         :setGravity(physics.Vect(0, gravity))
         :setSleepTimeThreshold(.5)
         
   self.objects   = {}
end

function pSpace:step(n)
   self.space:step(n)
end

function pSpace:addObj(obj, x, y)
   obj.body:setPos(physics.Vect(x, y))
   self.space:addBody(obj.body)
   
   self.space:addShape(obj.shape)
   if obj.added then obj:added(self) end
   
   table.insert(self.objects, obj)
   return self
end

function pSpace:addTerrainObj(obj, x, y)
   obj.body:setPos(physics.Vect(x, y))
   --self.space:addBody(obj.body)
   
   for _, ss in ipairs(obj.segments) do
      self.space:addStaticShape(ss)
   end
   
   table.insert(self.objects, obj)
   return self
end

function pSpace:addStaticObj(obj, x, y)
   obj.body:setPos(physics.Vect(x, y))
   --self.space:addBody(obj.body)
   self.space:addStaticShape(obj.shape)
   
   table.insert(self.objects, obj)
   return self
end

function pSpace:paint(gc)
   for _, obj in ipairs(self.objects) do
      obj:paint(gc)
   end
end

----------------
-- Box Object --
----------------

pBox   = class()

function pBox:init(w,h,mass,color)
   self.h=h
   self.w=w
   self.mass=mass
   self.color=color
   
   self.verts = {
      physics.Vect(-w/2, -h/2),
      physics.Vect(-w/2,  h/2),
      physics.Vect(w/2 ,  h/2),
      physics.Vect(w/2 , -h/2)
   } 
   
   self.body   = physics.Body(1, 1)
   self.body:setMass(mass)
   self.body:setMoment(physics.misc.momentForPoly(mass, self.verts, ZERO))
   self.body:setVel(ZERO)
   
   self.shape = physics.PolyShape(self.body, self.verts, ZERO)

   self.shape:setRestitution(0.6)
   self.shape:setFriction(0.6)
end

function pBox:paint(gc)
   local coords   = self.shape:points()
   local polycoords   = {}
   for k, vert in ipairs(coords) do
      table.insert(polycoords, vert:x())
      table.insert(polycoords, vert:y())
   end   
   local x,y=coords[1]:x(),coords[1]:y()
   table.insert(polycoords, x)
   table.insert(polycoords, y)           

   gc:setColorRGB(self.color)
   gc:fillPolygon(polycoords)
   gc:setColorRGB(0,0,0)
   gc:drawPolyLine(polycoords)
end


-----------------
-- Ball Object --
-----------------

pBall   = class()

function pBall:init(r,mass,color)
   self.r=r
   self.mass=mass
   self.color=color
   
   self.body   = physics.Body(1, 1)
   self.body:setMass(mass)
   self.body:setMoment(physics.misc.momentForCircle(mass, 0, r, ZERO))
   self.body:setVel(ZERO)
   
   self.shape = physics.CircleShape(self.body, r, ZERO)

   self.shape:setRestitution(0.6)
   self.shape:setFriction(0.6)
   --[[
   self.segment = physics.SegmentShape(self.body, physics.Vect(0,-r), physics.Vect(0,0), 1)
    self.segment:setRestitution(0)
   self.segment:setFriction(0)
   --]]
end

function pBall:added(spaceObj)
   --spaceObj.space:addShape(self.segment)
end

function pBall:paint(gc)
   local pos=self.body:pos()
   local x, y = pos:x(), pos:y()
    local r = self.r
         
    gc:setColorRGB(self.color)                           
    gc:fillArc(x-r, y-r, 2*r+1, 2*r+1, 0, 360)
    gc:setColorRGB(0)
    gc:drawArc(x-r, y-r, 2*r, 2*r, 0, 360)
   
    local x2,y2
    local angle=self.body:angle()
    x2   = math.cos(angle)*self.r+x
    y2   = math.sin(angle)*self.r+y
    gc:drawLine(x,y,x2,y2)
end



------------------
-- Terrain code --
------------------

function getMidPoint(line)
    local xdif    = math.abs(line[3]-line[1])
    local ydif    = math.abs(line[4]-line[2])
    local x    = math.min(line[3], line[1]) + xdif/2
    local y    = math.min(line[4], line[2]) + ydif/2
    return x, y
end

function terrain(bline, range, roughness, tms)
    local lines    = {bline}
    local lines2    = {}

    local midX, midY

    for times=1, tms do
        for index, line in pairs(lines) do
            midX, midY    = getMidPoint(line)
            midY    = midY + math.random(-range, range)

            table.insert(lines2, {line[1], line[2], midX, midY})
            table.insert(lines2, {midX, midY, line[3], line[4]})
        end
        lines    = lines2
        lines2    = {}
        range    = range * (roughness*2^-roughness)
    end

    return lines
end

------------------------
-- Terrain to physics --
------------------------

pTerrain   = class()

function pTerrain:init(bline, range, roughness, times)
   self.lines    = terrain(bline, range, roughness, times)
   self.segments = {}

   self.mass   = LARGE
   self.body   = physics.Body(1, 1)
   self.body:setMass(self.mass)
   
   self.inertia   = 0
   
   local a, b, ss
   for index, line in ipairs(self.lines) do
        a   = physics.Vect(line[1], line[2])
        b   = physics.Vect(line[3], line[4])
       
        self.inertia   = self.inertia + physics.misc.momentForSegment(self.mass/#self.lines, a, b)
        ss   = physics.SegmentShape(self.body, a, b, 1)
        ss:setRestitution(0)
      ss:setFriction(1)
        table.insert(self.segments, ss)
    end

   self.body:setMoment(self.inertia)
   self.body:setVel(ZERO)
   
end

function pTerrain:paint(gc)
   local a,b
    for index, ss in ipairs(self.segments) do
      a = ss:a()
      b = ss:b()
        gc:drawLine(a:x(), a:y(), b:x(), b:y())
    end
end



function on.construction()
   space   = pSpace(9. 8)
   
   timer.start(0.01)
   count=0
   
   ter   = pTerrain({0,120,318,120}, 60, 0.6, 5)
   space:addTerrainObj(ter, 0,0)
   
   ball = pBall(10, 5, 0xaaffaa)
   space:addObj(ball, 160,10)
end


function physicsUpdate()
   space:step(0.1)

   count = count + 1
   if count == 2 then
      platform.window:invalidate()
      count = 1
   end   
end

py,px=100,160

function on.paint(gc)
   space:paint(gc)
   gc:fillRect(px, py, 4, 4)
end

kaction   = {up={0,-5}, down={0,5}, left={-5,0}, right={5,0}}
function on.arrowKey(key)
   px=px+kaction[1]
   py=py+kaction[2]
end

function on.enterKey()
   local box   = pBox(20, 20, 5, math.random(2^16))
   space:addObj(box, px, py)
end

function on.timer()
   physicsUpdate()
end


Spoiler For A bit more advanced (motors/springs/etc):


platform.apilevel = '2.0'
require 'physics'


LARGE=physics.misc.INFINITY()
ZERO =physics.Vect(0,0)
------------------
-- Space Object --
------------------

pSpace   = class()

function pSpace:init(gravity)
   self.space = physics.Space()
         :setGravity(physics.Vect(0, gravity))
         :setSleepTimeThreshold(.5)
         --:resizeActiveHash(30, 500)
   self.objects   = {}
end

function pSpace:step(n)
   self.space:step(n)
end

function pSpace:addObj(obj, x, y)
   obj.body:setPos(physics.Vect(x, y))
   self.space:addBody(obj.body)
   
   self.space:addShape(obj.shape)
   if obj.added then obj:added(self) end
   
   table.insert(self.objects, obj)
   return self
end

function pSpace:addTerrainObj(obj, x, y)
   obj.body:setPos(physics.Vect(x, y))
   --self.space:addBody(obj.body)
   
   for _, ss in ipairs(obj.segments) do
      self.space:addStaticShape(ss)
   end
   
   table.insert(self.objects, obj)
   return self
end

function pSpace:addStaticObj(obj, x, y)
   obj.body:setPos(physics.Vect(x, y))
   --self.space:addBody(obj.body)
   self.space:addStaticShape(obj.shape)
   
   table.insert(self.objects, obj)
   return self
end

function pSpace:addComplexObj(obj, x, y)
   for _, childObj in ipairs(obj.objects) do
      self:addObj(childObj.obj, x+childObj.x, y+childObj.y)
   end
   
   for _, constraint in ipairs(obj.constraints) do
      self.space:addConstraint(constraint)
   end   
   
   table.insert(self.objects, obj)
   return self   
end

function pSpace:paint(gc)
   for _, obj in ipairs(self.objects) do
      obj:paint(gc)
   end
end

----------------
-- Box Object --
----------------

pBox   = class()

function pBox:init(w, h, mass, color, f, e, group)
   self.h=h
   self.w=w
   self.mass=mass
   self.color=color
   
   self.verts = {
      physics.Vect(-w/2, -h/2),
      physics.Vect(-w/2,  h/2),
      physics.Vect(w/2 ,  h/2),
      physics.Vect(w/2 , -h/2)
   } 
   
   self.body   = physics.Body(1, 1)
   self.body:setMass(mass)
   self.body:setMoment(physics.misc.momentForPoly(mass, self.verts, ZERO))
   self.body:setVel(ZERO)
   
   self.shape = physics.PolyShape(self.body, self.verts, ZERO)

   self.shape:setRestitution(e or 0.6)
   self.shape:setFriction(f or 0.6)
   
   if group then self.shape:setGroup(group) end
end

function pBox:paint(gc)
   local coords   = self.shape:points()
   local polycoords   = {}
   for k, vert in ipairs(coords) do
      table.insert(polycoords, vert:x())
      table.insert(polycoords, vert:y())
   end   
   local x,y=coords[1]:x(),coords[1]:y()
   table.insert(polycoords, x)
   table.insert(polycoords, y)           

   gc:setColorRGB(self.color)
   gc:fillPolygon(polycoords)
   gc:setColorRGB(0,0,0)
   gc:drawPolyLine(polycoords)
end


-----------------
-- Ball Object --
-----------------

pBall   = class()

function pBall:init(r,mass,color, f, e, group)
   self.r=r
   self.mass=mass
   self.color=color
   
   self.body   = physics.Body(1, 1)
   self.body:setMass(mass)
   self.body:setMoment(physics.misc.momentForCircle(mass, 0, r, ZERO))
   self.body:setVel(ZERO)
   
   self.shape = physics.CircleShape(self.body, r, ZERO)

   self.shape:setRestitution(e or 0.6)
   self.shape:setFriction(f or 0.6)
   
   if group then self.shape:setGroup(group) end
end

function pBall:paint(gc)
   local pos=self.body:pos()
   local x, y = pos:x(), pos:y()
    local r = self.r
         
    gc:setColorRGB(self.color)                           
    gc:fillArc(x-r, y-r, 2*r+1, 2*r+1, 0, 360)
    gc:setColorRGB(0)
    gc:drawArc(x-r, y-r, 2*r, 2*r, 0, 360)
   
    local x2,y2
    local angle=self.body:angle()
    x2   = math.cos(angle)*self.r+x
    y2   = math.sin(angle)*self.r+y
    gc:drawLine(x,y,x2,y2)
end





pCar   = class()

function pCar:init()
   local group   = 5
   
   local wheelR   = 5   -- wheel Radius
   local wheelM   = 5   -- wheel Mass
   local wheelF   = 0.9   -- wheel Friction
   local wheelE   = 0.0   -- wheel Elasticity
   
   local chassisM   = 10   -- Chassis Mass
   local chassisW   = 24   -- Chassis Width
   local chassisH   = 10   -- Chassis Height
   local chassisF   = 0.7   -- Chassis Friction
   local chassisE   = 0.0   -- Chassis Elasticity
   
   self.wheel1   = pBall(wheelR, wheelM, 0x55CC55, wheelF, wheelE, group)
   self.wheel2   = pBall(wheelR, wheelM+8, 0x55CC55, wheelF, wheelE, group)
   
   self.chassis   = pBox(chassisW, chassisH, chassisM, 0x5555CC, chassisF, chassisE, group)
   
   self.joint1   = physics.GrooveJoint(self.chassis.body, self.wheel1.body, physics.Vect(-10, 5), physics.Vect(-10, 25), ZERO)
   self.joint2   = physics.GrooveJoint(self.chassis.body, self.wheel2.body, physics.Vect( 10, 5), physics.Vect( 10, 25), ZERO)
   
   self.spring1   = physics.DampedSpring(self.chassis.body, self.wheel1.body, physics.Vect(-10, 0), ZERO, 17, 10, 10)
   self.spring2   = physics.DampedSpring(self.chassis.body, self.wheel2.body, physics.Vect( 10, 0), ZERO, 17, 10, 10)
   
   self.Fmotor   = physics.SimpleMotor(self.chassis.body, self.wheel2.body, 0):setMaxForce(1000)
   self.Pmotor   = physics.SimpleMotor(self.chassis.body, self.wheel2.body, 0):setMaxForce(1000)
   self.gear   = physics.GearJoint(self.wheel1.body, self.wheel2.body, 0, 1)
   
   self.objects   = {
      {obj = self.wheel1 , x = -10 ,y = 7},
      {obj = self.wheel2 , x = 10  , y = 7},
      {obj = self.chassis, x = 0 ,y = -7},
   }
   
   self.constraints   = {self.joint1, self.joint2, self.spring1, self.spring2, self.Fmotor, self.Pmotor, self.gear}   
end

function pCar:paint(gc)
   self.wheel1:paint(gc)
   self.wheel2:paint(gc)
   self.chassis:paint(gc)
end






------------------
-- Terrain code --
------------------

function getMidPoint(line)
    local xdif    = math.abs(line[3]-line[1])
    local ydif    = math.abs(line[4]-line[2])
    local x    = math.min(line[3], line[1]) + xdif/2
    local y    = math.min(line[4], line[2]) + ydif/2
    return x, y
end

function terrain(bline, range, roughness, tms)
    local lines    = {bline}
    local lines2    = {}

    local midX, midY

    for times=1, tms do
        for index, line in pairs(lines) do
            midX, midY    = getMidPoint(line)
            midY    = midY + math.random(-range, range)

            table.insert(lines2, {line[1], line[2], midX, midY})
            table.insert(lines2, {midX, midY, line[3], line[4]})
        end
        lines    = lines2
        lines2    = {}
        range    = range * (roughness*2^-roughness)
    end

    return lines
end

------------------------
-- Terrain to physics --
------------------------

pTerrain   = class()

function pTerrain:init(bline, range, roughness, times)
   self.lines    = terrain(bline, range, roughness, times)
   self.segments = {}

   self.mass   = LARGE
   self.body   = physics.Body(1, 1)
   self.body:setMass(self.mass)
   
   self.inertia   = 0
   
   local a, b, ss
   for index, line in ipairs(self.lines) do
        a   = physics.Vect(line[1], line[2])
        b   = physics.Vect(line[3], line[4])
       
        self.inertia   = self.inertia + physics.misc.momentForSegment(self.mass/#self.lines, a, b)
        ss   = physics.SegmentShape(self.body, a, b, 1)
        ss:setRestitution(0)
      ss:setFriction(1)
        table.insert(self.segments, ss)
    end

   self.body:setMoment(self.inertia)
   self.body:setVel(ZERO)
   
end

function pTerrain:paint(gc)
   local a,b
    for index, ss in ipairs(self.segments) do
      a = ss:a()
      b = ss:b()
        gc:drawLine(a:x(), a:y(), b:x(), b:y())
    end
end













function on.construction()
   space   = pSpace(9. 8)
   
   timer.start(0.02)
   count=0
   
   --[[
   floor   = pBox(300, 20, LARGE, 0xCC5555, 0.9)
   space:addStaticObj(floor, 150, 200)
   --]]
   
   ter   = pTerrain({0,120,318,120}, 60, 0.6, 5)
   space:addTerrainObj(ter, 0,0)
   
   car   = pCar()
   space:addComplexObj(car, 50, 50)
end


function on.tabKey()
   car.Pmotor:setMaxForce(10000)
   car.Pmotor:setRate(car.Pmotor:rate()-0.3)
end

function on.escapeKey()
   car.Pmotor:setMaxForce(0)
   car.Pmotor:setRate(0)   
end

function physicsUpdate()
   space:step(0.1)

   count = count + 1
   if count == 2 then
      platform.window:invalidate()
      count = 1
   end   
end

py,px=100,160

function on.paint(gc)
   local f   = math.abs(car.Pmotor:rate())
   gc:drawString("Force: " .. f, 2, 2, "top")
   space:paint(gc)
   gc:fillRect(px, py, 4, 4)
end

kaction   = {up={0,-5}, down={0,5}, left={-5,0}, right={5,0}}
function on.arrowKey(key)
   px=px+kaction[1]
   py=py+kaction[2]
end

function on.enterKey()
   local box   = pBox(20, 20, 5, math.random(2^16))
   space:addObj(box, px, py)
end

function on.timer()
   physicsUpdate()
end


I spend some time making this code, so please take care of it  ;)

5. Take a look at other exisiting activities for the TI-Nspire that use the physics engine
http://education.ti.com/calculators/tisciencenspired/US/Activities/Detail?sa=5029&id=17888

And last but not least ...
Have fun !

358
Other / Re: Weird DVD protection
« on: July 26, 2012, 07:05:34 am »
Windows has some weird things where it still can write to the empty space of a CD-R/DVD-R.
So it prolly just is a way to mark both the computer and CD.  Anyway, you probably can extract the movie out of the exe with some effort :)

359
News / Re: Omnimaga Programming Contest 2012: The Results
« on: July 25, 2012, 03:26:37 pm »
Congratulations to all, there where some fine entries :)
Regarding the votes of the other judges, are there any plans to open up the details on how they voted ?

360
Humour and Jokes / Re: Guess what Pepsi did to us
« on: July 22, 2012, 04:19:51 pm »
Nice :D

Our solution to fixing it is to ban people who use it. >:D
Muhahahahaha

Pages: 1 ... 22 23 [24] 25 26 ... 125