Author Topic: Plasma Effect problems :(  (Read 3286 times)

0 Members and 1 Guest are viewing this topic.

Offline 00Freak00

  • ZX 81
  • *
  • Posts: 1
  • Karma: 0
    • View Profile
Plasma Effect problems :(
« on: July 17, 2012 »
Hello I'm new here and have a question directly to you!

I wanted to create a simple plasma effect but I do not understand it quite. Even though I read through tutorials I find it still hard to understand this. I hope one or the other has a bit of time and could explain it to me :)

Sorry for my bad English :)

Offline n00bstar

  • ZX 81
  • *
  • Posts: 22
  • Karma: 8
    • View Profile
Re: Plasma Effect problems :(
« Reply #1 on: July 17, 2012 »
The best way to understand it is to realize that you aren't moving anything around. You are not making a big routine for moving snake-like beams of color that will blend. You are in fact, drawing all pixels on the screen 1 by 1, at the same position, every cycle. The only data that changes is what the RGB value of this pixel will be.

If you were to do this:

Code: [Select]
For X = 0 to 319
For Y = 0 to 239
    Color 255,255,255
    DrawPixel X,Y
Next
Next

You would be drawing a full 320x240 screen with white pixels.

Now, the entirety of your plasma effect rests on changing the "Color 255,255,255" command for someting like "Color (sinetable),(sinetable),(sinetable)"

If you use the same sinetable values for all three colours, you'll just be fading the screen from black to white, but with different table 'speeds' there, the colors will desynchronize and you'll get plasma. Play with the math for your sinetable and you get interesting patterns.

For example, this is the bog standard plasma:

Code: [Select]
While Poop Stinks

SineCounter = SineCounter + 1

For X = 0 to 319
For Y = 0 to 239

    Color (128 + (Sin(SineCounter) * 128)), (128 + (Sin(SineCounter * 0.9) * 128)), (128 + (Sin(SineCounter * 0.8) * 128))
    DrawPixel X,Y

Next
Next

FlipScreen

Wend

See this will do the Sine stuff in realtime, but generally people tend to precalc these into arrays for simplicity's sake and more speed. What will make the three colors move 'separately' is that I modify the value of SineCounter in the Color command (* 0.9 and * 0.8)

Was that clear? Prolly not...  :)

Offline Kirl

  • Senior Member
  • Pentium
  • ********
  • Posts: 1217
  • Karma: 230
    • View Profile
    • Homepage
Re: Plasma Effect problems :(
« Reply #2 on: July 18, 2012 »
Hello 00Freak00, welcome to the forums.

I finally got the idea by thinking of it in terms of 3 sines, one for the red value, one for green and one for blue. A sine just alternates between -1 and 1. So if you multiply the sine with 127 it goes from -127 to 127. By adding 127 it goes from 0 to 254.

Code: [Select]
R = 127 + 127 * Math.sin( randomCalc1 );
G = 127 + 127 * Math.sin( randomCalc2 );
B = 127 + 127 * Math.sin( randomCalc3 );

Now the cool thing is that no matter what you choose to do for randomCalc1, 2 or 3, it will always keep between 0 and 255. So you can go wild with some semi random calculations using the x and y screen position of the pixel you're setting.

I did one in javascript for one of the past competitions, so you can look at the source if you'd like: http://kirl.nl/plasmaScript/playMe.html (right click and select view source)
« Last Edit: July 18, 2012 by Kirl »
www.kirl.nl
Challenge Trophies Won: