static void modeset_render(Modeset *m, grdev_display *d) { const grdev_display_target *t; m->r = next_color(&m->r_up, m->r, 4); m->g = next_color(&m->g_up, m->g, 3); m->b = next_color(&m->b_up, m->b, 2); GRDEV_DISPLAY_FOREACH_TARGET(d, t) { modeset_draw(m, t); grdev_display_flip_target(d, t); }
// color `node' using the color `to_assign' // and try color all its adjacent nodes bool ConstraintGraph::recur_color(const GNode &node,COLOR to_assign){ assert( to_assign != G ); // color will not be G!! COLOR cur_color = get_color(node); // this node has been colored to H or L if( cur_color == to_assign ) return true; // this node has colored to different color, fail! else if( cur_color != G ) return false; // it is G, color it, and all its neighbours set_color(node,to_assign); COLOR opposite_color = next_color(to_assign); int idx = get_node_idx(node); vector<GEdge> & elist = edge[idx]; for(int i = 0; i < row+col; i++) { GEdge & e = elist[i]; if( i!=idx && e.count > 0){ bool result; if( e.type == DIFF ) result = recur_color(e.v,opposite_color); else result = recur_color(e.v,to_assign); if( result == false ) return false; } } // safely colored all neighbour return true; }
static void switch_color() { switch(color) { case COLOR_RED: GPIO_WriteBit(GPIOA, GPIO_Pin_3, led_state ? Bit_SET : Bit_RESET); next_color(COLOR_GREEN); break; case COLOR_GREEN: GPIO_WriteBit(GPIOA, GPIO_Pin_1, led_state ? Bit_SET : Bit_RESET); next_color(COLOR_BLUE); break; case COLOR_BLUE: GPIO_WriteBit(GPIOA, GPIO_Pin_2, led_state ? Bit_SET : Bit_RESET); next_color(COLOR_RED); break; } }
static void modeset_draw(int fd) { uint8_t r, g, b; bool r_up, g_up, b_up; unsigned int i, j, k, off; struct modeset_dev *iter; struct modeset_buf *buf; int ret; srand(time(NULL)); r = rand() % 0xff; g = rand() % 0xff; b = rand() % 0xff; r_up = g_up = b_up = true; for (i = 0; i < 50; ++i) { r = next_color(&r_up, r, 20); g = next_color(&g_up, g, 10); b = next_color(&b_up, b, 5); for (iter = modeset_list; iter; iter = iter->next) { buf = &iter->bufs[iter->front_buf ^ 1]; for (j = 0; j < buf->height; ++j) { for (k = 0; k < buf->width; ++k) { off = buf->stride * j + k * 4; *(uint32_t*)&buf->map[off] = (r << 16) | (g << 8) | b; } } ret = drmModeSetCrtc(fd, iter->crtc, buf->fb, 0, 0, &iter->conn, 1, &iter->mode); if (ret) fprintf(stderr, "cannot flip CRTC for connector %u (%d): %m\n", iter->conn, errno); else iter->front_buf ^= 1; } usleep(100000); } }
static void draw_stars (ALLEGRO_BITMAP *bitmap, struct star s[], struct stars_bitmap *sb, size_t count, enum vm vm) { if (anim_cycle % 4) { draw_bitmapc (sb->b, bitmap, &sb->c, 0); return; } int i = prandom (count - 1); s[i].color = next_color (s[i].color); draw_star (&s[i], sb, vm); draw_bitmapc (sb->b, bitmap, &sb->c, 0); }
static void draw_stars (ALLEGRO_BITMAP *bitmap, struct stars *stars, enum vm vm) { if (! stars->count) return; if (anim_cycle % 4 || game_paused) { draw_bitmapc (stars->b, bitmap, &stars->c, 0); return; } int i = prandom (stars->count - 1); stars->s[i].color = next_color (stars->s[i].color); draw_star (stars, i, vm); draw_bitmapc (stars->b, bitmap, &stars->c, 0); }
static void compute_stars_position (int last_room, int room) { struct pos p; p.room = room; int i, min_x = INT_MAX, min_y = INT_MAX, max_x = INT_MIN, max_y = INT_MIN; for (p.floor = FLOORS; p.floor >= -1; p.floor--) for (p.place = -1; p.place < PLACES; p.place++) { struct stars_bitmap *sb = &stars_bitmap[p.floor + 1][p.place + 1]; if (sb->b) { al_destroy_bitmap (sb->b); sb->b = NULL; } if (con (&p)->bg != BALCONY) continue; for (i = 0; i < STARS; i++) { struct star *s = &star[p.floor + 1][p.place + 1][i]; star_coord (&p, i, s); min_x = min_int (min_x, s->x); min_y = min_int (min_y, s->y); max_x = max_int (max_x, s->x); max_y = max_int (max_y, s->y); s->color = next_color (s->color); } sb->b = create_bitmap (max_x - min_x + 1, max_y - min_y + 1); clear_bitmap (sb->b, TRANSPARENT_COLOR); sb->c.room = room; sb->c.x = min_x; sb->c.y = min_y; redraw_stars_bitmap (star[p.floor + 1][p.place + 1], sb, STARS, vm); } }
void generate_stars_for_pos (struct pos *p) { struct pos np; npos (p, &np); int x, y; if (! mr_coord (np.room, -1, &x, &y)) return; struct stars *stars = &mr.cell[x][y].stars[np.floor][np.place]; destroy_bitmap (stars->b); stars->b = NULL; if (stars->s) al_free (stars->s); stars->s = NULL; stars->count = 0; if (con (&np)->bg != BALCONY) return; stars->count = 3 + prandom_pos (&np, 5); stars->s = xcalloc (stars->count, sizeof (* stars->s)); int i, min_x = INT_MAX, min_y = INT_MAX, max_x = INT_MIN, max_y = INT_MIN; for (i = 0; i < stars->count; i++) { struct star *s = &stars->s[i]; star_coord (&np, i, s); min_x = min_int (min_x, s->x); min_y = min_int (min_y, s->y); max_x = max_int (max_x, s->x); max_y = max_int (max_y, s->y); s->color = next_color (s->color); } stars->b = create_bitmap (max_x - min_x + 1, max_y - min_y + 1); clear_bitmap (stars->b, TRANSPARENT_COLOR); new_coord (&stars->c, np.l, np.room, min_x, min_y); redraw_stars_bitmap (stars, vm); }
// recursively reverse the color of a componenet, which contains `node' void ConstraintGraph::recur_reverse_color(const GNode &node, BoolVector & mark){ int idx = get_node_idx(node); // check if this node has been visited if( mark[idx] == true ) return; else mark[idx] = true; COLOR origin_color = get_color(node); COLOR new_color = next_color(origin_color); set_color(node,new_color); // reverse color all its adjacent nodes vector<GEdge> & adj_nodes = edge[idx]; for (int v_idx=0; v_idx<row+col;v_idx++) { // 1.no need to check itself // 2.only check if edge exist GEdge & e = adj_nodes[v_idx]; if( v_idx != idx && e.type != NOEDGE ){ assert( e.v != node ); recur_reverse_color(e.v,mark); } } }