## Plasma effect in BASIC

- SimonSideburns
**Posts:**392**Joined:**Mon Aug 26, 2013 8:09 pm**Location:**Purbrook, Hampshire-
**Contact:**

### Plasma effect in BASIC

Here's a smallish program I've written that fills the MODE 2 screen with a plasma effect. It's slow, it doesn't colour cycle (but I don't see why not) and it will most likely need to be tweaked for many improvements and enhancements, but I present it as-is for your delight.

Here's the plasma in action with a fairly low graininess value: And before I swapped the order of the colours (I still like this one though): I'm sure the plasma could look more, well, plasma-like, but I don't quite know what to change. I have had some time playing with the line that works out the value of m in line 147 to try to get it working better, but I'm not sure if I'm happy with it that much yet.

Also, you may have noticed that the right hand side is black. I'm pretty sure that's down to how I calculated the right hand side coordinates so no pixels are being plotted there, hence the fade to black). I've got a few ideas on that front, and will continue playing tomorrow sometime.

It's quickest if you paste it into BeebEm (does B-Em allow that too?). Oh, did I mention it's slow?

10 REM PLASMA

20 REM SIMON FERRE'

30 MODE2:g=RND(-TIME)

35 VDU 19,1,4,0,0,0,19,2,1,0,0,0,19,3,5,0,0,0,19,4,2,0,0,0,19,5,6,0,0,0,19,6,3,0,0,0

40 l%=0:r%=159:b%=0:t%=255

50 g=.25: REM graininess

60 VDU23;8202;0;0;0;

70 GCOL 0,RND(8)-1:PLOT 69,l%*8,t%*4

80 GCOL 0,RND(8)-1:PLOT 69,r%*8,t%*4

90 GCOL 0,RND(8)-1:PLOT 69,l%*8,b%*4

100 GCOL 0,RND(8)-1:PLOT 69,r%*8,b%*4

110 PROCgrid(l%,r%,t%,b%)

120 G=GET:END

130 DEFPROCgrid(l%,r%,t%,b%)

140 LOCAL q%,w%,e%,a%,s%,d%,z%,x%,c%,h%,v%,m

145 IF t%-b%<2 THEN ENDPROC

147 m=g*((r%-l%)+(t%-b%))*(RND(1)-.5)*RND(1)

150 q%=POINT(l%*8,t%*4):e%=POINT(r%*8,t%*4)

160 z%=POINT(l%*8,b%*4):c%=POINT(r%*8,b%*4)

170 w%=ABS(q%-e%)/2+m:IF q%>e%THENw%=e%+w%ELSEw%=q%+w%

180 a%=ABS(q%-z%)/2+m:IF q%>z%THENa%=z%+a%ELSEa%=q%+a%

190 d%=ABS(e%-c%)/2+m:IF e%>c%THENd%=c%+d%ELSEd%=e%+d%

200 x%=ABS(z%-c%)/2+m:IF z%>c%THENx%=c%+x%ELSEx%=z%+x%

210 s%=ABS(a%-d%)/2+m:IF a%>d%THENs%=d%+s%ELSEs%=a%+s%

220 h%=l%+((r%-l%)/2):v%=b%+((t%-b%)/2)

230 IF POINT(h%*8,t%*4)=0 THEN GCOL 0,w% MOD 7+1:PLOT 69,h%*8,t%*4:

235 IF POINT(h%*8,b%*4)=0 THEN GCOL 0,x% MOD 7+1:PLOT 69,h%*8,b%*4

240 IF POINT(l%*8,v%*4)=0 THEN GCOL 0,a% MOD 7+1:PLOT 69,l%*8,v%*4:

242 IF POINT(r%*8,v%*4)=0 THEN GCOL 0,d% MOD 7+1:PLOT 69,r%*8,v%*4

245 IF POINT(h%*8,v%*4)=0 THEN GCOL 0,s% MOD 7+1:PLOT 69,h%*8,v%*4

250 PROCgrid(l%,h%,t%,v%)

260 PROCgrid(l%,h%,v%,b%)

270 PROCgrid(h%,r%,t%,v%)

280 PROCgrid(h%,r%,v%,b%)

290 ENDPROC

Here's the plasma in action with a fairly low graininess value: And before I swapped the order of the colours (I still like this one though): I'm sure the plasma could look more, well, plasma-like, but I don't quite know what to change. I have had some time playing with the line that works out the value of m in line 147 to try to get it working better, but I'm not sure if I'm happy with it that much yet.

Also, you may have noticed that the right hand side is black. I'm pretty sure that's down to how I calculated the right hand side coordinates so no pixels are being plotted there, hence the fade to black). I've got a few ideas on that front, and will continue playing tomorrow sometime.

It's quickest if you paste it into BeebEm (does B-Em allow that too?). Oh, did I mention it's slow?

10 REM PLASMA

20 REM SIMON FERRE'

30 MODE2:g=RND(-TIME)

35 VDU 19,1,4,0,0,0,19,2,1,0,0,0,19,3,5,0,0,0,19,4,2,0,0,0,19,5,6,0,0,0,19,6,3,0,0,0

40 l%=0:r%=159:b%=0:t%=255

50 g=.25: REM graininess

60 VDU23;8202;0;0;0;

70 GCOL 0,RND(8)-1:PLOT 69,l%*8,t%*4

80 GCOL 0,RND(8)-1:PLOT 69,r%*8,t%*4

90 GCOL 0,RND(8)-1:PLOT 69,l%*8,b%*4

100 GCOL 0,RND(8)-1:PLOT 69,r%*8,b%*4

110 PROCgrid(l%,r%,t%,b%)

120 G=GET:END

130 DEFPROCgrid(l%,r%,t%,b%)

140 LOCAL q%,w%,e%,a%,s%,d%,z%,x%,c%,h%,v%,m

145 IF t%-b%<2 THEN ENDPROC

147 m=g*((r%-l%)+(t%-b%))*(RND(1)-.5)*RND(1)

150 q%=POINT(l%*8,t%*4):e%=POINT(r%*8,t%*4)

160 z%=POINT(l%*8,b%*4):c%=POINT(r%*8,b%*4)

170 w%=ABS(q%-e%)/2+m:IF q%>e%THENw%=e%+w%ELSEw%=q%+w%

180 a%=ABS(q%-z%)/2+m:IF q%>z%THENa%=z%+a%ELSEa%=q%+a%

190 d%=ABS(e%-c%)/2+m:IF e%>c%THENd%=c%+d%ELSEd%=e%+d%

200 x%=ABS(z%-c%)/2+m:IF z%>c%THENx%=c%+x%ELSEx%=z%+x%

210 s%=ABS(a%-d%)/2+m:IF a%>d%THENs%=d%+s%ELSEs%=a%+s%

220 h%=l%+((r%-l%)/2):v%=b%+((t%-b%)/2)

230 IF POINT(h%*8,t%*4)=0 THEN GCOL 0,w% MOD 7+1:PLOT 69,h%*8,t%*4:

235 IF POINT(h%*8,b%*4)=0 THEN GCOL 0,x% MOD 7+1:PLOT 69,h%*8,b%*4

240 IF POINT(l%*8,v%*4)=0 THEN GCOL 0,a% MOD 7+1:PLOT 69,l%*8,v%*4:

242 IF POINT(r%*8,v%*4)=0 THEN GCOL 0,d% MOD 7+1:PLOT 69,r%*8,v%*4

245 IF POINT(h%*8,v%*4)=0 THEN GCOL 0,s% MOD 7+1:PLOT 69,h%*8,v%*4

250 PROCgrid(l%,h%,t%,v%)

260 PROCgrid(l%,h%,v%,b%)

270 PROCgrid(h%,r%,t%,v%)

280 PROCgrid(h%,r%,v%,b%)

290 ENDPROC

Last edited by SimonSideburns on Sun Apr 07, 2019 1:24 pm, edited 2 times in total.

Just remember kids, Beeb spelled backwards is Beeb!

### Re: Plasma effect in BASIC

Excellent.

Perhaps this ought to go into the 'short type ins' topic ?

Perhaps this ought to go into the 'short type ins' topic ?

**EDIT...**I forgot my screenshot. I used a standard BBC B with the GFX extension ROM alive and well (not that it would do much I expect, maybe make it a bit faster perhaps)
Last edited by AndyF on Sun Apr 07, 2019 4:10 pm, edited 2 times in total.

Andy

* NEW * The Jetset Willy and Manic Miner community

Adventure games ported across to the BBC (in progress) as soon as I can find some time!

* NEW * The Jetset Willy and Manic Miner community

Adventure games ported across to the BBC (in progress) as soon as I can find some time!

- SimonSideburns
**Posts:**392**Joined:**Mon Aug 26, 2013 8:09 pm**Location:**Purbrook, Hampshire-
**Contact:**

### Re: Plasma effect in BASIC

I did contemplate this, but I wasn't sure it was short enough. It would probably take 10 minutes for an average typist to enter into the Beeb.

I've also been modifying it further. I will post an update later.

Just remember kids, Beeb spelled backwards is Beeb!

### Re: Plasma effect in BASIC

Yes that makes sense although I suspect most these days will be copying/pasting into an emulator but I do see your point 100% as it is as you say about 10 minutes (I think I could probably do it in a bit less) on average.SimonSideburns wrote: ↑Mon Apr 08, 2019 11:05 amI did contemplate this, but I wasn't sure it was short enough. It would probably take 10 minutes for an average typist to enter into the Beeb.

I've also been modifying it further. I will post an update later.

Looking forward to see the update.

I do have a few to add to that 'type ins' topic too but I've not written the other couple I wanted to add to it, rather submit them all into one post as they are quite similar and small.

Andy

* NEW * The Jetset Willy and Manic Miner community

Adventure games ported across to the BBC (in progress) as soon as I can find some time!

* NEW * The Jetset Willy and Manic Miner community

Adventure games ported across to the BBC (in progress) as soon as I can find some time!

- SimonSideburns
**Posts:**392**Joined:**Mon Aug 26, 2013 8:09 pm**Location:**Purbrook, Hampshire-
**Contact:**

### Re: Plasma effect in BASIC

I wasn't quite happy with it so a few tweaks later (not really sure what I'm doing, just trying to make it look a bit better) and here's the latest incarnation:

Here's the latest code:
Here it is set to a graininess of 0:
Here it is with a graininess of 10:
Now, a few slight modifications:
...and we arrive at this image:

Here's the latest code:

Code: Select all

```
10 REM PLASMA
20 REM SIMON FERRE'
30 MODE2:g=RND(-TIME)
40 VDU 19,1,4,0,0,0,19,2,1,0,0,0,19,3,5,0,0,0,19,4,2,0,0,0,19,5,6,0,0,0,19,6,3,0,0,0,19,8,0,0,0,0
45 VDU 19,9,4,0,0,0,19,10,1,0,0,0,19,11,5,0,0,0,19,12,2,0,0,0,19,13,6,0,0,0,19,14,3,0,0,0,19,15,7,0,0,0
50 l%=0:r%=159:b%=0:t%=255
60 g=10: REM graininess
70 VDU23;8202;0;0;0;
80 GCOL 0,RND(16)-1:PLOT 69,l%*8,t%*4
90 GCOL 0,RND(16)-1:PLOT 69,r%*8,t%*4
100 GCOL 0,RND(16)-1:PLOT 69,l%*8,b%*4
110 GCOL 0,RND(16)-1:PLOT 69,r%*8,b%*4
120 PROCgrid(l%,r%,t%,b%)
130 G=GET:END
140 DEFPROCgrid(l%,r%,t%,b%)
150 LOCAL q%,w%,e%,a%,s%,d%,z%,x%,c%,h%,v%,m
160 IF t%-b%<2 THEN ENDPROC
170 m=2/415*((r%-l%)+(t%-b%))*g*(RND(1)-.5)
180 q%=POINT(l%*8,t%*4):e%=POINT(r%*8,t%*4)
190 z%=POINT(l%*8,b%*4):c%=POINT(r%*8,b%*4)
200 w%=ABS(q%-e%)/2+m:IF q%>e%THENw%=e%+w%ELSEw%=q%+w%
210 a%=ABS(q%-z%)/2+m:IF q%>z%THENa%=z%+a%ELSEa%=q%+a%
220 d%=ABS(e%-c%)/2+m:IF e%>c%THENd%=c%+d%ELSEd%=e%+d%
230 x%=ABS(z%-c%)/2+m:IF z%>c%THENx%=c%+x%ELSEx%=z%+x%
240 s%=ABS(a%+d%+w%+x%)/4+m
250 h%=l%+((r%-l%)/2):v%=b%+((t%-b%)/2)
260 IF POINT(h%*8,v%*4)=0 THEN GCOL 0,s% MOD 16+1:PLOT 69,h%*8,v%*4
270 IF POINT(h%*8,b%*4)=0 THEN GCOL 0,x% MOD 16+1:PLOT 69,h%*8,b%*4
280 IF POINT(l%*8,v%*4)=0 THEN GCOL 0,a% MOD 16+1:PLOT 69,l%*8,v%*4:
290 IF POINT(h%*8,t%*4)=0 THEN GCOL 0,w% MOD 16+1:PLOT 69,h%*8,t%*4:
300 IF POINT(r%*8,v%*4)=0 THEN GCOL 0,d% MOD 16+1:PLOT 69,r%*8,v%*4
310 PROCgrid(l%,h%,t%,v%)
320 PROCgrid(l%,h%,v%,b%)
330 PROCgrid(h%,r%,t%,v%)
340 PROCgrid(h%,r%,v%,b%)
350 ENDPROC
```

Code: Select all

```
10 REM PLASMA
20 REM SIMON FERRE'
30 MODE2:g=RND(-TIME)
40 VDU 19,1,4,0,0,0,19,2,1,0,0,0,19,3,5,0,0,0,19,4,2,0,0,0,19,5,6,0,0,0,19,6,3,0,0,0,19,8,0,0,0,0
45 VDU 19,9,4,0,0,0,19,10,1,0,0,0,19,11,5,0,0,0,19,12,2,0,0,0,19,13,6,0,0,0,19,14,3,0,0,0,19,15,7,0,0,0
50 l%=0:r%=159:b%=0:t%=255
60 g=20: REM graininess
70 VDU23;8202;0;0;0;
80 GCOL 0,RND(16)-1:PLOT 69,l%*8,t%*4
90 GCOL 0,RND(16)-1:PLOT 69,r%*8,t%*4
100 GCOL 0,RND(16)-1:PLOT 69,l%*8,b%*4
110 GCOL 0,RND(16)-1:PLOT 69,r%*8,b%*4
120 PROCgrid(l%,r%,t%,b%)
130 G=GET:END
140 DEFPROCgrid(l%,r%,t%,b%)
150 LOCAL q%,w%,e%,a%,s%,d%,z%,x%,c%,h%,v%,m
160 IF t%-b%<2 THEN ENDPROC
170 m=1/415*((r%-l%)+(t%-b%))*g*(RND(1)-.5)
180 q%=POINT(l%*8,t%*4):e%=POINT(r%*8,t%*4)
190 z%=POINT(l%*8,b%*4):c%=POINT(r%*8,b%*4)
200 w%=ABS(q%-e%)/2+m:IF w%<0 THEN w%=w%+16ELSEIFw%>15 THEN w%=w%-16
205 IF q%>e%THENw%=e%+w%ELSEw%=q%+w%
210 a%=ABS(q%-z%)/2+m:IF a%<0 THEN a%=a%+16ELSEIFa%>15 THEN a%=a%-16
215 IF q%>z%THENa%=z%+a%ELSEa%=q%+a%
220 d%=ABS(e%-c%)/2+m:IF d%<0 THEN d%=d%+16ELSEIFd%>15 THEN d%=d%-16
225 IF e%>c%THENd%=c%+d%ELSEd%=e%+d%
230 x%=ABS(z%-c%)/2+m:IF x%<0 THEN x%=x%+16ELSEIFx%>15 THEN x%=x%-16
235 IF z%>c%THENx%=c%+x%ELSEx%=z%+x%
240 s%=ABS(a%+d%+w%+x%)/4+m
250 h%=l%+((r%-l%)/2):v%=b%+((t%-b%)/2)
260 IF POINT(h%*8,v%*4)=0 THEN GCOL 0,s%:PLOT 69,h%*8,v%*4
270 IF POINT(h%*8,b%*4)=0 THEN GCOL 0,x%:PLOT 69,h%*8,b%*4
280 IF POINT(l%*8,v%*4)=0 THEN GCOL 0,a%:PLOT 69,l%*8,v%*4:
290 IF POINT(h%*8,t%*4)=0 THEN GCOL 0,w%:PLOT 69,h%*8,t%*4:
300 IF POINT(r%*8,v%*4)=0 THEN GCOL 0,d%:PLOT 69,r%*8,v%*4
310 PROCgrid(l%,h%,t%,v%)
320 PROCgrid(l%,h%,v%,b%)
330 PROCgrid(h%,r%,t%,v%)
340 PROCgrid(h%,r%,v%,b%)
350 ENDPROC
```

Last edited by SimonSideburns on Mon Apr 08, 2019 9:44 pm, edited 1 time in total.

Just remember kids, Beeb spelled backwards is Beeb!

### Re: Plasma effect in BASIC

Cool stuff

Lee.

Lee.

- marcusjambler
**Posts:**668**Joined:**Mon May 22, 2017 11:20 am**Location:**Bradford-
**Contact:**

### Re: Plasma effect in BASIC

This is interesting

Last edited by marcusjambler on Mon Apr 08, 2019 11:23 pm, edited 1 time in total.

- SimonSideburns
**Posts:**392**Joined:**Mon Aug 26, 2013 8:09 pm**Location:**Purbrook, Hampshire-
**Contact:**

### Re: Plasma effect in BASIC

Those weird blobs at the bottom right occur if the palette wraps around. It then has to get from 15 to 0 in a small number of pixels. The latest version is using all 15 colours so it could work nicely with nULA with a gradient.

Last edited by SimonSideburns on Tue Apr 09, 2019 2:05 pm, edited 1 time in total.

Just remember kids, Beeb spelled backwards is Beeb!