~jagtalon/generative-art-template

ref: c37f3082110958b09cbb5a4703c7700e148d5328 generative-art-template/tiny-canvas.coffee -rw-r--r-- 951 bytes
c37f3082Jag Talon Use /bin/sh instead of /bin/bash 8 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
export default class TinyCanvas
	constructor: (@context) ->

	circle: (x, y, radius, startAngle = 0, endAngle = Math.PI * 2) ->
		@context.beginPath()
		@context.arc x, y, radius, startAngle, endAngle

	stroke: (color = "#000000", lineWidth = 10, lineCap = "butt") ->
		@context.strokeStyle = color
		@context.lineWidth = lineWidth
		@context.lineCap = lineCap
		@context.stroke()

	fill: (color = "#000000") ->
		@context.fillStyle = color
		@context.fill()

	rotate: (angle) ->
		@context.rotate(angle)

	rect: (x, y, width, height, mode = "fill", color = "#000000") ->
		if mode == "fill"
			@context.fillStyle = color
			@context.fillRect 0, 0, width, height
		else
			@context.strokeStyle = color
			@context.strokeRect 0, 0, width, height

	translate: (x, y) ->
		@context.translate x, y

	text: (x, y, character, color = "#000000", font = 'monospace') ->
		@context.fillStyle = color
		@context.font = font
		@context.fillText character, x, y