tinygo-org / tinydraw Goto Github PK
View Code? Open in Web Editor NEWTinyDraw is a package of drawing primitives on TinyGo displays.
Home Page: https://tinygo.org
License: BSD 3-Clause "New" or "Revised" License
TinyDraw is a package of drawing primitives on TinyGo displays.
Home Page: https://tinygo.org
License: BSD 3-Clause "New" or "Revised" License
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.
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
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)
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)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.