Giter Site home page Giter Site logo

tinygo-org / tinydraw Goto Github PK

View Code? Open in Web Editor NEW
42.0 7.0 11.0 1.63 MB

TinyDraw is a package of drawing primitives on TinyGo displays.

Home Page: https://tinygo.org

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

Go 95.62% Makefile 4.38%
tinygo golang microcontroller arduino arm microbit nrf51 nrf52 nrf52840 samd21

tinydraw's People

Contributors

conejoninja avatar deadprogram avatar sago35 avatar spearson78 avatar toffentoffen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

tinydraw's Issues

FilledRectangle: w and h are inclusive

It is confusing that the following code:

tinydraw.FilledRectangle(machine.Display, 20, 20, 0, 0, color)

fills in one pixel at 20, 20, and that

tinydraw.FilledRectangle(machine.Display, 20, 20, 1, 1, color)

fills in 4 pixels.

Typically, I expect the "width" and "height" that I pass into a rectangle function to be number of pixels horizontally and vertically, rather than the offset of the last inclusive point for drawing.

FilledTriangle divide by zero

While investigating #9 I ran into several divide by zero issues.
I checked the original Adafruit code and found an error in the translation the y variable is reset to last when it should be last+1 from the previous loop.

I created a pull request with the fix. Unfortunately this still doesn't fix #9 but malformed triangles are better than a panic

Suggest change to package name and API

I'd like to propose 2 changes to this package.

The first is to rename it tinydraw.

The second is to change the API to remove the word Draw from all of the functions.

For example:

tinydraw.Line(&display, 100, 100, 40, 50, yellow)
tinydraw.Rectangle(&display, 30, 120, 20, 20, black)
tinydraw.FilledRectangle(&display, 34, 124, 12, 12, yellow)

FilledTriangle stretches too far horizontally

I was using a FilledTriangle to draw the hands on a clock, and I noticed that the triangle for the minute hand goes outside the boundaries of the clock near the 3 o'clock and 9 o'clock positions.

Assuming there is nothing wrong with math.Sincos(), I can only assume that something is not quite right with FilledTriangle().

My logic looks something like this:

	const (
		hourRadius       = 55
		minuteRadius     = 95
		hourWidth        = 6
		minuteWidth      = 5
	)

	// Draw the clock hands.
	minuteAngle := float64(t.Minute()) / 60 * 2 * math.Pi
	mx, my := math.Sincos(minuteAngle)
	hourAngle := float64(t.Hour()*60+t.Minute()) / 60 / 12 * 2 * math.Pi
	hx, hy := math.Sincos(hourAngle)
	tinydraw.Triangle(
		display,
		x-int16(hourWidth*hy), y-int16(hourWidth*hx),
		x+int16(hourWidth*hy), y+int16(hourWidth*hx),
		x+int16(hourRadius*hx), y-int16(hourRadius*hy),
		black)
	tinydraw.FilledTriangle(
		display,
		x-int16(minuteWidth*my), y-int16(minuteWidth*mx),
		x+int16(minuteWidth*my), y+int16(minuteWidth*mx),
		x+int16(minuteRadius*mx), y-int16(minuteRadius*my),
		black)

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.