Skip to content

Instantly share code, notes, and snippets.

@MaBecker
Created December 5, 2019 19:52
Show Gist options
  • Save MaBecker/f931a05fa4dfc0644942a50efbf24577 to your computer and use it in GitHub Desktop.
Save MaBecker/f931a05fa4dfc0644942a50efbf24577 to your computer and use it in GitHub Desktop.
extend line with thickness
function draw_line(x1,y1,x2,y2,thickness){
var p = [];
var angle = Math.atan2(y2-y1,x2-x1);
cosP = Math.cos(angle+Math.PI/2);
cosM = Math.cos(angle-Math.PI/2);
sinP = Math.sin(angle+Math.PI/2);
sinM = Math.sin(angle-Math.PI/2);
p[0] = (x1 + thickness*cosP +0.5)|0;
p[1] = (y1 + thickness*sinP +0.5)|0;
p[2] = (x1 + thickness*cosM +0.5)|0;
p[3] = (y1 + thickness*sinM +0.5)|0;
p[4] = (x2 + thickness*cosM +0.5)|0;
p[5] = (y2 + thickness*sinM +0.5)|0;
p[6] = (x2 + thickness*cosP +0.5)|0;
p[7] = (y2 + thickness*sinP +0.5)|0;
g.fillPoly(p,true);
}
function drawHouse(){
var thick = (g.getWidth() *0.02 +0.5)|0;
var sx = g.getWidth() * 0.25;
var sy = g.getHeight() * 0.4;
draw_line(sx,sy*2,sx*3,sy*2,thick);
g.fillCircle(sx,sy*2,thick).flip();
draw_line(sx*3,sy*2,sx*3,sy,thick);
g.fillCircle(sx*3,sy*2,thick).flip();
draw_line(sx*3,sy,sx*2,sy*0.33,thick);
g.fillCircle(sx*3,sy,thick).flip();
draw_line(sx*2,sy*0.33,sx,sy,thick);
g.fillCircle(sx*2,sy*0.33,thick).flip();
draw_line(sx,sy,sx,sy*2,thick);
g.fillCircle(sx,sy,thick).flip();
}
Bangle.setLCDMode();
g.clear();
g.setColor(1,0,0);
drawHouse();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment