Skip to content
Sign upLog in
← Back to Community

Graphics with Go

Profile icon
Lord_Poseidon

Getting started with graphics development in Golang on repl.it

Introduction

Who doesn't love golang? some people, maybe.But no can resist the cuteness of the gopher. Fact.

Cannot infer image mime type

What I want to say is... I've found a way to do graphics in Go on repl.it. This post teaches you how to make a sample gopher screensaver using a framework called pixel.

Cannot infer image mime type

Please note that much of the code is from the original tutorials. It strongly recommended to go through them if you do want to make a game in go. To be honest, this is more of a half-baked amalgamation of

@eankeen
's original pygame tutorial and the tutorials

The final result will look like this:

Cannot infer image mime type

A bit glitchy.Don't know why

Getting started

First, start by making a polygott repl here. Or even better, fork my repl at https://repl.it/@Lord_Poseidon/NarrowCrookedExternalcommand. You would see a makefile. Paste this there and make a folder called src

.PHONY: dependencies run clean deppaths := github.com/faiface/pixel github.com/faiface/pixel/pixelgl golang.org/x/image/colornames gopath := /tmp/gopath run: dependencies cd src && GOPATH=$(gopath) go build -o /tmp/main-go TERM=xterm /tmp/main-go clean: rm -rf /tmp/main-go /tmp/gopath dependencies: GOPATH=$(gopath) go get $(deppaths)

Thanks to

@superwhiskers
for this code. The reason we are doing this is because repl does not have a Go package manager yet .That makefile gets our dependencies, then runs the code in the folder src .

create a file main.go in src folder and code away!!

my code is mostly from the original tutorials here but these are the changes:

Code changes:

pos:=pixel.V(100,300) horizadder,vertadder:=1.0,1.0 for !win.Closed() { pos=pos.Add(pixel.V(horizadder,vertadder)) mat:=pixel.IM win.Clear(colornames.Black) sprite.Draw(win, mat.Moved(pos)) if pos.X < 0 || pos.X > 800{ horizadder = -horizadder } if pos.Y < 0 || pos.Y > 600{ vertadder = -vertadder } win.Update() time.Sleep(16666666) }

just standard edge detection, speed changing, movement and delay.

Path:

the tutorials assume that the source directory is the working directory. This is not the case with us. You have to do src/hiking.png even if you already are in src directory.
Also, I had to resize the original image to make it smaller

Size of the window:

the tutorials assume 1074 by 768 pixels. We at repl.it have only 800 by 600


Thanks again to

@superwhiskers
and
@eankeen
. If you do decide to make a game in go,let me know in the comments

Voters
Profile icon
programmeruser
Profile icon
Nick4422
Profile icon
quick007
Profile icon
timmy_i_chen
Profile icon
hyperupcall
Profile icon
SamWhite3
Profile icon
Lord_Poseidon
Comments
hotnewtop
Profile icon
TopperSite

The use of an e-signature is creating greater consumer confidence in online business transactions. The webpage www.signnow.com offers an advanced eSignature solution that takes contract management to a new level. Get access to useful tools that help you close deals in hours instead of days.

Profile icon
TopperSite

It was important for me to understand this. I will use this information to improve my https://illusionsalonstudio.com/good-places-to-visit-in-search-of-paper-writers-for-hire job. It will be one of the best things for me, and I am happy about that.

Profile icon
tom0099

How do i fix wireless displays connections in windows 10 http://fixwindows10connections.com thanks for the share this basic information.