# Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

### The 20 Line Challenge / Plasma effect

Message
Posted: 19th May 2006 01:15
As you will probably see, I'm on a retro/demo type kick ATM Two lines are not indented, to highlight them for your - this is so you can amend them and play around with the speed and pattern if you want.

The first is the speed that the pattern changes - make it larger to run faster.
The second is used to assign a pallet colour to a pixel, using the standard maths functions - this sets the pattern.

The code then just shifts the pallet and redraws it with the new colours.

This also contains a HSV to RGB conversion function I've hacked down into a couple of lines ... it's easier to get a continuous colour pattern with HSV than RGB.

Posted: 19th May 2006 03:31
Wow, very nice effect, may I use it?
Posted: 19th May 2006 06:04
Wow, sweet stuff Ian.

Tempest - P2P UDP Multiplayer Plugin (DBP/DBCe) - 71%
Posted: 19th May 2006 12:00
Nice kalaidoscope effect mate (don't think that's the correct spelling, but you get the idea!) For game/demo music for YOUR PC productions visit:-www.futuredevelopments.org.uk
Posted: 19th May 2006 19:40 Edited at: 19th May 2006 19:43
Thanks. That was just one of many I was playing with.

Here are a few more ... just replace the line starting 'Plasma'

As simple as it gets:
Plasma(x, y) = x

Plasma(x, y) = x + sin(y)*50

Making circles:
Plasma(x, y) = sin(x) * 60 + sin(y) * 60

Smaller circles:
Plasma(x, y) = sin(x * 2) * 60 + sin(y * 2) * 60

Smaller circles, more colours:
Plasma(x, y) = sin(x * 2) * 180 + sin(y * 2) * 180

Distance from origin:
Plasma(x, y) = sqrt( x^2 + y^2 )

Distance from centre:
Plasma(x, y) = sqrt( (x-Width/2)^2 + (y-Height/2)^2 )

Modified Distance from centre:
Plasma(x, y) = sin( sqrt( (x-Width/2)^2 + (y-Height/2)^2 ) ) * 180

Modified distance from centre, plus making circles:
Plasma(x, y) = sin( sqrt( (x-Width/2)^2 + (y-Height/2)^2 ) ) * 180 + sin(x) * 60 + sin(y) * 60

Hopefully, you can see just how easy it is to come up with some quite nice effects, just by building things up Posted: 19th May 2006 20:01
Just a little clarification on how the pallette is arranged ...

If you've ever seen an HSV colour cone, then you'll get this almost immediately ... or you can see one for yourself : http://upload.wikimedia.org/wikipedia/en/f/f1/HSV_cone.jpg

The HSVtoRGB function accepts a 'Hue' of 0 to 360, measured as degrees around the circle. Change the angle, and you get a different colour.

Next is the Saturation level. The HSVtoRGB accepts a range of 0.0 (least colour) to 1.0 (most colour). This code always uses a value of 1.0

Last is the value known as 'Value' (really). Like the saturation level, the range is from 0.0 (darkest) to 1.0 (lightest). This code always uses a value of 1.0.

All that the calculations are doing is generating an angle around the colour circle to use, based on the x and y coordinates of the pixel being coloured. The code varies the colour on the screen by simply adding a number of degrees to move the colour around the circle.