StrokePath

Represents a single paint stroke with color, path, and brush width.

Overview

StrokePath is a dataclass that defines an individual stroke to be painted. Each stroke consists of:

  • A color (RGB tuple)
  • A path (list of x,y coordinates)
  • A brush width (thickness)

Definition

from dataclasses import dataclass

@dataclass
class StrokePath:
    color: tuple[int, int, int]  # (r, g, b)
    path: list[tuple[int, int]]   # [(x, y), ...]
    brushDiameter: int = 2

Attributes

Attribute Type Default Description
color tuple[int, int, int] Required RGB color values (0-255 each)
path list[tuple[int, int]] Required List of coordinate points in pixels
brushDiameter int 2 Stroke thickness in pixels

Creating a Stroke

Basic Stroke

from paintbot.datatypes.strokes import StrokePath

# Simple red line
stroke = StrokePath(
    color=(255, 0, 0),
    path=[(0, 0), (100, 0)]
)

With Custom Brush Width

# Thick blue line
stroke = StrokePath(
    color=(0, 0, 255),
    path=[(10, 10), (50, 50), (100, 10)],
    brushDiameter=5
)

Complex Path

# Green wavy path
stroke = StrokePath(
    color=(0, 255, 0),
    path=[
        (0, 100), (25, 80), (50, 100),
        (75, 80), (100, 100), (125, 80),
        (150, 100)
    ],
    brushDiameter=3
)

Color Reference

Common Colors

Color RGB Hex
Red (255, 0, 0) #FF0000
Green (0, 255, 0) #00FF00
Blue (0, 0, 255) #0000FF
Black (0, 0, 0) #000000
White (255, 255, 255) #FFFFFF
Yellow (255, 255, 0) #FFFF00
Cyan (0, 255, 255) #00FFFF
Magenta (255, 0, 255) #FF00FF

Grayscale

light_gray = (200, 200, 200)
dark_gray = (50, 50, 50)

Path Design

Straight Line

stroke = StrokePath(
    color=(0, 0, 0),
    path=[(0, 0), (100, 100)]  # Diagonal line from (0,0) to (100,100)
)

Curved Path (Multiple Points)

# Approximates a curve with line segments
stroke = StrokePath(
    color=(100, 150, 200),
    path=[
        (0, 50),
        (25, 20),
        (50, 15),
        (75, 25),
        (100, 50)
    ]
)

Closed Shape

# Square
stroke = StrokePath(
    color=(255, 0, 0),
    path=[
        (0, 0),
        (100, 0),
        (100, 100),
        (0, 100),
        (0, 0)  # Close the shape
    ],
    brushDiameter=2
)

Usage in StrokeSequence

from paintbot.datatypes.strokes import StrokeSequence, StrokePath

# Create sequence
sequence = StrokeSequence(image_size=(800, 600))

# Create and add strokes
for i in range(5):
    stroke = StrokePath(
        color=(i * 50, 100, 200 - i * 40),
        path=[(0, i * 100), (800, i * 100)],
        brushDiameter=2
    )
    sequence.strokes.append(stroke)

# Visualize
sequence.visualize()

Brush Width Guidelines

Width Use Case
1-2 Fine details, thin lines
2-4 Normal brush strokes
5-10 Bold lines, thick strokes
10+ Large fills, broad strokes

Coordinate System

  • Origin (0, 0): Top-left corner
  • X-axis: Increases left to right
  • Y-axis: Increases top to bottom
  • Units: Pixels
(0,0)          (width, 0)
  +----------------+
  |                |
  |                | height
  |                |
  +----------------+
(0,height)  (width, height)

Accessing Stroke Data

stroke = StrokePath(
    color=(255, 0, 0),
    path=[(0, 0), (100, 100)],
    brushDiameter=3
)

# Access attributes
red, green, blue = stroke.color
print(f"Color: R={red}, G={green}, B={blue}")

start_x, start_y = stroke.path[0]
print(f"Start: ({start_x}, {start_y})")

print(f"Thickness: {stroke.brushDiameter} pixels")
print(f"Path length: {len(stroke.path)} points")

Notes

  • All coordinates are in pixels
  • Color values must be integers 0-255
  • Path must contain at least 2 points for a valid stroke
  • Brush width must be at least 1 pixel
  • Paths are modified in-place (no immutability)

See Also