| How Do I Avoid Processes? 
 
	 
	
		| Author | Message |   
		| riveryu 
 
  
 
 
 | 
			
				|  Posted: Thu Mar 13, 2008 9:42 pm    Post subject: How Do I Avoid Processes? |  |   
				| 
 |  
				| How Do I Avoid Processes? Things rather seem complicated without using processes? I tried not use processes after reading Why Avoid Process... in Tutorial section. When I programmed I tried to keep a neat time line in my head, but many times, processes seems to be a shortcut. I cant find other ways, very frustrated right now and when I'm frustrated I play guitar, which annoys neighbor annoys me back and infinite loop....
 
 Here is a , I have an actual problem with trying to draw smoke and then let them "fade" or rather disappear in this example code...
 To me this looks to be the most inefficient way to draw smoke b/c I dont know any other...
 
 
 
 	  | Turing: |  	  | var cx, cy : int
var  cx1, cy1 : int
var  cxx, cyy : int
var  cx11, cy11 : int
process  smoke
for  decreasing i :  200 . . 10 by 10 
    cx:=maxx div 2 
    cy:=i
    for  i2 : 1 . . 40
        randint ( cx1, 0  + cx, 100  + cx) %random ovals forming realistic clouds, and every time different shape
        randint ( cy1, 0  + cy, 10  + cy)
        if  i2 mod 2 = 0
                then
            drawfilloval ( cx1, cy1, 10 , 10 , 29)
        else
            drawfilloval ( cx1, cy1, 10 , 10 , 30)
        end if
        delay (5)
    end for
end for
end  smoke
process  fade
for  decreasing i :  200 . . 10 by 10 
    cxx:=maxx div 2 
    cyy:=i
    for  i2 : 1 . . 40
        randint ( cx11, 0  + cxx, 100  + cxx) 
        randint ( cy11, 0  + cyy, 10  + cyy)          
            drawfilloval ( cx11, cy11, 15 , 15 , white)
        delay (5)
    end for
end for
end  fade
fork  smoke
delay (2000)
fork  fade | 
 
 If you have any better way please enlighten me, and also if I were to make them actually fade than disappear, do I have to store each oval's location in an array then redraw ovals on top of each with fading color values? This would be complicated since the smoke is basically overlapped ovals. How do I specifically identify the top most ovals without reducing amount of ovals and risk white space?
 This seems complicated to me, how do I make them fade?? ARRGHH....
   |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Sponsor Sponsor
 
  
   |  |   
		|  |   
		| Saad 
 
  
 
 
 | 
			
				|  Posted: Thu Mar 13, 2008 9:49 pm    Post subject: Re: How Do I Avoid Processes? |  |   
				| 
 |  
				| What you want to do is update everything in one big loop frame by frame 
 The code structure would go along the lines of
 
 
 	  | Turing: |  	  | loop
%% Draw some smoke
 
 if (waitedEnoughTime) then
 %% Erase some smoke
 end if
 
 end loop
 
 | 
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| riveryu 
 
  
 
 
 | 
			
				|  Posted: Thu Mar 13, 2008 10:15 pm    Post subject: Re: How Do I Avoid Processes? |  |   
				| 
 |  
				| So, in this case. I should get rid of the for loop, put in a counter manually, use a loop and exit when then... 
 if  Time.Elapsed  =  whatever
 then blow smoke away + keep on drawing new smoke
 end if
 
 Does Time.Elapsed end up differently on different computers? How can I record time from a specific point of the program other than using process?
 I know the other way may be counting how many time it looped and start erasing smoke at a specific loop approximating the time (I think), but anyways plz answer question above.
 
 I have a nearly unrelated question, do you think a grade 10 half way through a semester expects his students to acheive this? (serious question)
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| CodeMonkey2000 
 
 
 
 
 | 
			
				|  Posted: Thu Mar 13, 2008 10:19 pm    Post subject: RE:How Do I Avoid Processes? |  |   
				| 
 |  
				| You could have a finite amount of smoke that you keep drawing. That way you could move those points and cls the screen. |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| riveryu 
 
  
 
 
 | 
			
				|  Posted: Thu Mar 13, 2008 10:23 pm    Post subject: RE:How Do I Avoid Processes? |  |   
				| 
 |  
				| Can you be a little more clearer CodeMonkey? Did you mean, I keep drawing the smoke in one place for a while, and then moving the whole thing in one direction with the smoek actually keep drawing in one place in that picture, instead of keep on drawing in one direction like what I did earlier? |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| CodeMonkey2000 
 
 
 
 
 | 
			
				|  Posted: Thu Mar 13, 2008 10:25 pm    Post subject: RE:How Do I Avoid Processes? |  |   
				| 
 |  
				| Each smoke particle has a set amount of "life" or amount of time it is on screen. Once this time is up, it start over. |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| riveryu 
 
  
 
 
 | 
			
				|  Posted: Thu Mar 13, 2008 10:34 pm    Post subject: RE:How Do I Avoid Processes? |  |   
				| 
 |  
				| Firstly, thx CodeMonkey for ur help... 
 Sry, I would like make it clear that I'm Ultra N00b. I dont know how to do that CodeMonkey... but here is a wild guess does the solution involve using variables/array to store each smoke particle location and drawing over them each time with lighter color until transparency?
 
 can you show me some code example?
 
 Im trying to be courteous and perhaps overly demanding at the same time hmmm...
 Is it unethnical....
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| CodeMonkey2000 
 
 
 
 
 | 
			
				|  Posted: Thu Mar 13, 2008 10:40 pm    Post subject: Re: How Do I Avoid Processes? |  |   
				| 
 |  
				| This is a test of my old particle engine. I don't expect you to understand this, but observe what's happening. There are at most 5 particles on screen. My program process each one, and if I reach the end of my array, I start look at the first particle and restart it. Each particles is only allowed to live for 100 milliseconds. If it lives longer, I send it back to the start. This gives you the illusion of infinate particles.
 
 	  | Turing: |  	  | %saurabh
%unit
class particleSystem
    export  execute, RunParticle, atributes
    type  vector :
        record 
            x : real 
            y : real 
            vY : real 
            vX : real 
            duration : int 
            clr : int
        end record
    var  maxDuration : int := 2500
    var  pullY : real :=  -.98
    var  pullX : real := 0
    var  pClr : int := white
    var  spitOut : int := 10
    var  maxParticle : int := 2000
    var  CurrentParticle : int := 0
    var  particles : flexible array 0 . . 0 of  vector
    proc  DrawParticle ( current : int)
        drawfilloval (round ( particles ( current) .x), round ( particles ( current) .y), 5 , 5 , particles ( current) .clr)
    end  DrawParticle
    fcn  onScreen ( x, y : real) : boolean
        result  x >= 0 and  x <= maxx and  y >= 0 and  y <= maxy
    end  onScreen
    procedure  RunParticle
        for  x : 1 . . upper ( particles)
            if  particles ( x) .duration < maxDuration then 
                particles ( x) .duration += 1 
                particles ( x) .vY :=  particles ( x) .vY + pullY
 
                particles ( x) .vX :=  particles ( x) .vX + pullX
 
                particles ( x) .y := ( particles ( x) .y + particles ( x) .vY) 
                particles ( x) .x := ( particles ( x) .x + particles ( x) .vX)
                if not  onScreen ( particles ( x) .x, particles ( x) .y) then 
                    particles ( x) .duration :=  maxDuration
                end if
                if  particles ( x) .duration < maxDuration then 
                    DrawParticle ( x)
                end if
            end if
        end for
    end  RunParticle
    procedure  CreateParticle ( x, y : real)
        var  angle : real
        var  radii : real
        if  CurrentParticle > maxParticle then 
            CurrentParticle := 1
        end if
        if  CurrentParticle + 1  > upper ( particles) then
            new  particles, upper ( particles)  + 1
        end if 
        CurrentParticle += 1 
        particles ( CurrentParticle) .duration := 1 
        particles ( CurrentParticle) .clr :=  pClr
 
        particles ( CurrentParticle) .duration := 1 
        particles ( CurrentParticle) .x :=  x
 
        particles ( CurrentParticle) .y :=  y
 
        angle :=  Rand.Int (1 , 360) 
        radii :=  Rand.Int (1 , 12) 
        particles ( CurrentParticle) .vX :=  radii * cosd ( angle) 
        particles ( CurrentParticle) .vY :=  radii * sind ( angle) 
        DrawParticle ( CurrentParticle)
    end  CreateParticle
    proc  execute ( times, x, y : int)
        for  b : 1 . . times
            for  k : 1 . . spitOut
 
                CreateParticle ( x, y)
            end for
        end for
    end  execute
    proc  atributes ( pX, pY : real , colour , duration, out, maxP : int) 
        pullX :=  pX
 
        pullY :=  pY
 
        pClr := colour 
        maxDuration :=  duration
 
        spitOut :=  out
 
        maxParticle :=  maxP
    end  atributes
end  particleSystem
View.Set ("offscreenonly")
var  myParticle :  ^particleSystem
var  x, y, b : int
new  particleSystem, myParticle
colourback (black)
loop
    Mouse.Where ( x, y, b)
    if  b > 0 then 
        particleSystem ( myParticle) .atributes (0 , -.6 , grey , 100 , 1 , 5) %112 
        particleSystem ( myParticle) .execute (1 , x, y)
    end if 
    particleSystem ( myParticle) .RunParticle
    View.Update
    Time.DelaySinceLast (round (1000  / 30))
    cls
end loop | 
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Sponsor Sponsor
 
  
   |  |   
		|  |   
		| riveryu 
 
  
 
 
 | 
			
				|  Posted: Fri Mar 14, 2008 12:46 pm    Post subject: RE:How Do I Avoid Processes? |  |   
				| 
 |  
				| thanks a lot CodeMonkey2000 
 I dont understand:
 - the math involved moving the particles
 - how classes work
 - how you set the duration to be exactly 100 millisec, all i' m seeing is...
 I understand:
 -you reset the varibles when they reach the limit
 -each time it loops duration is added 1 if it does not reach the limits, when it does, you stop drawing then reset the variable and loops it again, you did similarly with the number of particles limit
 
 tell me if my assumptions are correct...
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| CodeMonkey2000 
 
 
 
 
 | 
			
				|  Posted: Fri Mar 14, 2008 1:48 pm    Post subject: RE:How Do I Avoid Processes? |  |   
				| 
 |  
				| Your assumptions are somewhat correct. You don't need to understand how classes work, it's not important. For your program, just pick a maximum amount of smoke. Declare an array that will hold all the points from 1 to the maximum. You also need to memorize the current particle you are on. Now make a main loop. In this main loop process the current particle (send it to where ever you want on the screen). Next clear the screen and draw all the particles from 1 to the current particle (you have the coordinates stored in an array). Then look at the next particle, if there is no next particle, then current particle should equal 1. Hope that helps! |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| riveryu 
 
  
 
 
 | 
			
				|  Posted: Fri Mar 14, 2008 3:44 pm    Post subject: RE:How Do I Avoid Processes? |  |   
				| 
 |  
				| Thank you, my problem is solved. I learned a lot from this. |  
				|  |  |   
		|  |  |  
	  
		|  |   
		|  |  
 |