Deutsch   English   

Documentation GPanel

Import: from gpanel import *

Start example programs by clicking on links
[WebTJ] only WebTigerJython


Function Action
makeGPanel() creates a GPanel graphics window with coordinates (x = 0..1, y = 0..1). Current cursor at (0, 0)
makeGPanel(xmin, xmax, ymin, ymax)
creates a GPanel graphics window with given float coordinate system. Current cursor at (0, 0)
makeGPanel(Size(width, height))
same as makeGPanel(), but window size user selectable (in pixels)
getScreenWidth()
returns the screen width (in pixels))
getScreenHeight()
returns the screen height (in pixels)
window(xmin, xmax, ymin, ymax)
sets a new coordinate span
drawGrid(x1, x2, y1, y2)

draws a coordinate grid with 10 ticks in range x1..x2, y1..y2. Label text depends if x, y or int or float

drawGrid(x1, x2, y1, y2, color)

same with given grid color

same with given number of ticks x3, y3 in x- and y-direction

same with given grid color

bgColor(color) sets the background color (X11-colors)
storeGraphics() [WebTJ] stores the current graphics in internal image buffer
recallGraphics() [WebTJ] renders the content of the internal image buffer
delay(time) pauses the program execution for given amount of time (in ms)
getDividingPoint(pt1, pt2, ratio) returns the point that divides the line from pt1 to pt2 with the given ratio (may be negative and greater than 1)
clear() clears the graphics window and sets the graphics cursor to (0, 0)
erase() clears the graphics window without changing the position of the graphics cursor

Drawing
lineWidth(width) resumes paused program execution
setColor(color) sets die drawing color (X11 color string)
move(x, y) moves cursor to (x, y) without drawing a line
getPosX() returns the cursor's current x-coordinate
getPosY() returns the cursor's current y-coordinate
getPos() returns the cursor current x-, y-coordinates as list
draw(x, y) draws line to (x, y) and updates cursor
draw(coord_list) draws line to coord. list and updates cursor
line(x1, y1, x2, y2) draws line from (x1, y1) to (x2, y2) without modifying cursor
line(pt1, pt2) draws line from pt1 = [x1, y1] to pt2 = [x2, y2] without modifying cursor
circle(radius) draws circle with center at current cursor position and given radius (in x-coordinate units)
fillCircle(radius) draws fiilled circle with center at current cursor position and given radius (fill color = pen color)
ellipse(a, b) draws ellipse with center at current cursor positon and given semiaxis
fillEllipse(a, b) draws ellipse with center at current cursor positon and given semiaxis (fill color = pen color)
rectangle(a, b) draws rectangle with center at current cursor position and given width and height
rectangle(x1, y1, x2, y2) draws rectangle with center at current cursor position and given diagonal
rectangle(pt1, pt2) same with diagonal point lists
fillRectangle(a, b) draws filled rectangle with center at cursor and given width and height (fill color = pen color)
fillRectangle(x1, y1, x2, y2) draws filled rectangle with center at cursor and given diagonal (fill color = pen color)
fillRectangle(pt1, pt2) same with diagonal point lists)
arc(radius, startAngle, extendAngle)
draws arc with center at cursor and given radius, start and sector angle (0 to east, positive counterclockwise)
fillArc(radius, startAngle, extendAngle)
same, but filled (fill color = pen color)
polygon([pt1, pt2,..]) draws polygon with list of point lists pt1, pt2,...
fillPolygon([pt1, pt2,..]) draws filled polygon with list of point lists pt1, pt2,...
quadraticBezier(x1, y1, xc, yc, x1, y2)
draws quadratic Bezier-curve with 2 points (x1, y1), (x2, y2) and control point (xc, yc)
quadraticBezier(pt1, pc, pt2)
same with points
cubicBezier(x1, y1, xc1, yc1, xc2, yc2, x2, y2)
draws cubic Bezier-curve with 2 points (x1, y1), (x2, y2) and two control points (xc1, yc1), (yc2, yc2)
cubicBezier(pt1, ptc1, ptc2, pt2)
same with points
triangle(x1, y1, x2, y2, x3, y3)
draws a triangle with vertexes from x-, y-coordinates
triangle(pt1, pt2, pt3)
same with point lists
fillTriangle(x1, y1, x2, y2, x3, y3)
draws a filled triangle with vertexes from x-, y-coordinates (fill color = pen color)
fillTriangle(pt1, pt2, pt3)
draws a filled triangle with vertexes from x-, y-coordinates (fill color = pen color)
point(x, y) draws one single point (pixel) at (x, y)
point(pt)

same with point list

enableRepaint(boolean) [WebTJ] enables/disables automatic rendering of the offscreen buffer (default: enabled)
repaint() [WebTJ] renders the offscreen buffer on screen (necessary if the automatic rendering is disabled)
getPixelColor(x, y) returns color of pixel at (x, y) as list [r, g, b]
getPixelColorStr(x, y) returns color of pixel at (x, y) as X11 color string,
in WebTigerJython as Hex-Farbcode (z.B. #ff0000)

Text
text(string) displays text starting at current cursor position
text(x, y, string) display text starting at given x-, y-coordinates
text(pt, string) same with point list

Callbacks (Mausevents)

makeGPanel(mouseNNN = onMouseNNN)
use a comma separator to register more than one

registers the callback function onMouseNNN(x, y) that is called when a mouse event happens. Values for NNN: Pressed, Released, Clicked, Dragged, Moved, Entered, Exited, SingleClicked, DoubleClicked

isLeftMouseButton(),
isRightMouseButton()

returns True, if the event is caused by the left/right mouse button

Tastatur
makeGPanel(keyPressed = onKeyPressed) registers the callback onKeyPressed(keyCode) that is called when a keyboard key is hit. keyCode is a unique integer value that identifies the key
onKeyPressed(key) Callbackfunction, returns key. In WebTigerJython the numeric code of the key pressed, in WebTigerPython the name of the key pressed( Enter, Escape, ArrowUp, r, g, ....)


Font-Format
Font(name, style, size) creates a new font with given name, style and size
name a string with a font name available on the system, e.g. "Times New Roman", "Arial", "Courier"
style one of the stype constants: Font.PLAIN, Font.BOLD, Font.ITALIC, may also be combined: Font.BOLD + Font.ITALIC
size an integer with an available font size in pixels, e.g. 12, 16, 72


Dialoge   
inputInt(prompt) opens a dialog with OK/Cancel buttons. OK returns integer (the dialog is shown again, if no integer is entered). Cancel or Close terminate the program. The named parameter init sets an initialising value.
inputFloat(prompt) opens a dialog with OK/Cancel buttons. OK returns float (the dialog is shown again, if no float is entered). Cancel or Close terminate the program. The named parameter init sets an initialising value
inputString(prompt) opens a dialog with OK/Cancel buttons. OK returns string. Cancel or Close terminate the program. The named parameter init sets an initialising value