Post Reply 
Python graphic module: observations, assumptions, suggestions
11-30-2021, 08:50 PM (This post was last modified: 12-01-2021 07:19 PM by Guenter Schink.)
Post: #1
Python graphic module: observations, assumptions, suggestions
I've downloaded the last (inofficial?) update to see if something significant has changed in the Python environment. Well the <draw_filled_polygon()> function no longer lets the G2 reboot Smile Here are my findings. I don't pretend that they are correct, however...

I had a closer look at the various entries of the "graphic module"
  1. cyan, magenta, yellow, blue, red, green, black, and white are simply constants of which you can simply print what values they consist of. Caution: new values can be assigned easily.
  2. set_pixel(), draw_pixel: can't see any difference. 3 arguments --> (x, y, color) Various experiments with lists and tuples (a list of pixels perhaps), always raised syntax error
  3. draw_line: 5 arguments --> (x1,y1,x2,y2,color) no surprise
  4. draw_polygon(): 2 arguments. -->list (or tuple) of coordinates, color. No need to repeat the first co-ordinate, the polygon simply closes in on the first point. E.g. draw_polygon([(10,10),(100,100),(10,200)],red) gives you a nice triangle, not filled, red perimeter.
  5. draw_filled_polygon(): same as above. Observation: draw_filled_polygon([(0,80),(160,120),(0,80)],red) draws two triangles heading their tips to each other. the right hand triangle has a center line of the background color. This doesn't seem to occur when one of the "80" is changed to e.g. "81" or "79" - weird.
  6. draw_rectangle(): arguments --> (x, y, width, height, color) . Should draw the perimeter of an rectangle - instead it draws a filled rectangle like the next one.
  7. fill_rect(), draw_filled_rectangle(): can't see any difference. Arguments as above.
  8. draw_circle(), draw_filled_circle(): As the name suggests either unfilled or filled circle. 4 Arguments --> (x,y, radius,color) no surprise
  9. draw_arc(),draw_filled_arc(): As the name suggests either unfilled or filled arc: 6-8 arguments -->(x,y, x_radius, y_radius, angle_start, angle_end[, color[, unknown_int]] An angle of "0" denotes "east" the arc is painted clockwise. Observation ERROR: The draw_arc() doubles the angle values, while the draw_filled_arc() behaves as expected. The last argument "unknown_int" didn't show any effect with my various approaches. Color can be omitted, default is black - it's 0
  10. get_pixel() doesn't return anything reasonable: 2 or 3 arguments: When invoked with 2 arguments it returns the tuple (0,0,0) when invoked with 3 arguments it returns -16777216 that equals -0x1000000
  11. draw_string(): seems to be broken but does something at least. 3-6 arguments --> (x,y,text[,text_color[,bg-color[,unknown-string]]]: Observation: The "unknown_string" did nothing discernible. A background is always painted, but doesn't match the height of the text. If bg-color is omitted, my Prime selects cyan, why? If the text_color is omitted the color is black. The font is very large!
  12. clear() and clear_screen() can't see any difference: Arguments 0 or 1 --> () denotes cyan, (color) whatever color you've chosen.


To get around the wrong implementation of draw_rectangle() and draw_arc() I've written a small workaround. The objective is to code as if the functions worked properly, so once they are rectified there's only minimum change to the code. Only the alias import and the two definitions would have to be deleted.


Code:
from graphic import *
from graphic import draw_arc as d_arc 
# this allows to redefine draw_arc while preserving the ability of the original function

def draw_rectangle(x,y,width,height,color): 
     # this overwrites the function of graphics with the same name
      draw_polygon([(x,y),(x+width,y),(x+width,y+height),(x,y+height)],color)

def draw_arc(x,y,x_radius,y_radius,start,end,color):
       d_arc(x, y, x_radius, y_radius, start//2, end//2, color)
       # using the original function but correcting the angles

Hope this is of use for someone. Perhaps you have a different insight. Comments, corrections are very welcome of course.

G√ľnter

edit: added some missing arguments
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Python graphic module: observations, assumptions, suggestions - Guenter Schink - 11-30-2021 08:50 PM



User(s) browsing this thread: 1 Guest(s)