Skip to content

Commit d33b1cd

Browse files
Add files via upload
Added example code for plotting
1 parent 0cbe2f8 commit d33b1cd

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

VGA_plot_test.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Micropython PICO2 VGA plot library test file
2+
# https://github.com/HughMaingauche/PICO2-VGA-Micropython
3+
4+
from VGA.VGA_800x600 import screen_800x600
5+
from VGA.VGA_plot import Plot, Line
6+
from math import cos, pi, sin
7+
8+
#
9+
# 3 bit color names
10+
RED = 0b001
11+
GREEN = 0b010
12+
BLUE = 0b100
13+
YELLOW = 0b011
14+
BLACK = 0
15+
WHITE = 0b111
16+
CYAN = 0b110
17+
MAGENTA = 0b101
18+
19+
20+
# Initialize VGA display
21+
display = screen_800x600()
22+
display.VGA_init()
23+
display.fill_screen(BLACK)
24+
25+
plot1 = Plot(display, ul_x=1, ul_y=1, br_x=780, br_y=300,ax_color=WHITE, min_x=0, max_x=360, min_y=-1, max_y=1, x_ticks_num=10,y_ticks_num=10)
26+
line1 = Line(plot1, [], [], CYAN,label="cos(x)")
27+
line2 = Line(plot1, [], [], YELLOW,label="sin(x)")
28+
29+
plot2 = Plot(display, ul_x=1, ul_y=320, br_x=280, br_y=590,ax_color=GREEN, min_x=-10, max_x=10, min_y=-1, max_y=6, x_ticks_num=10,y_ticks_num=5)
30+
line3 = Line(plot2, [], [], RED,label="cos(x) + 1/x^2")
31+
32+
plot3 = Plot(display, ul_x=320, ul_y=320, br_x=770, br_y=590,ax_color=YELLOW, min_x=-30, max_x=30, min_y=-17, max_y=17, x_ticks_num=10,y_ticks_num=10)
33+
line4 = Line(plot3, [], [], MAGENTA,label="sin(x).cos(x).x")
34+
35+
36+
for x in range(360):
37+
t=x*2*pi/360
38+
line1.add_data_ns(x,cos(t),draw_line=True)
39+
line2.add_data_ns(x,sin(t),draw_line=True)
40+
41+
for x in range(-1000,1000):
42+
if x!=0:
43+
t=x/100
44+
f=cos(t)+(1/t**2)
45+
if f<6:
46+
line3.add_data_ns(t,f,draw_line=True)
47+
48+
for x in range(-2400,2400):
49+
t=x/80
50+
f=cos(t)*sin(t)*t
51+
line4.add_data_ns(t,f,draw_line=True)

0 commit comments

Comments
 (0)