Coordinates

Coordinates in Processing #

Processing similarly to Godot uses pixels for coordinates. The origin (0, 0) is also in the upper left of the window and the coordinate in the lower right is (width-1, height-1).

Example of Coordinates in Processing
// Sets the screen to be 640 pixels wide and 360 pixels high
size(640, 360);

// Set the background to black and turn off the fill color
background(0);
noFill();

// The two parameters of the point() function define its location.
// The first parameter is the x-coordinate and the second is the y-coordinate 
stroke(255);
point(320, 180);
point(320, 90); 

// Coordinates are used for drawing all shapes, not just points.
// Parameters for different functions are used for different purposes.
// For example, the first two parameters to line() specify 
// the coordinates of the first endpoint and the second two parameters 
// specify the second endpoint
stroke(0, 153, 255);
line(0, 120, 640, 120);

// The first two parameters to rect() are the coordinates of the 
// upper-left corner and the second pair is the width and height 
// of the rectangle
stroke(255, 153, 0);
rect(160, 36, 320, 288);

Coordinates in Godot #

Godot Coordinates Output

To replicate the same example in Godot, set the window size to 640 by 360 pixels:

Godot > menu Project > Project Settings… > tab General > Display > Window > Width: 640, Height: 360
Godot Screen Size

Set the background to black color.

Godot > menu Project > Project Settings… > tab General > Rendering > Environment > Define Clear Color
Godot Screen Color

Create Node2D called Main and attach a script: Godot Node2D Main with Script

extends Node2D
# Converted from https://processing.org/examples/coordinates.html
#
# Set the window size to 640 by 360 pixels in
# Godot > menu Project > Project Settings... > tab General > 
# Display > Window > Width: 640, Height: 360
#
# Set the background to black color in
# Godot > menu Project > Project Settings... > tab General > 
# Rendering > Environment > Define Clear Color

# Called automatically only once after enter scene tree. 
# If re-drawing is required, call update() on this node.
func _draw():
	draw_line(Vector2(320,180), Vector2(321,180),Color.white, 1, false)
	draw_line(Vector2(320,90), Vector2(321,90),Color.white, 1, false)
	draw_line(Vector2(0, 120), Vector2(640, 120), color256(0, 153, 255), 1, false)
	
	var points = [
		Vector2(160,36),
		Vector2(160+320,36),
		Vector2(160+320,288),
		Vector2(160,288),
		Vector2(160,36)
	]
	draw_rect(Rect2(160,36,320,288), color256(255,153,0), false)
	
# Helper to convert rgb values 0..255 to 0..1 range
func color256(r,g,b):
	return Color(r/255.0, g/255.0, b/255.0)

You can download the whole zipped Godot project here: 01-Coordinates.zip.