Skip to content

Instantly share code, notes, and snippets.

@hyakuhei
Created March 17, 2015 08:47
Show Gist options
  • Save hyakuhei/4e0a4dfa0e5af58057cf to your computer and use it in GitHub Desktop.
Save hyakuhei/4e0a4dfa0e5af58057cf to your computer and use it in GitHub Desktop.
using Toybox.WatchUi as Ui;
using Toybox.Graphics as Gfx;
using Toybox.System as Sys;
using Toybox.Lang as Lang;
using Toybox.Time as Time;
class WaveWatch1View extends Ui.WatchFace {
//! Constants
const BAR_THICKNESS = 5;
const ARC_MAX_ITERS = 300;
//! Class vars
var fast_updates = true;
var device_settings;
function fetchData() {
var data = {
"lowTideHeight"=>1.3,
"lowTideTime"=>1130,
"highTideHeight"=>3.9,
"highTideTime"=>1641,
"windDirection"=>95,
"windSpeedKnots"=>17.4
};
return data;
}
//! Load your resources here
function onLayout(dc) {
var data = fetchData();
setLayout(Rez.Layouts.WatchFace(dc));
device_settings = Sys.getDeviceSettings();
//setLayout(Rez.Layouts.MainLayout(dc));
}
//! Restore the state of the app and prepare the view to be shown
function onShow() {
}
//! Update the view
function onUpdate(dc) {
// Get and show the current time
var clockTime = Sys.getClockTime();
var timeString = Lang.format("$1$:$2$:$3$", [clockTime.hour, clockTime.min.format("%.2d"), clockTime.sec.format("%.2d")]);
var view = View.findDrawableById("TimeLabel");
// Arc Code Adapted From: https://github.com/CodyJung/connectiq-apps/blob/master/ArcWatch
// Set Background Colour
dc.clear();
dc.setColor(Gfx.COLOR_BLACK, Gfx.COLOR_TRANSPARENT);
dc.fillRectangle(0, 0, dc.getWidth(), dc.getHeight()); //Not 100% sure I need this
var x = dc.getWidth() / 2;
var y = dc.getHeight() / 2;
// Lets draw some test arcs!
var radius = 104;
drawArc(dc, x, y, radius, (9 / 12f) * 2 * Math.PI, Gfx.COLOR_YELLOW);
}
//! Fast (but kind of bad-looking) arc drawing.
//! From http://stackoverflow.com/questions/8887686/arc-subdivision-algorithm/8889666#8889666
//! TODO: Once we have drawArc, use that instead.
function drawArc(dc, cent_x, cent_y, radius, theta, color) {
dc.setColor( color, Gfx.COLOR_WHITE);
var iters = ARC_MAX_ITERS * ( theta / ( 2 * Math.PI ) );
var dx = 0;
var dy = -radius;
var ctheta = Math.cos(theta/(iters - 1));
var stheta = Math.sin(theta/(iters - 1));
dc.fillCircle(cent_x + dx, cent_y + dy, BAR_THICKNESS);
for(var i=1; i < iters; ++i) {
var dxtemp = ctheta * dx - stheta * dy;
dy = stheta * dx + ctheta * dy;
dx = dxtemp;
dc.fillCircle(cent_x + dx, cent_y + dy, BAR_THICKNESS);
}
}
//! The user has just looked at their watch. Timers and animations may be started here.
function onExitSleep() {
}
//! Terminate any active timers and prepare for slow updates.
function onEnterSleep() {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment