Coder Social home page Coder Social logo

xyproto / pixelpusher Goto Github PK

View Code? Open in Web Editor NEW
9.0 3.0 2.0 39.69 MB

:space_invader: Plot pixels on a 320x200 256c canvas

License: BSD 3-Clause "New" or "Revised" License

Go 100.00%
rasterization gamedev graphics renderer go 256-colors pixel-art software-renderer sdl2

pixelpusher's Introduction

pixelpusher

Build GoDoc License Go Report Card

Concurrent software rendering, triangle rasterization and pixel buffer manipulation.

screencap triangles

butterflies glitch effect

software rendered duck with glitch effect software rendered beveled cube

Features and limitations

  • Can draw software-rendered triangles concurrently, using goroutines. The work of drawing the triangles is divided on the available CPU cores.
  • Provides flat-shaded triangles.
  • Everything is drawn to a []uint32 pixel buffer (containing "red", "green", "blue" and "alpha").
  • Tested together with SDL2, but can be used with any graphics library that can output pixels from a pixel buffer.
  • The software rendering of 3D graphics in the screenshot above is provided by fauxgl. The outputs from this can be combined with effects from pixelpusher.

Getting started

This program imports pixelpusher, sets up a callback function for drawing pixels to the gfx.Pixels slice, creates a pixelpusher.Config struct and then calls the .Run function. The window title is Red Pixel:

package main

import (
    pp "github.com/xyproto/pixelpusher"
)

func onDraw(canvas *pp.Canvas) error {
    // x=0, y=0, red=255, green=0, blue=0
    return pp.Plot(canvas, 0, 0, 255, 0, 0)
}

func main() {
    // The window title is "Red Pixel"
    canvas := pp.New("Red Pixel")
    // onDraw will be called whenever it is time to draw a frame
    canvas.Run(onDraw, nil, nil, nil)
}

This program allows the user to press the arrow keys or the WASD keys to move a red pixel around and draw something. Press ctrl-s to save the image and press Esc or q to quit.

package main

import (
    "errors"

    pp "github.com/xyproto/pixelpusher"
)

var x, y = 160, 100

func onDraw(canvas *pp.Canvas) error {
    return pp.Plot(canvas, x, y, 255, 0, 0)
}

func onPress(left, right, up, down, space, enter, esc bool) error {
    if up {
        y--
    } else if down {
        y++
    }
    if left {
        x--
    } else if right {
        x++
    }
    if esc {
        return errors.New("quit")
    }
    return nil
}

func main() {
    pp.New("Simple Draw").Run(onDraw, onPress, nil, nil)
}

General information

pixelpusher's People

Contributors

xyproto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

asdlei99 tilosens

pixelpusher's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.