use different colours in "plot"

Here you can talk about anything related to BBC BASIC, not covered in another category
zdrastvutye
Posts: 4
Joined: Mon 03 Sep 2018, 19:48

use different colours in "plot"

Post by zdrastvutye »

the triangle in this snapshot http://bilder-hochladen.to/hosted/27f4e ... 5077c0.jpg
is black, but i want to use any colour.
the code is as follows, as can be read from the snapshot
1 move 0,0
2 move 100,10
3 plot 85,100,100
and important notice, bbcsdlide will freeze if you try to change the size of the output window
download source http://www.bbcbasic.co.uk/bbcsdl/
DDRM

Re: use different colours in "plot"

Post by DDRM »

The simple answer is that you need to set the foreground colour for graphics, which you can do with the GCOL command:

Code: Select all

GCOL 1  :REM set the foreground colour to red
MOVE 0,0
MOVE 100,10
PLOT 85,100,100
GCOL can take a single parameter from 0 to 15, which will set the foreground colour to one of the pre-specified colours (black, red, green, yellow, blue, magenta, cyan, and then the same plus "added white" - so brighter versions of the above. 15 is pure white.

A slightly more complex, but hopefully useful, guide is that the (default) colour number uses bit 1 to indicate red content, 2 for green, and 3 for blue, with bit 4 meaning "brighter". So 6 is bit 3 (4) plus bit 2 (2): blue+green is cyan.

If you want more control over the exact colour, you can reprogram the colours, using a version of the COLOUR command with 4 parameters. The first is the colour you want to change (0-15), and then come three values (0-255) for red, green and blue. For example, to reset colour 1 to a mid-brown, you could do

Code: Select all

 COLOUR 8,200,100,50
. When you change the colour like this you won't change anything you've already displayed, but anything you plot in colour 8 subsequently will have the new colour.

A couple of other things you might want to know:

1) At the moment you are plotting in the default display window, which is fine, but depends in size on the specific computer it is running on[EDIT -in BBC Basic for Windows]. You might want to consider using the MODE command to set a specified window size, so that you know how many pixels you have to play with. Note that this will also (by default) change the background colour to black (colour 0) and reset the palette, so I'd do this first! [EDIT: It's been pointed out that your post implies that you are using BBC_SDL, for which the default window IS always the same size, so that issue doesn't apply.]
2) You can change the background graphics colour using GCOL 128+[colour number]. You'll then need to clear the graphics window (CLG) before the change takes place.
3) Your code uses lower case keywords, which may be convenient, but (a) risks clashes with useful variable names, and (b) may fox those on the forum who always use upper case keywords. I'd encourage you to consider sticking with upper case keywords.

So I might amend your program as follows:

Code: Select all

MODE 21 :REM Set a window of 800 x 600 pixels (1600 x 1200 graphics units)
COLOUR 8,200,100,50   :REM Redefine colour 8 as brown
GCOL 8    :REM Select our new brown colour as the foreground colour
MOVE 0,0
MOVE 100,10
PLOT 85,100,100
Hope that's useful!

D
zdrastvutye
Posts: 4
Joined: Mon 03 Sep 2018, 19:48

thank you

Post by zdrastvutye »

thank you i changed what you wrote
http://bilder-hochladen.to/hosted/dd397 ... 8b19f1.jpg
the code to create this image is
for a=0 to 15
gcol a :rem set the foreground colour to red
move 0,a*30
move 100+30*a,10
plot 85,100,100
next a
print a
DDRM

Re: use different colours in "plot"

Post by DDRM »

Don't know if this is interesting to you, or anyone else, but I was bored...
2 for the price of 1: take out the REM just inside the first loop to convert a spinning rainbow wheel to a spiral.

Best wishes,

D

Code: Select all

MODE 21
ORIGIN 800,600
a=0
deltaa=2*PI*1/32
fr%=600
*REFRESH OFF
FOR goes%=1 TO 50
   REM fr%=12*(50-goes%)  :REM un-REM this line for a spiral!
   FOR wedges%=0 TO 32
      GCOL wedges% MOD 16
      MOVE 0,0
      MOVE fr%*COS(a),fr%*SIN(a)
      a+=deltaa
      PLOT 181, fr%*COS(a),fr%*SIN(a)
   NEXT wedges%
   *REFRESH
   WAIT 8
NEXT goes%
*REFRESH ON