View difference between Paste ID: Bc5YmtLE and sQeattvM
SHOW: | | - or go back to the newest paste.
1-
from microbit import *
1+
from microbit import *
2-
2+
3-
def dim_display():
3+
def dim_display():
4-
    for x in range(0, 5):
4+
    for x in range(0, 5):
5-
        for y in range(0, 5):
5+
        for y in range(0, 5):
6-
            c = display.get_pixel(x, y)
6+
            c = display.get_pixel(x, y)
7-
            if c > 1:
7+
            if c > 1:
8-
                display.set_pixel(x, y, c - 1)
8+
                display.set_pixel(x, y, c - 1)
9-
9+
10-
def set_brightness(b):
10+
def set_brightness(b):
11-
    for x in range(0, 5):
11+
    for x in range(0, 5):
12-
        for y in range(0, 5):
12+
        for y in range(0, 5):
13-
            if display.get_pixel(x, y) > 0:
13+
            if display.get_pixel(x, y) > 0:
14-
                display.set_pixel(x, y, b)
14+
                display.set_pixel(x, y, b)
15-
15+
16-
16+
17-
def brighten_display():
17+
def brighten_display():
18-
    for x in range(0, 5):
18+
    for x in range(0, 5):
19-
        for y in range(0, 5):
19+
        for y in range(0, 5):
20-
            c = display.get_pixel(x, y)
20+
            c = display.get_pixel(x, y)
21-
            if c > 0 and c < 9:
21+
            if c > 0 and c < 9:
22-
                display.set_pixel(x, y, c + 1)
22+
                display.set_pixel(x, y, c + 1)
23-
23+
24-
def pulse():
24+
def pulse():
25-
    d = 80
25+
    d = 80
26-
    for x in range(3):
26+
    for x in range(3):
27-
        brighten_display()
27+
        brighten_display()
28-
        sleep(d)
28+
        sleep(d)
29-
        d -= 10
29+
        d -= 10
30-
30+
31-
    for x in range(3):
31+
    for x in range(3):
32-
        dim_display()
32+
        dim_display()
33-
        sleep(d)
33+
        sleep(d)
34-
        d += 10
34+
        d += 10
35-
35+
36-
    d = 80
36+
    d = 80
37-
    for x in range(7):
37+
    for x in range(7):
38-
        brighten_display()
38+
        brighten_display()
39-
        sleep(d)
39+
        sleep(d)
40-
        d -= 10
40+
        d -= 10
41-
    sleep(200)
41+
    sleep(200)
42-
42+
43-
    d = 40
43+
    d = 40
44-
    for x in range(7):
44+
    for x in range(7):
45-
        dim_display()
45+
        dim_display()
46-
        sleep(d)
46+
        sleep(d)
47-
        d += 5
47+
        d += 5
48-
    sleep(100)
48+
    sleep(100)
49-
49+
50-
50+
51-
display.show(Image.HEART)
51+
display.show(Image.HEART)
52-
set_brightness(2)
52+
set_brightness(2)
53-
53+
54-
while True:
54+
while True:
55
    pulse()