rplace

package module
v0.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 4, 2022 License: MIT Imports: 17 Imported by: 1

README

rplace is a Go client for the r/place canvas and updates.

Its purpose is to be able to more simply diff the state of the canvas with some desired state as given by an image and x,y location.

var cli rplace.Client
updates, err := cli.Subscribe(context.Background())
if err != nil {
	log.Fatal(err)
}

for upds := range updates {
	for _, upd := range upds {
		fmt.Println(upd.Link(), " => " upd.Color.Name)	
	}
}

For a more practical example, see the cmd/rplace package.

TODO

  • Add multiple desired image states tracking with the same update feed.
  • Don't check alpha 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	StdPalette = color.Palette{}
)

Functions

func GetAnonymousToken

func GetAnonymousToken(ctx context.Context) (oauth2.Token, error)

GetAnonymousToken returns the web accessToken that is written to the r/place reddit page in javascript <script> tags by default.

func GetPalette added in v0.2.0

func GetPalette(r io.Reader) (map[string]CanvasColor, error)

GetPalette searches for the colors given an html page.

Types

type CanvasColor added in v0.2.0

type CanvasColor struct {
	color.Color
	Name string
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

A Client exists to help read and understand changes to the canvas as they happen, and determine changes necessary to bring specific desired states (images) to the canvas.

func (*Client) GetDiff added in v0.6.0

func (c *Client) GetDiff(ctx context.Context, img image.Image, at image.Point) ([]Update, error)

GetDiff returns a slice of changes that must be made for the Client's current canvas to become the given image, overlayed at the given point.

func (*Client) Init added in v0.4.0

func (c *Client) Init(ctx context.Context) error

func (*Client) NeededUpdatesFor

func (c *Client) NeededUpdatesFor(ctx context.Context, img image.Image, at image.Point) (chan Update, error)

NeededUpdatesFor takes an image.Image and a location on r/place to place it, and returns a channel of updates needed to create and maintain the image at that location. It is subscribed to further canvas updates and will continue to return necessary changes until the context is closed.

func (*Client) Subscribe

func (c *Client) Subscribe(ctx context.Context) (chan []Update, error)

Subscribe returns a channel of pixel updates from the r/place canvas. This does not include the initial canvas downloads.

func (*Client) WithImage added in v0.3.0

func (c *Client) WithImage(img image.Image, at image.Point) (image.Image, error)

WithImage returns a copy of the canvas with a preview image overlayed.

type Update

type Update struct {
	image.Point
	Color CanvasColor
}

An Update is a desired change that must be made to a canvas.

func (u Update) Link() string

Link encodes the browser link that would take you to the correct location on r/place's canvas.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL