 # Twinkling stars

6 replies to this topic

### #1 RetrospectOFFLINE

Retrospect
• Location:Wakefield, England

Posted Thu Nov 29, 2018 4:47 AM

Hi all.

I'm currently preparing to program "Lunar Mission II" and I had an idea.  The sort of idea that actually stops progress of the game because you want it in, but it's not working right.

Okay, Parsec ... note the twinkling stars.  Just how was this done?  I've tried a couple of methods none of which were satisfactory.

I've tried creating stars using different character sets and having those sets switch to black and then back to white, this didn't work as expected (but could be improved later), I've also tried cycling colours through the stars (using lots of char sets obviously) and this had a good effect but not like the one in Parsec.

How did the Parsec guys do it? ### #2 sometimes99erOFFLINE

sometimes99er
• Location:Denmark

Posted Thu Nov 29, 2018 5:59 AM

Try this. ```100 call screen(2)::call clear::call color(2,16,1)::for i=0 to 5::s(i)=int(rnd*256)::next i
110 p\$="010204081020400"::for i=0 to 7::call char(40+i,seg\$(p\$,i*2+1,2))::next i
120 for i=0 to 5::call hchar(i*3+2,32-int(s(i)/8),40+(s(i)and 7))::s(i)=(s(i)+1)and 255
130 next i::goto 120
run

```

Edited by sometimes99er, Thu Nov 29, 2018 6:04 AM.

### #3 RetrospectOFFLINE

Retrospect
• Location:Wakefield, England

Posted Thu Nov 29, 2018 6:48 AM

Try this. ```100 call screen(2)::call clear::call color(2,16,1)::for i=0 to 5::s(i)=int(rnd*256)::next i
110 p\$="010204081020400"::for i=0 to 7::call char(40+i,seg\$(p\$,i*2+1,2))::next i
120 for i=0 to 5::call hchar(i*3+2,32-int(s(i)/8),40+(s(i)and 7))::s(i)=(s(i)+1)and 255
130 next i::goto 120
run

```

Hey thanks Karsten, that's really good.  I'll have a bash at implementing that into the code

### #4 sometimes99erOFFLINE

sometimes99er
• Location:Denmark

Posted Thu Nov 29, 2018 8:05 AM

It's basically the same method the Parsec guys used.

```for i=0 to 5::s(i)=int(rnd*256)::next i
```

The above fills an array with a random star constellation. Each star has a horizontal position in the range 0 to 255.

You only have to dimension (DIM) the array if it has more than eleven elements (numbered 0 to 10).

Let's try 24 stars ...

```100 call screen(2)::call clear::call color(2,16,1)::dim s(23)::for i=0 to 23::s(i)=int(rnd*256)::next i
110 p\$="010204081020400"::for i=0 to 7::call char(40+i,seg\$(p\$,i*2+1,2))::next i
120 for i=0 to 23::call hchar(i+1,32-int(s(i)/8),40+(s(i)and 7))::s(i)=(s(i)+1)and 255
130 next i::goto 120
run

```

Edited by sometimes99er, Thu Nov 29, 2018 8:52 AM.

### #5 sometimes99erOFFLINE

sometimes99er
• Location:Denmark

Posted Thu Nov 29, 2018 8:24 AM

```110 p\$="010204081020400"::for i=0 to 7::call char(40+i,seg\$(p\$,i*2+1,2))::next i
```

The above defines 8 characters. If we print these characters at the same position, it will look like a star moving to the left. Note that the last character has no star. This is the twinkle effect. If we had a star in the eighth character, we'd then have to clear this position (with an empty space) while also printing a star left of this position. So we're actually saving some trouble - or let's call it a neat trick. If all stars used the same character at any given time, then all stars would twinkle in sync, and the overall effect is gone. That's why we assign a unique pixel position for each star - and from that we calculate character to be used and character position.

### #6 sometimes99erOFFLINE

sometimes99er
• Location:Denmark

Posted Thu Nov 29, 2018 8:50 AM

Here's 6 twinkling stars and moving down.

```100 call screen(2)::call clear::call color(2,16,1)::for i=0 to 5::s(i)=int(rnd*192)::next i
110 for i=0 to 6::call char(40+i,rpt\$("00",i)&"1")::next i::call char(47,"")
120 for i=0 to 5::call hchar(int(s(i)/8)+1,i+1,40+(s(i)and 7))::s(i)=(s(i)+1)::if s(i)=192 then s(i)=0
130 next i::goto 120
run

```

And here's 32 stars

```100 call screen(2)::call clear::call color(2,16,1)::dim s(31)::for i=0 to 31::s(i)=int(rnd*192)::next i
110 for i=0 to 6::call char(40+i,rpt\$("00",i)&"1")::next i::call char(47,"")
120 for i=0 to 31::call hchar(int(s(i)/8)+1,i+1,40+(s(i)and 7))::s(i)=(s(i)+1)::if s(i)=192 then s(i)=0
130 next i::goto 120
run

```

Edited by sometimes99er, Thu Nov 29, 2018 8:52 AM.

### #7 RetrospectOFFLINE

Retrospect
• Location:Wakefield, England

Posted Thu Nov 29, 2018 9:22 AM

Hey this is really neat!  .... This will come in handy for my game, as it will have a screen where you are in outer space (with twinkling stars and animated meteors) and then a screen where you collect the astronauts (the stars wouldn't be moving for this bit as you land on this screen). .... so yeah thanks for these examples and I must say they work really well.

#### 0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users