Skip to content

Color

Below is a list of all of the information about colors within spark.

All of the examples below assume you have the boilerplate from the notebook setup in your code

Creating a background

There are two ways to use background:

Method Description Syntax
String Give the name i.e. "green" background("Green")
3 ints Give the r,g,b vaule i.e. 0,255,0 background(0, 255, 0)

String background

1
background(color)

Parameters

  • color: (str) The name of the color to use

Example(s):

Creating a green background

1
2
3
4
5
6
7
%%ignite

def setup():
    size(200, 200)

def draw():
    background("Green")

Results in:

background(message) example

Integer background

1
background(r, g, b)

Parameters

  • r: (int) The red value (between 0-255)
  • g: (int) The green value (between 0-255)
  • b: (int) The blue value (between 0-255)

Example(s):

Creating a green background

1
2
3
4
5
6
7
%%ignite

def setup():
    size(200, 200)

def draw():
    background(0, 255, 0)

Results in:

background(r, g, b) example

Clearing the screen

To clear the screen, there are two options:

Method Description
clear() Clear the screen to default background color (light or dark depending on user settings)
background() Clear the screen with a specific color

Notes

  • For both make sure to put it at the top or bottom of your draw() function if you are using one
  • For the r, g, b values they go from 0-255. So for all green you would use 0, 255, 0

clear()

clear explicitly just clears the screen to the default background color

1
clear()

Example(s):

Drawing a green background and a circle, then clearing the screen and drawing just a rectangle

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
%%ignite

def setup():
    size(200, 200)

    # Draw stuff before clear
    background(0, 255, 0)
    fill_circle(100, 100, 75)

    # Clear everything on the screen
    clear()

    # Only this stuff shows up
    fill_rect(100, 100, 75, 50)

Results in:

clear() example

Changing the color of shapes

There are two available options to change the color of shapes you draw:

Method Description Syntax
String Give the name i.e. "green" fill_style("Green")
3 ints Give the r,g,b vaule i.e. 0,255,0 fill_style(0, 255, 0)

Notes

  • Keep in mind you need to select the color then draw the shape. Like dipping a paintbrush before drawing.
  • For the r, g, b values they go from 0-255. So for all green you would use 0, 255, 0

String version

1
fill_style(color)

Parameters

Example(s):

Drawing a red, a green, and a blue circle at different points on the canvas

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
%%ignite 

def setup():
    size(200, 200)

    # Red Circle
    fill_style("red")
    fill_circle(50, 50, 50)

    # Green Circle
    fill_style("green")
    fill_circle(100, 100, 50)

    # Blue Circle
    fill_style("blue")
    fill_circle(150, 150, 50)

Results in:

fill_style(color)

Integer version

1
fill_style(r, g, b)

Parameters

  • r: (int) The red value (between 0-255)
  • g: (int) The green value (between 0-255)
  • b: (int) The blue value (between 0-255)

Example(s):

Drawing a red, a green, and a blue circle at different points on the canvas

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
%%ignite

def setup():
    size(200, 200)

    # Red circle
    fill_style(255, 0, 0)
    fill_circle(50, 50, 50)

    # Green Circle
    fill_style(0, 255, 0)
    fill_circle(100, 100, 50)

    # Blue circle
    fill_style(0, 0, 255)
    fill_circle(150, 150, 50)

Results in:

fill_style(r, g, b)