-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathDoubleBuffer.cs
More file actions
59 lines (48 loc) · 1.22 KB
/
DoubleBuffer.cs
File metadata and controls
59 lines (48 loc) · 1.22 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DoubleBuffer : MonoBehaviour {
private Framebuffer temp = new Framebuffer();
private Framebuffer current = new Framebuffer();
private Framebuffer next = new Framebuffer();
private void Start() {
Draw();
for (int i = 0; i < current.pixels.Length; i++) {
Debug.Log(current.pixels[i]);
}
}
private void Draw() {
next.Clear();
next.Draw(1, 1);
next.Draw(4, 1);
next.Draw(1, 3);
next.Draw(2, 4);
next.Draw(3, 4);
next.Draw(4, 3);
Swap();
}
private void Swap() {
temp = current;
current = next;
next = temp;
}
}
class Framebuffer {
private const int WIDTH = 6;
private const int HEIGHT = 6;
public Color[] pixels = new Color[WIDTH * HEIGHT];
public Framebuffer() {
Clear();
}
public void Clear() {
for (int i = 0; i < WIDTH * HEIGHT; i++) {
pixels[i] = Color.white;
}
}
public void Draw(int x, int y) {
pixels[(WIDTH * y) + x] = Color.black;
}
public Color[] GetPixels() {
return pixels;
}
}