or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

camera-system.mdcore-graphics.mdgui-framework.mdindex.mdmath-utilities.mdphysics-engines.mdsound-system.mdspecialized-features.mdsprite-system.mdtexture-management.mdwindow-management.md

core-graphics.mddocs/

0

# Core Graphics and Drawing

1

2

Comprehensive 2D drawing functions for creating visual elements in games and applications. Arcade provides both immediate-mode drawing for simple graphics and batch rendering for performance-critical applications.

3

4

## Capabilities

5

6

### Filled Shape Drawing

7

8

Functions for drawing solid, filled geometric shapes with specified colors and positions.

9

10

```python { .api }

11

def draw_circle_filled(center_x: float, center_y: float, radius: float, color: arcade.types.Color, num_segments: int = -1) -> None:

12

"""

13

Draw a filled circle.

14

15

Args:

16

center_x: X coordinate of circle center

17

center_y: Y coordinate of circle center

18

radius: Radius of the circle

19

color: Color as RGB or RGBA tuple (0-255)

20

num_segments: Number of segments to use for drawing (default auto-calculated)

21

"""

22

23

def draw_ellipse_filled(center_x: float, center_y: float, width: float, height: float, color: arcade.types.Color, tilt_angle: float = 0, num_segments: int = -1) -> None:

24

"""

25

Draw a filled ellipse.

26

27

Args:

28

center_x: X coordinate of ellipse center

29

center_y: Y coordinate of ellipse center

30

width: Width of the ellipse

31

height: Height of the ellipse

32

color: Color as RGB or RGBA tuple (0-255)

33

tilt_angle: Rotation angle in degrees

34

num_segments: Number of segments to use for drawing (default auto-calculated)

35

"""

36

37

def draw_arc_filled(center_x: float, center_y: float, width: float, height: float, color: arcade.types.Color, start_angle: float, end_angle: float, tilt_angle: float = 0, num_segments: int = 128) -> None:

38

"""

39

Draw a filled arc (pie slice).

40

41

Args:

42

center_x: X coordinate of arc center

43

center_y: Y coordinate of arc center

44

width: Width of the arc

45

height: Height of the arc

46

color: Color as RGB or RGBA tuple (0-255)

47

start_angle: Start angle in degrees

48

end_angle: End angle in degrees

49

tilt_angle: Rotation angle of the entire arc in degrees

50

num_segments: Number of segments to use for drawing

51

"""

52

53

def draw_parabola_filled(start_x: float, start_y: float, end_x: float, height: float, color: arcade.types.Color, tilt_angle: float = 0) -> None:

54

"""

55

Draw a filled parabola.

56

57

Args:

58

start_x: X coordinate of parabola start

59

start_y: Y coordinate of parabola start

60

end_x: X coordinate of parabola end

61

height: Height of the parabola

62

color: Color as RGB or RGBA tuple (0-255)

63

tilt_angle: Rotation angle in degrees

64

"""

65

66

def draw_triangle_filled(x1: float, y1: float, x2: float, y2: float, x3: float, y3: float, color: arcade.types.Color) -> None:

67

"""

68

Draw a filled triangle.

69

70

Args:

71

x1, y1: First vertex coordinates

72

x2, y2: Second vertex coordinates

73

x3, y3: Third vertex coordinates

74

color: Color as RGB or RGBA tuple (0-255)

75

"""

76

77

def draw_polygon_filled(point_list: arcade.types.PointList, color: arcade.types.Color) -> None:

78

"""

79

Draw a filled polygon.

80

81

Args:

82

point_list: List of (x, y) coordinate tuples defining polygon vertices

83

color: Color as RGB or RGBA tuple (0-255)

84

"""

85

86

def draw_rectangle_filled(center_x: float, center_y: float, width: float, height: float, color: arcade.types.Color, tilt_angle: float = 0) -> None:

87

"""

88

Draw a filled rectangle.

89

90

Args:

91

center_x: X coordinate of rectangle center

92

center_y: Y coordinate of rectangle center

93

width: Width of the rectangle

94

height: Height of the rectangle

95

color: Color as RGB or RGBA tuple (0-255)

96

tilt_angle: Rotation angle in degrees

97

"""

98

99

def draw_lrbt_rectangle_filled(left: float, right: float, bottom: float, top: float, color: arcade.types.Color) -> None:

100

"""

101

Draw a filled rectangle using left, right, bottom, top coordinates.

102

103

Args:

104

left: Left edge X coordinate

105

right: Right edge X coordinate

106

bottom: Bottom edge Y coordinate

107

top: Top edge Y coordinate

108

color: Color as RGB or RGBA tuple (0-255)

109

"""

110

111

def draw_lbwh_rectangle_filled(left: float, bottom: float, width: float, height: float, color: arcade.types.Color) -> None:

112

"""

113

Draw a filled rectangle using left, bottom, width, height.

114

115

Args:

116

left: Left edge X coordinate

117

bottom: Bottom edge Y coordinate

118

width: Width of the rectangle

119

height: Height of the rectangle

120

color: Color as RGB or RGBA tuple (0-255)

121

"""

122

```

123

124

### Outline Shape Drawing

125

126

Functions for drawing shape outlines and borders with configurable line widths and styles.

127

128

```python { .api }

129

def draw_circle_outline(center_x: float, center_y: float, radius: float, color: arcade.types.Color, border_width: float = 1, num_segments: int = -1) -> None:

130

"""

131

Draw a circle outline.

132

133

Args:

134

center_x: X coordinate of circle center

135

center_y: Y coordinate of circle center

136

radius: Radius of the circle

137

color: Color as RGB or RGBA tuple (0-255)

138

border_width: Width of the outline in pixels

139

num_segments: Number of segments to use for drawing (default auto-calculated)

140

"""

141

142

def draw_ellipse_outline(center_x: float, center_y: float, width: float, height: float, color: arcade.types.Color, border_width: float = 1, tilt_angle: float = 0, num_segments: int = -1) -> None:

143

"""

144

Draw an ellipse outline.

145

146

Args:

147

center_x: X coordinate of ellipse center

148

center_y: Y coordinate of ellipse center

149

width: Width of the ellipse

150

height: Height of the ellipse

151

color: Color as RGB or RGBA tuple (0-255)

152

border_width: Width of the outline in pixels

153

tilt_angle: Rotation angle in degrees

154

num_segments: Number of segments to use for drawing (default auto-calculated)

155

"""

156

157

def draw_arc_outline(center_x: float, center_y: float, width: float, height: float, color: arcade.types.Color, start_angle: float, end_angle: float, border_width: float = 1, tilt_angle: float = 0, num_segments: int = 128) -> None:

158

"""

159

Draw an arc outline.

160

161

Args:

162

center_x: X coordinate of arc center

163

center_y: Y coordinate of arc center

164

width: Width of the arc

165

height: Height of the arc

166

color: Color as RGB or RGBA tuple (0-255)

167

start_angle: Start angle in degrees

168

end_angle: End angle in degrees

169

border_width: Width of the outline in pixels

170

tilt_angle: Rotation angle of the entire arc in degrees

171

num_segments: Number of segments to use for drawing

172

"""

173

174

def draw_parabola_outline(start_x: float, start_y: float, end_x: float, height: float, color: arcade.types.Color, border_width: float = 1, tilt_angle: float = 0) -> None:

175

"""

176

Draw a parabola outline.

177

178

Args:

179

start_x: X coordinate of parabola start

180

start_y: Y coordinate of parabola start

181

end_x: X coordinate of parabola end

182

height: Height of the parabola

183

color: Color as RGB or RGBA tuple (0-255)

184

border_width: Width of the outline in pixels

185

tilt_angle: Rotation angle in degrees

186

"""

187

188

def draw_triangle_outline(x1: float, y1: float, x2: float, y2: float, x3: float, y3: float, color: arcade.types.Color, border_width: float = 1) -> None:

189

"""

190

Draw a triangle outline.

191

192

Args:

193

x1, y1: First vertex coordinates

194

x2, y2: Second vertex coordinates

195

x3, y3: Third vertex coordinates

196

color: Color as RGB or RGBA tuple (0-255)

197

border_width: Width of the outline in pixels

198

"""

199

200

def draw_polygon_outline(point_list: arcade.types.PointList, color: arcade.types.Color, border_width: float = 1) -> None:

201

"""

202

Draw a polygon outline.

203

204

Args:

205

point_list: List of (x, y) coordinate tuples defining polygon vertices

206

color: Color as RGB or RGBA tuple (0-255)

207

border_width: Width of the outline in pixels

208

"""

209

210

def draw_rectangle_outline(center_x: float, center_y: float, width: float, height: float, color: arcade.types.Color, border_width: float = 1, tilt_angle: float = 0) -> None:

211

"""

212

Draw a rectangle outline.

213

214

Args:

215

center_x: X coordinate of rectangle center

216

center_y: Y coordinate of rectangle center

217

width: Width of the rectangle

218

height: Height of the rectangle

219

color: Color as RGB or RGBA tuple (0-255)

220

border_width: Width of the outline in pixels

221

tilt_angle: Rotation angle in degrees

222

"""

223

224

def draw_lrbt_rectangle_outline(left: float, right: float, bottom: float, top: float, color: arcade.types.Color, border_width: float = 1) -> None:

225

"""

226

Draw a rectangle outline using left, right, bottom, top coordinates.

227

228

Args:

229

left: Left edge X coordinate

230

right: Right edge X coordinate

231

bottom: Bottom edge Y coordinate

232

top: Top edge Y coordinate

233

color: Color as RGB or RGBA tuple (0-255)

234

border_width: Width of the outline in pixels

235

"""

236

237

def draw_lbwh_rectangle_outline(left: float, bottom: float, width: float, height: float, color: arcade.types.Color, border_width: float = 1) -> None:

238

"""

239

Draw a rectangle outline using left, bottom, width, height.

240

241

Args:

242

left: Left edge X coordinate

243

bottom: Bottom edge Y coordinate

244

width: Width of the rectangle

245

height: Height of the rectangle

246

color: Color as RGB or RGBA tuple (0-255)

247

border_width: Width of the outline in pixels

248

"""

249

```

250

251

### Line and Point Drawing

252

253

Functions for drawing lines, line strips, and individual points for creating linear graphics and debug visualization.

254

255

```python { .api }

256

def draw_line(start_x: float, start_y: float, end_x: float, end_y: float, color: arcade.types.Color, line_width: float = 1) -> None:

257

"""

258

Draw a single line between two points.

259

260

Args:

261

start_x: X coordinate of line start

262

start_y: Y coordinate of line start

263

end_x: X coordinate of line end

264

end_y: Y coordinate of line end

265

color: Color as RGB or RGBA tuple (0-255)

266

line_width: Width of the line in pixels

267

"""

268

269

def draw_lines(point_list: arcade.types.PointList, color: arcade.types.Color, line_width: float = 1) -> None:

270

"""

271

Draw multiple separate line segments.

272

273

Args:

274

point_list: List of (x, y) coordinates. Must have even number of points.

275

Each pair defines start and end of a line segment.

276

color: Color as RGB or RGBA tuple (0-255)

277

line_width: Width of the lines in pixels

278

"""

279

280

def draw_line_strip(point_list: arcade.types.PointList, color: arcade.types.Color, line_width: float = 1) -> None:

281

"""

282

Draw connected line segments (line strip).

283

284

Args:

285

point_list: List of (x, y) coordinates defining connected line segments

286

color: Color as RGB or RGBA tuple (0-255)

287

line_width: Width of the lines in pixels

288

"""

289

290

def draw_point(x: float, y: float, color: arcade.types.Color, size: float = 1) -> None:

291

"""

292

Draw a single point.

293

294

Args:

295

x: X coordinate of the point

296

y: Y coordinate of the point

297

color: Color as RGB or RGBA tuple (0-255)

298

size: Size of the point in pixels

299

"""

300

301

def draw_points(point_list: arcade.types.PointList, color: arcade.types.Color, size: float = 1) -> None:

302

"""

303

Draw multiple points.

304

305

Args:

306

point_list: List of (x, y) coordinate tuples defining point positions

307

color: Color as RGB or RGBA tuple (0-255)

308

size: Size of the points in pixels

309

"""

310

```

311

312

### Texture and Sprite Drawing

313

314

Functions for drawing textures and sprites with support for transformations, tinting, and rectangular regions.

315

316

```python { .api }

317

def draw_texture_rect(texture: arcade.Texture, rect: arcade.types.Rect, alpha: int = 255, angle: float = 0, repeat_count_x: int = 1, repeat_count_y: int = 1) -> None:

318

"""

319

Draw a texture in a rectangular area.

320

321

Args:

322

texture: Texture to draw

323

rect: Rectangle defining drawing area (x, y, width, height)

324

alpha: Transparency (0-255, where 255 is fully opaque)

325

angle: Rotation angle in degrees

326

repeat_count_x: Number of times to repeat texture horizontally

327

repeat_count_y: Number of times to repeat texture vertically

328

"""

329

330

def draw_sprite(sprite: arcade.Sprite) -> None:

331

"""

332

Draw an individual sprite.

333

334

Args:

335

sprite: Sprite object to draw

336

"""

337

338

def draw_sprite_rect(sprite: arcade.Sprite, rect: arcade.types.Rect) -> None:

339

"""

340

Draw a sprite in a specified rectangular area.

341

342

Args:

343

sprite: Sprite object to draw

344

rect: Rectangle defining drawing area (x, y, width, height)

345

"""

346

```

347

348

### Drawing Utilities

349

350

Utility functions for advanced line drawing and shape generation.

351

352

```python { .api }

353

def get_points_for_thick_line(start_x: float, start_y: float, end_x: float, end_y: float, line_width: float) -> arcade.types.PointList:

354

"""

355

Generate points for drawing a thick line as a polygon.

356

357

Args:

358

start_x: X coordinate of line start

359

start_y: Y coordinate of line start

360

end_x: X coordinate of line end

361

end_y: Y coordinate of line end

362

line_width: Width of the line

363

364

Returns:

365

List of (x, y) points defining the thick line polygon

366

"""

367

```

368

369

### Screen Capture

370

371

Functions for capturing screen content and reading pixel data.

372

373

```python { .api }

374

def get_image(x: int = 0, y: int = 0, width: int = None, height: int = None) -> PIL.Image.Image:

375

"""

376

Capture screen content as an image.

377

378

Args:

379

x: Left coordinate of capture area (default 0)

380

y: Bottom coordinate of capture area (default 0)

381

width: Width of capture area (default full window width)

382

height: Height of capture area (default full window height)

383

384

Returns:

385

PIL Image object containing captured screen data

386

"""

387

388

def get_pixel(x: int, y: int) -> tuple[int, int, int]:

389

"""

390

Get the color of a pixel at specific coordinates.

391

392

Args:

393

x: X coordinate of the pixel

394

y: Y coordinate of the pixel

395

396

Returns:

397

RGB color tuple (red, green, blue) with values 0-255

398

"""

399

```

400

401

### Rendering Control

402

403

Functions for managing the rendering pipeline and background settings.

404

405

```python { .api }

406

def start_render() -> None:

407

"""

408

Begin rendering a frame. Must be called before drawing operations.

409

"""

410

411

def finish_render() -> None:

412

"""

413

Complete rendering a frame. Must be called after all drawing operations.

414

"""

415

416

def set_background_color(color: arcade.types.Color) -> None:

417

"""

418

Set the window background color.

419

420

Args:

421

color: Background color as RGB or RGBA tuple (0-255)

422

"""

423

```

424

425

## Usage Examples

426

427

### Basic Shape Drawing

428

429

```python

430

import arcade

431

432

# Open a window

433

arcade.open_window(800, 600, "Shape Drawing")

434

arcade.set_background_color(arcade.color.WHITE)

435

436

arcade.start_render()

437

438

# Draw filled shapes

439

arcade.draw_circle_filled(100, 100, 50, arcade.color.RED)

440

arcade.draw_rectangle_filled(300, 100, 80, 120, arcade.color.BLUE)

441

arcade.draw_triangle_filled(500, 50, 450, 150, 550, 150, arcade.color.GREEN)

442

443

# Draw outlines

444

arcade.draw_circle_outline(100, 300, 50, arcade.color.BLACK, 3)

445

arcade.draw_rectangle_outline(300, 300, 80, 120, arcade.color.BLACK, 2)

446

447

# Draw lines and points

448

arcade.draw_line(50, 500, 150, 500, arcade.color.PURPLE, 5)

449

arcade.draw_points([(200, 500), (220, 520), (240, 500), (260, 520)],

450

arcade.color.ORANGE, 8)

451

452

arcade.finish_render()

453

arcade.run()

454

```

455

456

### Complex Polygon Drawing

457

458

```python

459

import arcade

460

import math

461

462

def create_star_points(center_x, center_y, outer_radius, inner_radius, points=5):

463

"""Generate points for a star polygon."""

464

point_list = []

465

for i in range(points * 2):

466

angle = math.radians(i * 180 / points)

467

radius = outer_radius if i % 2 == 0 else inner_radius

468

x = center_x + radius * math.cos(angle)

469

y = center_y + radius * math.sin(angle)

470

point_list.append((x, y))

471

return point_list

472

473

arcade.open_window(400, 400, "Star Polygon")

474

arcade.set_background_color(arcade.color.BLACK)

475

476

arcade.start_render()

477

478

# Draw a filled star

479

star_points = create_star_points(200, 200, 100, 50)

480

arcade.draw_polygon_filled(star_points, arcade.color.YELLOW)

481

482

# Draw star outline

483

arcade.draw_polygon_outline(star_points, arcade.color.RED, 3)

484

485

arcade.finish_render()

486

arcade.run()

487

```