本文整理汇总了C++中sin_lookup函数的典型用法代码示例。如果您正苦于以下问题:C++ sin_lookup函数的具体用法?C++ sin_lookup怎么用?C++ sin_lookup使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sin_lookup函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: second_display_layer_update_callback
void second_display_layer_update_callback(Layer *me, GContext* ctx) {
(void) me;
time_t now = time(NULL);
struct tm *t = localtime(&now);
int32_t second_angle = t->tm_sec * (0xffff / 60);
int second_hand_length = 70;
GPoint center = grect_center_point(&GRECT_FULL_WINDOW);
GPoint second = GPoint(center.x, center.y - second_hand_length);
if (init_anim < ANIM_SECONDS) {
second = GPoint(center.x, center.y - 70);
} else if (init_anim == ANIM_SECONDS) {
second_angle_anim += 0xffff / 60;
if (second_angle_anim >= second_angle) {
init_anim = ANIM_DONE;
second =
GPoint(center.x + second_hand_length * sin_lookup(second_angle)/0xffff,
center.y + (-second_hand_length) * cos_lookup(second_angle)/0xffff);
} else {
second =
GPoint(center.x + second_hand_length * sin_lookup(second_angle_anim)/0xffff,
center.y + (-second_hand_length) * cos_lookup(second_angle_anim)/0xffff);
}
} else {
second =
GPoint(center.x + second_hand_length * sin_lookup(second_angle)/0xffff,
center.y + (-second_hand_length) * cos_lookup(second_angle)/0xffff);
}
graphics_context_set_stroke_color(ctx, GColorWhite);
graphics_draw_line(ctx, center, second);
}
示例2: second_display_layer_update_callback
void second_display_layer_update_callback(Layer *me, GContext* ctx) {
(void)me;
PblTm t;
get_time(&t);
int32_t second_angle = t.tm_sec * (0xffff/60);
int32_t counter_second_angle = t.tm_sec * (0xffff/60);
if(t.tm_sec<30)
{
counter_second_angle += 0xffff/2;
}
else
{
counter_second_angle -= 0xffff/2;
}
int second_hand_length = 60;
int counter_second_hand_length = 15;
graphics_context_set_fill_color(ctx, GColorWhite);
GPoint center = grect_center_point(&me->frame);
GPoint counter_second = GPoint(center.x + counter_second_hand_length * sin_lookup(counter_second_angle)/0xffff,
center.y + (-counter_second_hand_length) * cos_lookup(counter_second_angle)/0xffff);
GPoint second = GPoint(center.x + second_hand_length * sin_lookup(second_angle)/0xffff,
center.y + (-second_hand_length) * cos_lookup(second_angle)/0xffff);
graphics_draw_line(ctx, counter_second, second);
}
示例3: update_scale
static void update_scale(Layer *layer, GContext *context) {
GRect bounds = layer_get_bounds(layer);
GPoint center = GPoint(bounds.size.w / 2, bounds.size.h / 2);
graphics_context_set_stroke_color(context, GColorWhite);
GPoint start;
GPoint end;
for( int i = 0; i < 12; ++i) {
int32_t current_angle = TRIG_MAX_ANGLE * i / 12;
// create an oval shape indicator start point
start.x = (sin_lookup(current_angle) * 65 / TRIG_MAX_RATIO) + center.x;
start.y = (-cos_lookup(current_angle) * 75 / TRIG_MAX_RATIO) + center.y;
end.x = (sin_lookup(current_angle) * 100 / TRIG_MAX_RATIO) + center.x;
end.y = (-cos_lookup(current_angle) * 100 / TRIG_MAX_RATIO) + center.y;
if (i % 3 == 0) {
// reached a quarter, draw bigger indicator
graphics_context_set_stroke_width(context, 6);
} else {
graphics_context_set_stroke_width(context, 3);
}
graphics_draw_line(context, start, end);
}
}
示例4: update_time
static void update_time() {
// Get a tm structure
time_t temp = time(NULL);
struct tm *t = localtime(&temp);
srand((unsigned) time(&temp));
static PropertyAnimation *s_min_animation, *s_hour_animation, *s_ufo_animation;
static GRect min_from_frame, min_to_frame, hour_to_frame, hour_from_frame, ufo_to_frame, ufo_from_frame;
static int x1ufo, x2ufo, y1ufo, y2ufo;
int min_distance = 64;
int hour_distance = 40;
int32_t min_angle = TRIG_MAX_ANGLE * t->tm_min/60;
int32_t hour_angle = (TRIG_MAX_ANGLE * (((t->tm_hour % 12) * 6) + (t->tm_min / 10))) / (12 * 6);
xmin = (int16_t)(sin_lookup(min_angle) * min_distance / TRIG_MAX_RATIO) + 72 - 16;
ymin = (int16_t)(-cos_lookup(min_angle) * min_distance / TRIG_MAX_RATIO) + 86 - 16;
xhour = (int16_t)(sin_lookup(hour_angle) * hour_distance / TRIG_MAX_RATIO) + 72 - 14;
yhour = (int16_t)(-cos_lookup(hour_angle) * hour_distance / TRIG_MAX_RATIO) + 86 - 14;
min_from_frame = GRect(oldxmin, oldymin, 32, 32);
min_to_frame = GRect(xmin, ymin, 32, 32);
hour_from_frame = GRect(oldxhour, oldyhour, 28,28);
hour_to_frame = GRect(xhour, yhour, 28,28);
s_min_animation = property_animation_create_layer_frame((Layer *)s_min_layer, &min_from_frame, &min_to_frame);
animation_set_duration((Animation *)s_min_animation,1000);
s_hour_animation = property_animation_create_layer_frame((Layer *)s_hour_layer, &hour_from_frame, &hour_to_frame);
animation_set_duration((Animation *)s_hour_animation,1000);
animation_set_handlers((Animation*) s_min_animation, (AnimationHandlers) {
.stopped = (AnimationStoppedHandler) animation_sunmoon_stopped,
}, NULL);
示例5: hands_update_proc
static void hands_update_proc(Layer *layer, GContext *ctx) {
GRect bounds = layer_get_bounds(layer);
GPoint center = grect_center_point(&bounds);
const int16_t hourHandLength = bounds.size.w / 2 +20;
const int16_t minuteHandLength = hourHandLength - 30;
GPoint minuteHand;
center.y +=20;
time_t now = time(NULL);
struct tm *t = localtime(&now);
for (int i=0;i<12;i++)
{
int16_t minute_angle = TRIG_MAX_ANGLE * (((59-t->tm_min)+i*5)%60) / 60;
minuteHand.y = (int16_t)(-cos_lookup(minute_angle) * (int32_t)minuteHandLength / TRIG_MAX_RATIO) + center.y;
minuteHand.x = (int16_t)(sin_lookup(minute_angle) * (int32_t)minuteHandLength / TRIG_MAX_RATIO) + center.x;
GRect frame = layer_get_frame(text_layer_get_layer(num_layer[i]));
frame.origin.x = minuteHand.x-frame.size.w/2;
frame.origin.y = minuteHand.y-frame.size.h/2;
layer_set_frame(text_layer_get_layer(num_layer[i]),frame);
layer_set_hidden(text_layer_get_layer(num_layer[i]),false);
int16_t hour_angle = (TRIG_MAX_ANGLE * (((24-t->tm_hour+i) % 12) * 6) +
((TRIG_MAX_ANGLE * (60-t->tm_min)) / 10)) / (12 * 6);
minuteHand.y = (int16_t)(-cos_lookup(hour_angle) * (int32_t)hourHandLength / TRIG_MAX_RATIO) + center.y;
minuteHand.x = (int16_t)(sin_lookup(hour_angle) * (int32_t)hourHandLength / TRIG_MAX_RATIO) + center.x;
frame = layer_get_frame(text_layer_get_layer(hour_layer[i]));
frame.origin.x = minuteHand.x-frame.size.w/2;
frame.origin.y = minuteHand.y-frame.size.h/2;
layer_set_frame(text_layer_get_layer(hour_layer[i]),frame);
layer_set_hidden(text_layer_get_layer(hour_layer[i]),false);
}
// draw minute line
if(getDrawline())
{
if(getInvert())
graphics_context_set_stroke_color(ctx,GColorWhite);
else
graphics_context_set_stroke_color(ctx,GColorBlack);
graphics_draw_line(ctx,GPoint(144/2,0),GPoint(144/2,167));
}
// draw background
transbitmap_draw_in_rect(background_bitmap, ctx, bounds);
// draw date
if(draw_date)
{
graphics_context_set_fill_color(ctx,GColorBlack);
graphics_fill_circle(ctx,GPoint(120,120),16);
layer_set_hidden(text_layer_get_layer(date_layer),false);
}
else
layer_set_hidden(text_layer_get_layer(date_layer),true);
}
示例6: rotate
void rotate(uint16_t ang,GPoint *p)
{
ang-=0x4000;
int16_t ox=p->x;
int16_t oy=p->y;
p->x=(sin_lookup(ang)*ox/TRIG_MAX_RATIO)+(cos_lookup(ang)*oy/TRIG_MAX_RATIO);
p->y=(-cos_lookup(ang)*ox/TRIG_MAX_RATIO)+(sin_lookup(ang)*oy/TRIG_MAX_RATIO);
}
示例7: update_main_proc
static void update_main_proc(Layer *layer, GContext *ctx) {
GRect bounds = layer_get_bounds(s_main_layer);
graphics_context_set_fill_color(ctx, GColorBlack);
graphics_fill_rect(ctx, bounds, 0, GCornerNone);
if(s_is_running) {
show_round_meter(ctx, &bounds);
}
graphics_context_set_antialiased(ctx, ANTIALIASING);
Time mode_time;
srand(time(NULL));
time_t t = time(NULL);
struct tm *time_now = localtime(&t);
mode_time.hours = time_now->tm_hour;
mode_time.minutes = time_now->tm_min;
// Adjust for minutes through the hour
float minute_angle = TRIG_MAX_ANGLE * mode_time.minutes / 60;
float hour_angle = TRIG_MAX_ANGLE * mode_time.hours / 12;
hour_angle += (minute_angle / TRIG_MAX_ANGLE) * (TRIG_MAX_ANGLE / 12);
// Plot hands
GPoint minute_hand = (GPoint) {
.x = (int16_t)(sin_lookup(TRIG_MAX_ANGLE * mode_time.minutes / 60 ) * (int32_t)(HAND_RADIUS - HAND_MARGIN) / TRIG_MAX_RATIO) + s_center.x,
.y = (int16_t)(-cos_lookup(TRIG_MAX_ANGLE * mode_time.minutes / 60) * (int32_t)(HAND_RADIUS - HAND_MARGIN) / TRIG_MAX_RATIO) + s_center.y,
};
GPoint hour_hand = (GPoint) {
.x = (int16_t)(sin_lookup(hour_angle) * (int32_t)(HAND_RADIUS - (2 * HAND_MARGIN)) / TRIG_MAX_RATIO) + s_center.x,
.y = (int16_t)(-cos_lookup(hour_angle) * (int32_t)(HAND_RADIUS - (2 * HAND_MARGIN)) / TRIG_MAX_RATIO) + s_center.y,
};
graphics_context_set_stroke_color(ctx, GColorWhite);
graphics_context_set_stroke_width(ctx, 4);
// Draw hands with positive length only
if(HAND_RADIUS > 2 * HAND_MARGIN) {
graphics_draw_line(ctx, s_center, hour_hand);
}
if(HAND_RADIUS > HAND_MARGIN) {
graphics_draw_line(ctx, s_center, minute_hand);
}
// center dot
graphics_context_set_fill_color(ctx, GColorWhite);
graphics_fill_circle(ctx, s_center, 7);
}
static void main_select_click_handler(ClickRecognizerRef recognizer, void *context) {
window_stack_push(s_menu_window, false);
}
static void main_click_config_provider(void *context) {
window_single_click_subscribe(BUTTON_ID_SELECT, main_select_click_handler);
}
示例8: batteryLineArc
void batteryLineArc(GContext *ctx, float start_angle, float end_angle, GPoint centre, int radius, int thickness){
float minus_bit = radius - thickness/2 + 0.5;// + (user_battery_colour <= 1 ? 0.5 : 0); //add 0.5 for the int casting, later !!! dark colours like 1.0, light better with 0.5
float add_bit = (radius + thickness/2 + 0.5);
graphics_context_set_stroke_width(ctx, 1);
if (start_angle == 0) {
start_angle = 2.5; // for some reason, 0 seems to start too far to the left....at least for my purposes
}
for (float i = start_angle; i <= end_angle; i+=0.5) {
GPoint inside_point = (GPoint) {
.x = (int16_t)(sin_lookup(i * TRIG_MAX_ANGLE / 360) * minus_bit / TRIG_MAX_RATIO) + centre.x,
.y = (int16_t)(-cos_lookup(i * TRIG_MAX_ANGLE / 360) * minus_bit / TRIG_MAX_RATIO) + centre.y,
};
GPoint outside_point = (GPoint) {
.x = (int16_t)(sin_lookup(i * TRIG_MAX_ANGLE / 360) * add_bit / TRIG_MAX_RATIO) + centre.x,
.y = (int16_t)(-cos_lookup(i * TRIG_MAX_ANGLE / 360) * add_bit / TRIG_MAX_RATIO) + centre.y,
};
graphics_draw_line(ctx, inside_point, outside_point);
}
}
/*************************** AnimationImplementation **************************/
static void animation_started(Animation *anim, void *context) {
s_animating = true;
}
static void animation_stopped(Animation *anim, bool stopped, void *context) {
s_animating = false;
}
static void animate(int duration, int delay, AnimationImplementation *implementation, bool handlers) {
Animation *anim = animation_create();
animation_set_duration(anim, duration);
animation_set_delay(anim, delay);
animation_set_curve(anim, AnimationCurveEaseInOut);
animation_set_implementation(anim, implementation);
if(handlers) {
animation_set_handlers(anim, (AnimationHandlers) {
.started = animation_started,
.stopped = animation_stopped
}, NULL);
}
animation_schedule(anim);
}
示例9: Graphics_RenderCircle
void Graphics_RenderCircle(u16 CentreX, u16 CentreY, u16 Radius, u16 colour, TFT *TftPtr){
double x, y, old_x, old_y;
int i = 0;
x = (Radius*(cos_lookup(i))) + CentreX;
y = (Radius*(sin_lookup(i))) + CentreY;
for(i = SIN_DIV; i<=360; i = i+SIN_DIV){
old_x = x;
old_y = y;
x = (Radius*(cos_lookup(i))) + CentreX;
y = (Radius*(sin_lookup(i))) + CentreY;
render_line(old_x, old_y, x, y, colour, TftPtr);
}
}
示例10: anim_update
static void anim_update(Animation *animation, const AnimationProgress progress) {
int max_angle = TRIG_MAX_ANGLE / 8;
int angle_left = TRIG_MAX_ANGLE / 4 + (max_angle * progress) / ANIMATION_NORMALIZED_MAX;
int angle_right = TRIG_MAX_ANGLE / 4 - (max_angle * progress) / ANIMATION_NORMALIZED_MAX;
int length_left = (left_length * progress) / ANIMATION_NORMALIZED_MAX;
int length_right = (right_length * progress) / ANIMATION_NORMALIZED_MAX;
left_end = GPoint(left_start.x + (cos_lookup(angle_left) * length_left) / TRIG_MAX_RATIO,
left_start.y - (sin_lookup(angle_left) * length_left) / TRIG_MAX_RATIO);
right_end = GPoint(right_start.x + (cos_lookup(angle_right) * length_right) / TRIG_MAX_RATIO,
right_start.y - (sin_lookup(angle_right) * length_right) / TRIG_MAX_RATIO);
layer_mark_dirty(graphics_layer);
}
示例11: draw_compass_face
void draw_compass_face(void) {
int32_t starx = 0;
int32_t stary = 0;
if (orientToHeading) {
starx = center.x;
stary = center.y-63;
} else if (heading>=0) {
starx = center.x + 63 * sin_lookup(TRIG_MAX_ANGLE * heading / 360 + orientation)/TRIG_MAX_RATIO;
stary = center.y - 63 * cos_lookup(TRIG_MAX_ANGLE * heading / 360 + orientation)/TRIG_MAX_RATIO;
}
layer_set_frame((Layer *) star_layer, GRect(starx - 14, stary - 18, 28, 28));
int32_t nx = center.x + 63 * sin_lookup(orientation)/TRIG_MAX_RATIO;
int32_t ny = center.y - 63 * cos_lookup(orientation)/TRIG_MAX_RATIO;
#ifndef PBL_COLOR
if (orientToHeading && (abs(nx-starx)<10) && (abs(ny-stary)<10))
text_layer_set_text(n_layer, "");
else
#endif
text_layer_set_text(n_layer, "N");
layer_set_frame((Layer *) n_layer, GRect(nx - 14, ny - 18, 28, 28));
int32_t ex = center.x + 63 * sin_lookup(orientation + TRIG_MAX_ANGLE/4)/TRIG_MAX_RATIO;
int32_t ey = center.y - 63 * cos_lookup(orientation + TRIG_MAX_ANGLE/4)/TRIG_MAX_RATIO;
#ifndef PBL_COLOR
if (orientToHeading && (abs(ex-starx)<10) && (abs(ey-stary)<10))
text_layer_set_text(e_layer, "");
else
#endif
text_layer_set_text(e_layer, "E");
layer_set_frame((Layer *) e_layer, GRect(ex - 14, ey - 18, 28, 28));
int32_t sx = center.x + 63 * sin_lookup(orientation + TRIG_MAX_ANGLE/2)/TRIG_MAX_RATIO;
int32_t sy = center.y - 63 * cos_lookup(orientation + TRIG_MAX_ANGLE/2)/TRIG_MAX_RATIO;
#ifndef PBL_COLOR
if (orientToHeading && (abs(sx-starx)<10) && (abs(sy-stary)<10))
text_layer_set_text(s_layer, "");
else
#endif
text_layer_set_text(s_layer, "S");
layer_set_frame((Layer *) s_layer, GRect(sx - 14, sy - 18, 28, 28));
int32_t wx = center.x + 63 * sin_lookup(orientation + TRIG_MAX_ANGLE*3/4)/TRIG_MAX_RATIO;
int32_t wy = center.y - 63 * cos_lookup(orientation + TRIG_MAX_ANGLE*3/4)/TRIG_MAX_RATIO;
#ifndef PBL_COLOR
if (orientToHeading && (abs(wx-starx)<10) && (abs(wy-stary)<10))
text_layer_set_text(w_layer, "");
else
#endif
text_layer_set_text(w_layer, "W");
layer_set_frame((Layer *) w_layer, GRect(wx - 14, wy - 18, 28, 28));
layer_mark_dirty(head_layer);
}
示例12: set_hand_angle
void set_hand_angle(RotBmpPairContainer *hand_image_container, unsigned int hand_angle, GPoint offset) {
signed short x_fudge = 0;
signed short y_fudge = 0;
unsigned int pebble_angle = TRIG_MAX_ANGLE * hand_angle / 360;
x_fudge += offset.x * cos_lookup(pebble_angle) / TRIG_MAX_RATIO - offset.y * sin_lookup(pebble_angle) / TRIG_MAX_RATIO;
y_fudge += offset.x * sin_lookup(pebble_angle) / TRIG_MAX_RATIO + offset.y * cos_lookup(pebble_angle) / TRIG_MAX_RATIO;
// (144 = screen width, 168 = screen height)
hand_image_container->layer.layer.frame.origin.x = (144/2) - (hand_image_container->layer.layer.frame.size.w/2) + x_fudge;
hand_image_container->layer.layer.frame.origin.y = (168/2) - (hand_image_container->layer.layer.frame.size.h/2) + y_fudge;
layer_mark_dirty(&hand_image_container->layer.layer);
}
示例13: set_hand_text
void set_hand_text(TextLayer *text_layer, unsigned int hand_angle, char *text, GPoint offset, GSize size) {
signed short x_fudge = (144/2);
signed short y_fudge = (168/2);
unsigned int pebble_angle = TRIG_MAX_ANGLE * hand_angle / 360;
x_fudge += offset.x * cos_lookup(pebble_angle) / TRIG_MAX_RATIO - offset.y * sin_lookup(pebble_angle) / TRIG_MAX_RATIO;
y_fudge += offset.x * sin_lookup(pebble_angle) / TRIG_MAX_RATIO + offset.y * cos_lookup(pebble_angle) / TRIG_MAX_RATIO;
x_fudge -= size.w / 2;
y_fudge -= size.h / 2;
layer_set_frame(&text_layer->layer, GRect(x_fudge, y_fudge, size.w, size.h));
text_layer_set_text(text_layer, text);
}
示例14: startup_animation_init
void startup_animation_init() {
update_angles();
hour_delta = GPoint(
DOTS_RADIUS * sin_lookup(hour_angle) / ONE,
-DOTS_RADIUS * cos_lookup(hour_angle) / ONE);
gpath_move_to(hour_path, GPoint(CENTER_X + hour_delta.x, CENTER_Y + hour_delta.y));
min_delta = GPoint(
DOTS_RADIUS * sin_lookup(min_angle) / ONE,
-DOTS_RADIUS * cos_lookup(min_angle) / ONE);
gpath_move_to(min_path, GPoint(CENTER_X + min_delta.x, CENTER_Y + min_delta.y));
sec_delta = GPoint(
DOTS_RADIUS * sin_lookup(sec_angle) / ONE,
-DOTS_RADIUS * cos_lookup(sec_angle) / ONE);
gpath_move_to(sec_path, GPoint(CENTER_X + sec_delta.x, CENTER_Y + sec_delta.y));
}
示例15: hands_update_proc
static void hands_update_proc(Layer* me, GContext* ctx) {
const GPoint center = grect_center_point(&me->bounds);
const int16_t secondHandLength = me->bounds.size.w / 2;
GPoint secondHand;
PblTm t;
get_time(&t);
int32_t second_angle = TRIG_MAX_ANGLE * t.tm_sec / 60;
secondHand.y = (int16_t)(-cos_lookup(second_angle) * (int32_t)secondHandLength / TRIG_MAX_RATIO) + center.y;
secondHand.x = (int16_t)(sin_lookup(second_angle) * (int32_t)secondHandLength / TRIG_MAX_RATIO) + center.x;
// second hand
graphics_context_set_stroke_color(ctx, GColorWhite);
graphics_draw_line(ctx, secondHand, center);
// minute/hour hand
graphics_context_set_fill_color(ctx, GColorWhite);
graphics_context_set_stroke_color(ctx, GColorBlack);
gpath_rotate_to(&s_data.minute_arrow, TRIG_MAX_ANGLE * t.tm_min / 60);
gpath_draw_filled(ctx, &s_data.minute_arrow);
gpath_draw_outline(ctx, &s_data.minute_arrow);
gpath_rotate_to(&s_data.hour_arrow, (TRIG_MAX_ANGLE * (((t.tm_hour % 12) * 6) + (t.tm_min / 10))) / (12 * 6));
gpath_draw_filled(ctx, &s_data.hour_arrow);
gpath_draw_outline(ctx, &s_data.hour_arrow);
// dot in the middle
graphics_context_set_fill_color(ctx, GColorBlack);
graphics_fill_rect(ctx, GRect(me->bounds.size.w / 2-1, me->bounds.size.h / 2-1, 3, 3), 0, GCornerNone);
}