@@ -43,7 +43,6 @@ class PLOT:
43
43
Defaults to white ''(255, 255, 255)``
44
44
:param int tickx_height: x axes tick height in pixels. Defaults to 8.
45
45
:param int ticky_height: y axes tick height in pixels. Defaults to 8.
46
- :param int scale: scale of the plot. Defaults to 1.
47
46
48
47
"""
49
48
@@ -65,8 +64,12 @@ def __init__(
65
64
self ._background_color = set_color (
66
65
display , 0 , background_color [0 ], background_color [1 ], background_color [2 ]
67
66
)
67
+
68
68
self ._tickcolor = set_color (display , 1 , 255 , 255 , 255 )
69
69
self ._boxcolor = set_color (display , 2 , box_color [0 ], box_color [1 ], box_color [2 ])
70
+ self ._color0 = background_color
71
+ self ._color1 = box_color
72
+ self ._color2 = (255 , 255 , 255 )
70
73
71
74
self ._axesparams = "box"
72
75
self ._decimal_points = None
@@ -366,6 +369,7 @@ def tick_params(
366
369
self ._tickcolor = set_color (
367
370
self ._display , 1 , tickcolor [0 ], tickcolor [1 ], tickcolor [2 ]
368
371
)
372
+ self ._color2 = tickcolor
369
373
370
374
self ._tickgrid = tickgrid
371
375
self ._showtext = showtext
@@ -395,7 +399,7 @@ def show_text(
395
399
distance = 5
396
400
397
401
if ax == "y" :
398
- x = x - font_width - distance
402
+ x = x - font_width * ( len ( text )) - distance
399
403
y = y - font_height // 2
400
404
if ax == "x" :
401
405
x = x - font_width // 2
@@ -449,16 +453,64 @@ def _draw_gridx(self, ticks_data: list[int]) -> None:
449
453
)
450
454
start = start - self ._grid_espace - self ._grid_lenght
451
455
452
- def writeplainpbm (self , file ):
456
+ def _writeplainpbm (self , file : str = "newfile.pbm" ):
453
457
"""
454
458
Function to write a plain pbm file
459
+ adapted from https://github.com/orgs/micropython/discussions/10785
460
+ Author: Stewart Russell
455
461
"""
456
462
with open (file , "wb" ) as file_write :
457
463
file_write .write ("P1" + "\n " )
458
464
file_write .write (str (480 ) + " " + str (320 ) + "\n " )
459
465
for y in range (320 ):
460
466
for x in range (480 ):
461
- print (str (self ._display .pixel (x , y )))
462
467
file_write .write (str (self ._display .pixel (x , y )))
463
468
file_write .write ("\n " )
464
469
file_write .close ()
470
+
471
+ def _savingppm (self , filename : str = "picture.ppm" , width = 480 , height = 320 ):
472
+ """
473
+ Function to save the screen as a ppm file
474
+ Adapted from https://gist.github.com/nicholasRutherford/c95a55239e03ba99bab3
475
+ Author: Nicholas Rutherford
476
+
477
+ :param str filename: picture filename
478
+ :param int width: screenshot width in pixels
479
+ :param int height: screenshot height in pixels
480
+
481
+ This function requires adding the colors used manually in the z list
482
+ """
483
+
484
+ z = [
485
+ self ._color0 ,
486
+ self ._color2 ,
487
+ self ._color1 ,
488
+ (255 , 255 , 0 ),
489
+ (255 , 69 , 69 ),
490
+ (34 , 98 , 129 ),
491
+ ]
492
+
493
+ # Header values for the file
494
+ comment = b"MicroPlot"
495
+ ftype = b"P6"
496
+
497
+ # First write the header values
498
+ with open (filename , "wb+" ) as ppmfile :
499
+ ppmfile .write (b"%s\n " % (ftype ))
500
+ ppmfile .write (b"#%s\n " % comment )
501
+ ppmfile .write (b"%d %d\n " % (width , height ))
502
+ ppmfile .write (b"255\n " )
503
+
504
+ for y in range (height ):
505
+ for x in range (width ):
506
+ if self ._display .pixel (x , y ) > 5 :
507
+ print (self ._display .pixel (x , y ))
508
+ ppmfile .write (
509
+ b"%c%c%c"
510
+ % (
511
+ z [self ._display .pixel (x , y )][0 ],
512
+ z [self ._display .pixel (x , y )][1 ],
513
+ z [self ._display .pixel (x , y )][2 ],
514
+ )
515
+ )
516
+ ppmfile .close ()
0 commit comments