Computer Science Canada

Particle System help

Author:  prateke [ Sun May 16, 2010 9:13 am ]
Post subject:  Particle System help

What is it you are trying to achieve?
For my ICS2OI summative, i proposed to make a Particle System in turing. The program would consist of different particle types with different properties (heavy, light, flammable, etc.) and would be physics based (gravity, friction, etc.) I need a push in the right direction before i can get to start programming the particle system

What is the problem you are having?
I'm having a problem trying to make the boxes I draw with the mouse get affected gravity. I was able to make the boxes be drawn where the mouse is and when it is clicked. The problem i had is that the boxes/particles that are being drawn have a fixed x and y position, and therefore can't change them. Here is how i draw the boxes.
code:

var x, y, button : int
var px, py, px2, py2 :int
loop
Mouse.Where (x, y, button)
px := x
py := y
px2 := x +4
py2 := y +4
 if button = 1 then
drawfillbox (px, py, px2, py2, black)
end if
end loop

Describe what you have tried to solve this problem
I tried to put a variable for Gravity and subtract gravity from the y values of the boxes, but it didnt work as the co-ordinates of the boxes were fixed and couldnt be changed.


Please specify what version of Turing you are using
I'm using version 4.1.1

Thanks
Mr. Green

Author:  BigBear [ Sun May 16, 2010 9:38 am ]
Post subject:  RE:Particle System help

draw your boxes with variables and change those variables depending what is affecting the box.

so if you want gravity to pull the box down have x decrement every loop iteration (make the x -= FORCE_OF_GRAVITY)

then if the boxes make contact calculate friction and change the variables where you draw the box.

Author:  prateke [ Sun May 16, 2010 9:51 am ]
Post subject:  Re: RE:Particle System help

BigBear @ Sun May 16, 2010 9:38 am wrote:
draw your boxes with variables and change those variables depending what is affecting the box.

so if you want gravity to pull the box down have x decrement every loop iteration (make the x -= FORCE_OF_GRAVITY)...
.


I've already tried doing that by setting a constant named Gravity and subtracted the constant from the 2 y values of the box...but the problem is the when the mouse is clicked and the variables for the x and y co-ordinates are set, they cant be changed for some reason, its as if they are NOT variables.

Author:  BigBear [ Sun May 16, 2010 10:23 am ]
Post subject:  RE:Particle System help

If you take the y coordindates in the drawing call it will draw it at that spot

say yPosition is 10 and GRAVITY is 5, the y position will now be 5, a constant.

you need to continuesly subtract GRAVITY from the yPosition.

Author:  prateke [ Sun May 16, 2010 4:38 pm ]
Post subject:  Re: RE:Particle System help

BigBear @ Sun May 16, 2010 10:23 am wrote:
If you take the y coordindates in the drawing call it will draw it at that spot

say yPosition is 10 and GRAVITY is 5, the y position will now be 5, a constant.

you need to continuesly subtract GRAVITY from the yPosition.


I tried doing what you said, but it doesnt seem to work

code:

var x, y, button, px, py, px2, py2 : int
const Gravity : int := 3
loop
Mouse.Where (x, y, button)
px := x
py := y
px2 := x+2
py2 := y+2
py -= Gravity
py2 -= Gravity
if button = 1 then
 drawfillbox (px, py, px2, py2, black)
end if
end loop

Author:  prateke [ Sun May 16, 2010 4:39 pm ]
Post subject:  RE:Particle System help

Im guessing that i need to have a array for the boxes, but im not sure of how to use that

Author:  BigBear [ Sun May 16, 2010 5:17 pm ]
Post subject:  RE:Particle System help

Turing:
var x, y, button, px, py, px2, py2 : int
const Gravity : int := 3
loop
    Mouse.Where (x, y, button)
    px := x
    py := y
    px2 := x + 2
    py2 := y + 2
    py -= Gravity
    py2 -= Gravity
    if button = 1 then
        drawfillbox (px, py, px2, py2, black)
    end if
end loop


you get x and y variables based on where the mouse is, then you make modifications to those variables and draw a box, but next loop iteration you set px := x (where the mouse is) and py := y (where the mouse is) so it never loops and lets gravity influence is since you reset it back to where the mouse is

try making a loop to get the mouse position then a loop to draw the box then a loop around the whole thing


: