Simple graphic library for beginners

bartc bc at freeuk.com
Thu Jan 11 08:38:27 EST 2018


On 11/01/2018 05:16, Michael Torrie wrote:
> On 01/10/2018 01:13 PM, bartc wrote:

> Yes the link didn't have the simple examples I hoped for.  How's this:
> -----------------------------
> import pygame
> import time
> 
> pygame.init()
> screen = pygame.display.set_mode((1024, 768) )
> red = (255,0,0)
> green = (0,255,0)
> 
> screen.fill( (255,255,255) )
> pygame.draw.lines(screen, red, False, ((0,0),(100,100)))
> pygame.draw.lines(screen, green, False, ((0,100),(100,0)))
> pygame.display.update()
> 
> time.sleep(5)
> pygame.quit()
> ------------------------------

That looks reasonable.

Although I can't run it because 'pygame' is not available. I think 
installing this library is likely to be a bigger obstacle than 
programming any graphics!

(If I try and download it as a ready-built library for Windows, it has a 
range of .msi files, none of which is a match for my Python. The newest 
is for win32 Py3.2; I need win64 Py3.6. While building from source 
involves running MSVC 2008 .... urghh)

> PyGame has other primitives like circles, ellipses, etc.  Much like the
> old BASIC graphics primitives.
> 
>> 'Turtle' will do it (assuming there's a way of drawing things without
>> having to watch an actual turtle symbol crawling around the screen).
> 
> Yes I think it can.
> 
>> One simple library of my own (not for Python) would use one function
>> call to create a window, and another to draw an element (say, a box)
>> within that window. (Plus a third to keep it on the screen otherwise it
>> will disappear when the program terminates.)
> 
> Are you thinking of sprites?

No. I've put an example of my library, roughly corresponding to what I 
believe your example does, below my sig (as it is not Python). This is 
fairly low level and expects to have another layer applied, but it is 
not too bad to use directly.

(This library actually is entirely implemented in the byte-code 
language, and talks directly to Win32 API.

That would be the equivalent of Pygame being written in 100% Python, 
which would make it trivial to install. But some elements would need to 
be different according to platform.)

-- 
Bartc

-----------------------------------------
import gxlib

proc start=

	w := gxcreatewindow(dim:(1024,768))

	gxclear(w,getrgb(yellow))    # window is already white

	gxcolour(w, getrgb(red))
	gxline(w, 0,0, 100,100)

	gxcolour(w, getrgb(green))
	gxline(w, 0,0, 100,0)

	eventloop()

end



More information about the Python-list mailing list