static struct sprite_trans * trans_mul(struct sprite_trans *a, struct sprite_trans *b, struct sprite_trans *t, struct matrix *tmp_matrix) { if (b == NULL) { return a; } *t = *a; if (t->mat == NULL) { t->mat = b->mat; } else if (b->mat) { matrix_mul(tmp_matrix, t->mat, b->mat); t->mat = tmp_matrix; } if (t->color == 0xffffffff) { t->color = b->color; } else if (b->color != 0xffffffff) { t->color = color_mul(t->color, b->color); } if (t->additive == 0) { t->additive = b->additive; } else if (b->additive != 0) { t->additive = color_add(t->additive, b->additive); } if (t->program == PROGRAM_DEFAULT) { t->program = b->program; } return t; }
int ray_color(t_ray *ray, t_env *e) { double spot_dist; int color; t_list *lst; t_ray light; if (!ray->obj) return (COLOR_BACKGROUND); if (!e->scene->spot) return (ray->obj->param.color); /* Si le damier est voulue; */ //color = damier_color(ray); color = color_scale(ray->obj->param.color, ray->obj->param.ambiant); lst = e->scene->spot; while (lst) { init_light_ray(&light, ray, lst->content); ray_intersect(&light, e); spot_dist = 0; if (light.obj) spot_dist = mat_dist(&LST_CONTENT(lst, t_spot*)->position, &ray->intersection); if (!light.obj || spot_dist < light.dist) color = color_add(color, get_spot(ray, &light, lst->content)); lst = lst->next; } //if(ray->obj && ray->obj->param.type == PLANE) // color = damier_color(ray); return (color); }
static int get_spot(t_ray *ray, t_ray *light, t_spot *spot) { int color; color = get_diffuse(ray, light, spot); color = color_add(color, get_specular(ray, light, spot)); return (color); }
Image *image_add(const Image *a, const Image *b, Image *out) { int wi, hi; for (hi = 0; hi < a->height; ++hi) for (wi = 0; wi < a->width; ++wi) color_add(a->channels, sample(a,wi,hi), sample(b,wi,hi), sample(out,wi,hi)); return out; }
Color renderAntiAliasedPixel(int x, int y, Scene scene, RenderStats* r){ float x1 = (float) x / (float) scene.width; float x2 = ((float) x + 0.5) / (float) scene.width; float y1 = (float) y / (float) scene.height; float y2 = ((float) y + 0.5) / (float) scene.height; Ray ray1 = scene.camera.getRay(x1, y1); Ray ray2 = scene.camera.getRay(x1, y2); Ray ray3 = scene.camera.getRay(x2, y1); Ray ray4 = scene.camera.getRay(x2, y2); Color avg = trace(ray1, 0, scene, r); avg = color_add(avg, trace(ray2, 0, scene, r)); avg = color_add(avg, trace(ray3, 0, scene, r)); avg = color_add(avg, trace(ray4, 0, scene, r)); avg = color_scale(avg, 0.25); return avg; }
int CmdGHistoryAnnual::execute (std::string& output) { int rc = 0; std::map <time_t, int> groups; // Represents any month with data std::map <time_t, int> addedGroup; // Additions by month std::map <time_t, int> completedGroup; // Completions by month std::map <time_t, int> deletedGroup; // Deletions by month // Scan the pending tasks. handleRecurrence (); std::vector <Task> filtered; filter (filtered); context.tdb2.commit (); std::vector <Task>::iterator task; for (task = filtered.begin (); task != filtered.end (); ++task) { Date entry (task->get_date ("entry")); Date end; if (task->has ("end")) end = Date (task->get_date ("end")); time_t epoch = entry.startOfYear ().toEpoch (); groups[epoch] = 0; // Every task has an entry date. ++addedGroup[epoch]; // All deleted tasks have an end date. if (task->getStatus () == Task::deleted) { epoch = end.startOfYear ().toEpoch (); groups[epoch] = 0; ++deletedGroup[epoch]; } // All completed tasks have an end date. else if (task->getStatus () == Task::completed) { epoch = end.startOfYear ().toEpoch (); groups[epoch] = 0; ++completedGroup[epoch]; } } int widthOfBar = context.getWidth () - 5; // 5 == strlen ("YYYY ") // Now build the view. ViewText view; view.width (context.getWidth ()); view.add (Column::factory ("string", STRING_CMD_GHISTORY_YEAR)); view.add (Column::factory ("string.left_fixed", STRING_CMD_GHISTORY_NUMBER)); Color color_add (context.config.get ("color.history.add")); Color color_done (context.config.get ("color.history.done")); Color color_delete (context.config.get ("color.history.delete")); // Determine the longest line, and the longest "added" line. int maxAddedLine = 0; int maxRemovedLine = 0; std::map <time_t, int>::iterator i; for (i = groups.begin (); i != groups.end (); ++i) { if (completedGroup[i->first] + deletedGroup[i->first] > maxRemovedLine) maxRemovedLine = completedGroup[i->first] + deletedGroup[i->first]; if (addedGroup[i->first] > maxAddedLine) maxAddedLine = addedGroup[i->first]; } int maxLine = maxAddedLine + maxRemovedLine; if (maxLine > 0) { unsigned int leftOffset = (widthOfBar * maxAddedLine) / maxLine; int totalAdded = 0; int totalCompleted = 0; int totalDeleted = 0; int priorYear = 0; int row = 0; std::map <time_t, int>::iterator i; for (i = groups.begin (); i != groups.end (); ++i) { row = view.addRow (); totalAdded += addedGroup[i->first]; totalCompleted += completedGroup[i->first]; totalDeleted += deletedGroup[i->first]; Date dt (i->first); int m, d, y; dt.toMDY (m, d, y); if (y != priorYear) { view.set (row, 0, y); priorYear = y; } unsigned int addedBar = (widthOfBar * addedGroup[i->first]) / maxLine; unsigned int completedBar = (widthOfBar * completedGroup[i->first]) / maxLine; unsigned int deletedBar = (widthOfBar * deletedGroup[i->first]) / maxLine; std::string bar = ""; if (context.color ()) { std::string aBar = ""; if (addedGroup[i->first]) { aBar = format (addedGroup[i->first]); while (aBar.length () < addedBar) aBar = " " + aBar; } std::string cBar = ""; if (completedGroup[i->first]) { cBar = format (completedGroup[i->first]); while (cBar.length () < completedBar) cBar = " " + cBar; } std::string dBar = ""; if (deletedGroup[i->first]) { dBar = format (deletedGroup[i->first]); while (dBar.length () < deletedBar) dBar = " " + dBar; } bar += std::string (leftOffset - aBar.length (), ' '); bar += color_add.colorize (aBar); bar += color_done.colorize (cBar); bar += color_delete.colorize (dBar); } else { std::string aBar = ""; while (aBar.length () < addedBar) aBar += "+"; std::string cBar = ""; while (cBar.length () < completedBar) cBar += "X"; std::string dBar = ""; while (dBar.length () < deletedBar) dBar += "-"; bar += std::string (leftOffset - aBar.length (), ' '); bar += aBar + cBar + dBar; } view.set (row, 1, bar); } } std::stringstream out; if (view.rows ()) { out << optionalBlankLine () << view.render () << "\n"; if (context.color ()) out << format (STRING_CMD_HISTORY_LEGEND, color_add.colorize (STRING_CMD_HISTORY_ADDED), color_done.colorize (STRING_CMD_HISTORY_COMP), color_delete.colorize (STRING_CMD_HISTORY_DEL)) << optionalBlankLine () << "\n"; else out << STRING_CMD_HISTORY_LEGEND_A << "\n"; } else { context.footnote (STRING_FEEDBACK_NO_TASKS); rc = 1; } output = out.str (); return rc; }
int main() { /* xyz */ printf(" *** testing xyz *** \n"); xyz v = xyz_expr(1,2,3); xyz add = xyz_add(v,v); xyz vv = xyz_expr(5,5,5); xyz sub = xyz_sub(v,vv); xyz n = xyz_neg(sub); xyz sc = xyz_scale(1.5,v); xyz sc2 = xyz_scale(-3.33,n); double dt = xyz_dot(v,sc); double mag = xyz_mag(v); xyz z = xyz_expr(0,0,0); xyz zn = xyz_norm(z); xyz vn = xyz_norm(v); printf("xyz_expr(1,2,3) =>\t%s\n",xyz_tos(v)); printf("(1,2,3)+(1,2,3) =>\t%s\n",xyz_tos(add)); printf("(1,2,3)-(5,5,5) =>\t%s\n",xyz_tos(sub)); printf("-(-4,-3,-2) =>\t%s\n",xyz_tos(n)); printf("scale (1,2,3) by 1.5 =>\t%s\n",xyz_tos(sc)); printf("scale (4,3,2) by -3.33 =>\t%s\n",xyz_tos(sc2)); printf("(1,2,3)*(1.5,3,4.5) =>\t%.2lf\n",dt); printf("magnitude of (1,2,3) =>\t%.2lf\n",mag); printf("norm (0,0,0) =>\t%s\n",xyz_tos(zn)); printf("norm (1,2,3) =>\t%s\n",xyz_tos(vn)); printf(" *****\n"); /* color */ printf(" *** testing color *** \n"); color c = color_expr(1,0.5,0); color cc = color_expr(0.75,0,0.25); color mod = color_modulate(c,cc); color scc = color_scale(1.5, cc); color addc = color_add(c,cc); printf("color_expr(1,0.5,0) =>\t%s\n",color_tos(c)); printf("(1,0.5,0)*(0.75,0,0.25) =>\t%s\n",color_tos(mod)); printf("scale (0.75,0,0.25) by 1.5 =>\t%s\n",color_tos(scc)); printf("(1,0.5,0)+(0.75,0,0.25) =>\t%s\n",color_tos(addc)); printf("(0.75,0,0.25) on [0,255] =>"); color_show_bytes(stdout,cc); printf(" *****\n"); /* ray */ printf(" *** testing ray *** \n"); ray testray = {v,vv}; printf("ray from (1,2,3) to (5,5,5) =>\t%s\n",ray_tos(testray)); printf(" *****\n"); /* sphere */ printf(" *** testing sphere *** \n"); sphere testsph = sphere_expr(v, 3.2, get_sc, c); printf("sphere at (1,2,3) with radius 3.2:\n"); sphere_show(stdout,testsph); printf("\n *****\n"); /* poster */ printf(" *** testing poster *** \n"); poster testpst = poster_expr(v, 4, 5.25, get_sc, c); printf("poster at (1,2,3) with width 4 and height 5.25:\n"); poster_show(stdout,testpst); printf("\n *****\n"); /* object */ printf(" *** testing object *** \n"); object objs = {SPHERE,{.s = testsph},NULL};
Color Color::__add__(const Color& c1) { Color r; color_add(&r.c_, &c_, &c1.c_); return r; }