pixelflow_canvas 0.7.3 → 0.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE +674 -0
- data/docs/.gitignore +15 -0
- data/docs/Gemfile +7 -0
- data/docs/Gemfile.lock +92 -0
- data/{LICENSE.txt → docs/LICENSE} +6 -6
- data/docs/README.md +174 -0
- data/docs/_config.yml +11 -0
- data/docs/advanced_use.md +37 -0
- data/docs/drawing_things.md +296 -0
- data/docs/images/4x6.png +0 -0
- data/docs/images/6x10.png +0 -0
- data/docs/images/7x13.png +0 -0
- data/docs/images/7x13B.png +0 -0
- data/docs/images/8x13.png +0 -0
- data/docs/images/8x13B.png +0 -0
- data/docs/images/9x15.png +0 -0
- data/docs/images/9x15B.png +0 -0
- data/docs/images/code/0ba813cd6b7e0ae0.png +0 -0
- data/docs/images/code/30c5ac94e5fa22ba.png +0 -0
- data/docs/images/code/3871051301832e44.png +0 -0
- data/docs/images/code/40acf0284459aa0e.png +0 -0
- data/docs/images/code/4eb9d4f97e05c739.png +0 -0
- data/docs/images/code/584e2ee3b7526718.png +0 -0
- data/docs/images/code/7fa15cea8c83a542.png +0 -0
- data/docs/images/code/809d9ce7d7a8ce6c.png +0 -0
- data/docs/images/code/85abc3576f6d78b1.png +0 -0
- data/docs/images/code/ec32331b354119d2.png +0 -0
- data/docs/images/code/ef667cfe7ff65c27.png +0 -0
- data/docs/index.md +126 -0
- data/docs/palettes.md +3192 -0
- data/docs/render-docs.rb +98 -0
- data/lib/pixelflow_canvas/palettes.yaml +257 -0
- data/lib/pixelflow_canvas/version.rb +1 -1
- data/lib/pixelflow_canvas.rb +28 -13
- metadata +33 -9
- data/sig/pixelflow_canvas.rbs +0 -4
- data/test-anaglyph.rb +0 -15
- data/test-sirds.rb +0 -46
- data/test-triangle.rb +0 -25
- data/test-turtle.rb +0 -14
- data/test.rb +0 -36
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/docs/index.md
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
---
|
2
|
+
title: Getting started
|
3
|
+
layout: home
|
4
|
+
nav_order: 0
|
5
|
+
---
|
6
|
+
|
7
|
+
<style>
|
8
|
+
img.full {
|
9
|
+
width: 100%;
|
10
|
+
max-width: 100%;
|
11
|
+
margin: 0;
|
12
|
+
padding: 0;
|
13
|
+
image-rendering: pixelated;
|
14
|
+
}
|
15
|
+
</style>
|
16
|
+
|
17
|
+
# Pixelflow Canvas (Ruby driver)
|
18
|
+
|
19
|
+
A virtual CRT for old school graphics programming in Visual Studio Code.
|
20
|
+
|
21
|
+
The Pixelflow Canvas is a simple library for creating pixel graphics, animations or interactive experiments in Ruby. It provides a canvas that you can draw on using a fixed palette of 256 colors or 24-bit RGB values. The canvas can be displayed in Visual Studio Code using the Pixelflow Canvas extension.
|
22
|
+
|
23
|
+
{: .info }
|
24
|
+
This is the documentation for the pixelflow_canvas rubygem which requires the [»Pixelflow Canvas«](https://marketplace.visualstudio.com/items?itemName=gymnasiumsteglitz.pixelflow-canvas) Visual Studio Code extension to work. You can find the documentation for the VS Code extension [here](https://specht.github.io/pixelflow_canvas_vscode/).
|
25
|
+
|
26
|
+
## Creating a canvas
|
27
|
+
|
28
|
+
There are two ways to work with a canvas.
|
29
|
+
|
30
|
+
### Working with an instance
|
31
|
+
|
32
|
+
Specify the width, height, and color mode (either `:palette` or `:rgb`) to create a new canvas:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
require 'pixelflow_canvas'
|
36
|
+
|
37
|
+
canvas = Pixelflow::Canvas.new(32, 18, :palette)
|
38
|
+
canvas.set_pixel(16, 9, 10)
|
39
|
+
```
|
40
|
+
|
41
|
+
This should produce the following output:
|
42
|
+
|
43
|
+
<!-- code begin
|
44
|
+
Pixelflow::Canvas.new(32, 18, :palette) do
|
45
|
+
set_pixel(16, 9, 10)
|
46
|
+
end
|
47
|
+
code end --><img class='full' src='images/code/7fa15cea8c83a542.png'>
|
48
|
+
|
49
|
+
### Pass a block to the constructor
|
50
|
+
|
51
|
+
This method allows you to omit the `canvas` variable on every method call:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
Canvas.new(320, 180, :palette) do
|
55
|
+
set_pixel(160, 90, 10)
|
56
|
+
end
|
57
|
+
```
|
58
|
+
|
59
|
+
You can also use the `perform` method to run a block on an existing canvas:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
canvas = Canvas.new(320, 180, :palette)
|
63
|
+
canvas.perform do
|
64
|
+
set_pixel(160, 90, 10)
|
65
|
+
end
|
66
|
+
```
|
67
|
+
|
68
|
+
## Modes of operation
|
69
|
+
|
70
|
+
The following modes of operation affect how the canvas is working and how it is displayed.
|
71
|
+
|
72
|
+
### Color modes
|
73
|
+
|
74
|
+
There are two color modes: `:palette` and `:rgb`. In palette mode, the canvas uses a fixed palette of 256 colors and each pixel is represented by an index (0...255) into this palette. In RGB mode, each pixel is represented by a 24-bit RGB value.
|
75
|
+
|
76
|
+
The default color mode is `:rgb`. It can be changed by calling `set_color_mode`.
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
canvas.set_color_mode(:palette)
|
80
|
+
```
|
81
|
+
|
82
|
+
### Double buffering
|
83
|
+
|
84
|
+
There are two drawing modes: `:direct` and `:buffered`. In direct mode, every pixel gets drawn immediately. In buffered mode, the canvas is drawn to an off-screen buffer and then copied to the screen when `flip` is called. Double buffering is useful for animations to prevent flickering.
|
85
|
+
|
86
|
+
The default drawing mode is `:direct`. It can be changed by calling `set_draw_mode`.
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
canvas.set_draw_mode(:buffered)
|
90
|
+
```
|
91
|
+
|
92
|
+
{: .info }
|
93
|
+
If you get a black canvas in buffered mode, make sure to call `flip` at the end of your drawing code.
|
94
|
+
|
95
|
+
### Composition modes
|
96
|
+
|
97
|
+
There are three composition modes: `:copy`, `:add`, `:subtract` and `:multiply`.
|
98
|
+
|
99
|
+
- `:copy` copies the source pixel to the destination pixel
|
100
|
+
- `:add` adds the source pixel to the destination pixel
|
101
|
+
- `:subtract` subtracts the source pixel from the destination pixel
|
102
|
+
- `:multiply` multiplies the source pixel with the destination pixel
|
103
|
+
|
104
|
+
The default composition mode is `:copy`. It can be changed by calling `set_composition_mode`.
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
canvas.set_composition_mode(:add)
|
108
|
+
```
|
109
|
+
|
110
|
+
{: .info }
|
111
|
+
Composition modes other than `:copy` require the canvas to be in RGB mode.
|
112
|
+
|
113
|
+
### Interpolation modes
|
114
|
+
|
115
|
+
There are two interpolation modes: `:nearest` and `:bilinear`. This mode only affects the display of the canvas in the Visual Studio Code extension.
|
116
|
+
|
117
|
+
The default interpolation mode is `:nearest`. It can be changed by calling `set_interpolation_mode`.
|
118
|
+
|
119
|
+
```ruby
|
120
|
+
canvas.set_interpolation_mode(:bilinear)
|
121
|
+
```
|
122
|
+
<!--
|
123
|
+
- Using masks
|
124
|
+
- Saving the canvas
|
125
|
+
- Event polling
|
126
|
+
-->
|