News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

Simple Plasma

Started by kevin, October 07, 2008, 07:45:34 PM

Previous topic - Next topic

kevin

Simple Plasma Using Cos/Sin


PlayBASIC Code: [Select]
   createimage 1,360,360
Do

PLasma()

Sync
loop



Function PLasma()
Static BaseAngle#
rendertoimage 1
YAngle#=Baseangle#
for ylp=0 to 359
Lockbuffer
nullpixel=point(0,0)
For xlp=0 to 359
c1=sinradius(Yangle#+xlp,255)
c2=cosradius(Baseangle#+(xlp*3),255)
c3=cosradius(c1+(xlp*5),255)

c1=cliprange(c1,0,255)
c2=cliprange(c2,0,255)
c3=cliprange(c3,0,255)
fastdot xlp,ylp,rgb(c1,c2,c3)

next
unlockbuffer

YAngle#=Yangle#+5
next
rendertoscreen
tileimage 1,0,0,false
BaseAngle#=BaseAngle#+10
EndFunction







thaaks

See? As I said in the other thread about "spanned jumping": What books do you read?
How did you get that idea? Or a find and quick port to PB in the internet?

Will look gaze at it tonight  ;)

My plasma requires Perlin noise, midpoint displacement and is definitely too slow to be animated...sigh...

Cheers,
Tommy

ATLUS

this hypnosis code :P  ::)

kevin

#3
QuoteWhat books do you read?

   The last book (well reference manual) I read, was most likely the C64 programmers reference manual,   Then later the 680x0 manuals.  


QuoteHow did you get that idea?

    By writing lots of and lots of demos!   When I grew up,  most information you discovered personally.  Trial and error.  So you sat there and came up approach #1. Generally the first 'obvious' solution sucked.. So you opt'd it, then soon approach #2 becomes visible and so on, the cycle repeats.


    If  you imagine a sine wave plotted across the screen. Where, down the screen is the positive Y, and up negative Y.  It clear to see what Y axis is doing.

PlayBASIC Code: [Select]
WaveHeight=100

For Xlp=0 to 800

; calc the Y sinus at this angle * wave height
y#=sin(xlp) * WaveHeight

; plot the Y
Dot xlp,300+Y#
next

; center (zero)
linec 0,300,800,300,$ff0000


centertext 400,200,"Bellow Zero"

centertext 400,400,"Above Zero"


circle 400,550,30,true
centertext 400,500,"Viewer"
\
Sync
waitkey




   However what we could do,  is use Y the value as colour intensity rather than an offset.   Like so.   It's like we're standing above the strip now.  So the closest points (those at the top of the curve) are brighter than those at the bottom.


PlayBASIC Code: [Select]
WaveHeight=127

For Xlp=0 to 800

; calc the Y sinus at this angle * wave height
y#=sin(xlp) * WaveHeight

; convert Y into a Blue colour intensity
Col=WaveHeight+Y#

; plot the pixel
Dotc xlp,300,Col
next


Sync
waitkey






 So all we're doing is drawing a bunch of these rows slightly displaced.  Which should be obvious in the following.


PlayBASIC Code: [Select]
Width=180
Height=180
createfximage 1,Width,height

WaveHeight=127


RowDisplacement=180
Scaler=1

setfps 60

Do

Rendertoimage 1

; transfer the 'base angle into the temp angle value
; so everything this frame is offset from this point
angle#=Baseangle#

For ylp=0 to Height-1
lockbuffer
Nullpixel=point(0,0)
For Xlp=0 to Width-1
; calc the Y sinus at this angle * wave height
y#=sinRadius(Angle#*Scaler,WaveHeight)

; convert Y into a Blue colour intensity
Col=WaveHeight+Y#

; plot the pixel
FastDot xlp,ylp,Col

inc Angle#
next
; bump this angle ahead another 180 degrees so it's the start of the next row.
Angle#=wrapangle(Angle#,RowDisplacement)
unlockbuffer
next


; bump the base point
baseangle#=wrapangle(baseangle#,5)

rendertoscreen
DrawRotatedimage 1,0,0,0,800.0/Width,600.0/Height,0,0,false+4


if leftkey() then inc RowDisplacement
if rightkey() then dec RowDisplacement

if upkey() then inc Scaler
if downkey() then dec Scaler


text 0,10, Scaler
text 0,20, RowDisplacement

Sync

loop





For more complex variations you add various sinus waves together...

PlayBASIC Code: [Select]
WaveHeight=100


do
cls 0
angle#=baseangle#
For Xlp=0 to 800

; calc the Y sinus at this angle * wave height
y1#=sin(angle#) * WaveHeight

y2#=sin(angle#*2+400) * WaveHeight

; plot the Y
Dot xlp,300+Y1#+y2#
inc angle#
next

baseangle#=wrapangle(Baseangle#,1)

Sync
loop





QuoteOr a find and quick port to PB in the internet?

   No thanks!




thaaks

Thanks for the nice sin lesson  :)

Cheers,
Tommy