Width and Height

Width and Height in Processing #

Processing defines window ‘width’ and ‘height’ variables set in the size() function.

Example of Width and Height in Processing
void setup() {
  size(640, 360);
}

void draw() {
  background(127);
  noStroke();
  for (int i = 0; i < height; i += 20) {
    fill(129, 206, 15);
    rect(0, i, width, 10);
    fill(255);
    rect(i, 0, 10, height);
  }
}

Width and Height in Godot #

Godot Coordinates Output

To replicate the 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 gray color 127,127,127.

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/widthheight.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 gray color in
# Godot > menu Project > Project Settings... > tab General > 
# Rendering > Environment > Define Clear Color

# Register the size_changed event
func _ready():
	get_tree().get_root().connect("size_changed", self, "on_size_changed")

# Event called on window size change
func on_size_changed():
	print("Resizing: ", get_viewport_rect().size)

# Called automatically only once after enter scene tree. 
# If re-drawing is required, call update() on this node.
func _draw():
	var size = get_viewport_rect().size
	var width = size.x
	var height = size.y
	
	# Alternative way to set the background color:
	# draw_rect(Rect2(0, 0, width-1, height-1), Color.lightgray, true)
	
	for i in range(0, height, 20):
		draw_rect(Rect2(0, i, width, 10), color256(129, 206,15), true)
		draw_rect(Rect2(i, 0, 10, height), Color.white, true)

# 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: 02-WidthAndHeight.zip.