Documentation ¶
Overview ¶
The cell package manages the state for the Conway's Game of Life cellular automaton.
Package cell is a generated protocol buffer package.
It is generated from these files:
field.proto
It has these top-level messages:
FieldProto
Package cell is a generated protocol buffer package.
It is generated from these files:
input.proto
It has these top-level messages:
UpdateRequest UpdateResponse UpdateMaskRequest ResetFieldRequest
Index ¶
- func Run(c *Field, tick <-chan time.Time, update <-chan *UpdateRequest) <-chan *Field
- func ToImage(f *Field) *image.NRGBA
- type Field
- type FieldProto
- type ResetFieldRequest
- type UpdateMaskRequest
- type UpdateRequest
- func (m *UpdateRequest) GetInput() isUpdateRequest_Input
- func (m *UpdateRequest) GetResetField() *ResetFieldRequest
- func (m *UpdateRequest) GetUpdateMask() *UpdateMaskRequest
- func (*UpdateRequest) ProtoMessage()
- func (m *UpdateRequest) Reset()
- func (m *UpdateRequest) String() string
- func (*UpdateRequest) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, ...)
- type UpdateRequest_ResetField
- type UpdateRequest_UpdateMask
- type UpdateResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Field ¶
type Field struct { // State holds the state information. The state for the cell at (x, y) // is stored at State[Width * y + x]. State []uint32 // Width is one dimension of the 2D state. The state is of size Width // times Height. Width int // Height is one dimension of the 2D state. The state is of size Width // times Height. Height int }
Field represents the entire state of a 2D cellular automaton.
func FromProto ¶
func FromProto(f *FieldProto) (*Field, error)
FromProto converts a FieldProto into the Field struct.
Since FieldProtos can come from untrusted sources this method returns an error instead of panicing when encountering invalid Field data.
func NewField ¶
NewField creates an empty 2D cellular automaton state with the given (w, h) dimensions.
func RandomField ¶
RandomField creates a random 2D cellular automaton state with the given dimensions (w, h).
It uses the lower 24 bits of state to make it easy to visualize using with an image (8 bits for each red, green, and blue).
type FieldProto ¶
type FieldProto struct { // State holds the state information. The state for the cell at (x, y) // is stored at State[Width * y + x]. State []uint32 `protobuf:"varint,1,rep,name=state" json:"state,omitempty"` // Width is one dimension of the 2D state. The state is of size Width // times Height. Width int32 `protobuf:"varint,2,opt,name=width" json:"width,omitempty"` // Height is one dimension of the 2D state. The state is of size Width // times Height. Height int32 `protobuf:"varint,3,opt,name=height" json:"height,omitempty"` // Seq is the sequence number indicating the current iteration number. Seq int32 `protobuf:"varint,4,opt,name=seq" json:"seq,omitempty"` }
FieldProto represents the entire state of a 2D cellular automaton.
func (*FieldProto) ProtoMessage ¶
func (*FieldProto) ProtoMessage()
func (*FieldProto) Reset ¶
func (m *FieldProto) Reset()
func (*FieldProto) String ¶
func (m *FieldProto) String() string
type ResetFieldRequest ¶
type ResetFieldRequest struct { }
ResetFieldRequest modifies the field to be a random state.
func (*ResetFieldRequest) ProtoMessage ¶
func (*ResetFieldRequest) ProtoMessage()
func (*ResetFieldRequest) Reset ¶
func (m *ResetFieldRequest) Reset()
func (*ResetFieldRequest) String ¶
func (m *ResetFieldRequest) String() string
type UpdateMaskRequest ¶
type UpdateMaskRequest struct {
Value uint32 `protobuf:"varint,1,opt,name=value" json:"value,omitempty"`
}
UpdateMaskRequest modifies the mask used in the Game of Life calculation.
The default mask is used to filter the calculations to use every three bits for the game of life.
func (*UpdateMaskRequest) ProtoMessage ¶
func (*UpdateMaskRequest) ProtoMessage()
func (*UpdateMaskRequest) Reset ¶
func (m *UpdateMaskRequest) Reset()
func (*UpdateMaskRequest) String ¶
func (m *UpdateMaskRequest) String() string
type UpdateRequest ¶
type UpdateRequest struct { // Types that are valid to be assigned to Input: // *UpdateRequest_UpdateMask // *UpdateRequest_ResetField Input isUpdateRequest_Input `protobuf_oneof:"input"` }
UpdateRequest is used to to modify a running Game of Life simulation.
func (*UpdateRequest) GetInput ¶
func (m *UpdateRequest) GetInput() isUpdateRequest_Input
func (*UpdateRequest) GetResetField ¶
func (m *UpdateRequest) GetResetField() *ResetFieldRequest
func (*UpdateRequest) GetUpdateMask ¶
func (m *UpdateRequest) GetUpdateMask() *UpdateMaskRequest
func (*UpdateRequest) ProtoMessage ¶
func (*UpdateRequest) ProtoMessage()
func (*UpdateRequest) Reset ¶
func (m *UpdateRequest) Reset()
func (*UpdateRequest) String ¶
func (m *UpdateRequest) String() string
type UpdateRequest_ResetField ¶
type UpdateRequest_ResetField struct {
ResetField *ResetFieldRequest `protobuf:"bytes,2,opt,name=reset_field,oneof"`
}
type UpdateRequest_UpdateMask ¶
type UpdateRequest_UpdateMask struct {
UpdateMask *UpdateMaskRequest `protobuf:"bytes,1,opt,name=update_mask,oneof"`
}
type UpdateResponse ¶
type UpdateResponse struct { }
UpdateResponse is the response to an UpdateRequest.
It is blank for now, but exists in case we need to add response information in the future.
func (*UpdateResponse) ProtoMessage ¶
func (*UpdateResponse) ProtoMessage()
func (*UpdateResponse) Reset ¶
func (m *UpdateResponse) Reset()
func (*UpdateResponse) String ¶
func (m *UpdateResponse) String() string