void ShimmerEffect::Render(Effect *effect, const SettingsMap &SettingsMap, RenderBuffer &buffer) { float oset = buffer.GetEffectTimeIntervalPosition(); int Duty_Factor = GetValueCurveInt("Shimmer_Duty_Factor", 50, SettingsMap, oset); bool Use_All_Colors = SettingsMap.GetBool("CHECKBOX_Shimmer_Use_All_Colors", false); float cycles = GetValueCurveDouble("Shimmer_Cycles", 1.0, SettingsMap, oset); int colorcnt=buffer.GetColorCount(); double position = buffer.GetEffectTimeIntervalPosition(cycles); double ColorIdx = round(position * 0.999 * (double)colorcnt); double pos2 = position * colorcnt; while (pos2 > 1.0) { pos2 -= 1.0; } if (pos2 * 100 > Duty_Factor) { return; } xlColor color; buffer.palette.GetColor(ColorIdx, color); for (int y=0; y<buffer.BufferHt; y++) { for (int x=0; x<buffer.BufferWi; x++) { if(Use_All_Colors) { // Should we randomly assign colors from palette or cycle thru sequentially? ColorIdx=rand() % colorcnt; // Select random numbers from 0 up to number of colors the user has checked. 0-5 if 6 boxes checked buffer.palette.GetColor(ColorIdx, color); // Now go and get the hsv value for this ColorIdx } buffer.SetPixel(x,y,color); // Turn pixel } } }
void OnEffect::Render(Effect *eff, const SettingsMap &SettingsMap, RenderBuffer &buffer) { int start = SettingsMap.GetInt(TEXTCTRL_Eff_On_Start, 100); int end = SettingsMap.GetInt(TEXTCTRL_Eff_On_End, 100); bool shimmer = SettingsMap.GetInt(CHECKBOX_On_Shimmer, 0) > 0; float cycles = SettingsMap.GetDouble(TEXTCTRL_On_Cycles, 1.0); int x,y; int cidx = 0; if (shimmer) { int tot = buffer.curPeriod - buffer.curEffStartPer; if (tot % 2) { if (buffer.palette.Size() <= 1) { return; } cidx = 1; } } bool spatialcolour = buffer.palette.IsSpatial(cidx); double adjust = buffer.GetEffectTimeIntervalPosition(cycles); xlColor color; if (start == 100 && end == 100) { buffer.palette.GetColor(cidx, color); } else { HSVValue hsv; buffer.palette.GetHSV(cidx,hsv); double d = adjust; d = start + (end - start) * d; d = d / 100.0; hsv.value = hsv.value * d; color = hsv; } int transparency = GetValueCurveInt("On_Transparency", 0, SettingsMap, adjust); if (transparency) { transparency *= 255; transparency /= 100; color.alpha = 255 - transparency; } ///////////////////////// DMX Support //////////////////////// // if the model is a DMX model this will write the color into // the proper red, green, and blue channels. ////////////////////////////////////////////////////////////// if (buffer.cur_model != "") { Model* model_info = buffer.frame->AllModels[buffer.cur_model]; if (model_info != nullptr) { if( model_info->GetDisplayAs() == "DMX" ) { xlColor c; DmxModel* dmx = (DmxModel*)model_info; int red_channel = dmx->GetRedChannel(); int grn_channel = dmx->GetGreenChannel(); int blu_channel = dmx->GetBlueChannel(); if( red_channel != 0 ) { c.red = color.red; c.green = color.red; c.blue = color.red; buffer.SetPixel(red_channel-1, 0, c); } if( grn_channel != 0 ) { c.red = color.green; c.green = color.green; c.blue = color.green; buffer.SetPixel(grn_channel-1, 0, c); } if( blu_channel != 0 ) { c.red = color.blue; c.green = color.blue; c.blue = color.blue; buffer.SetPixel(blu_channel-1, 0, c); } return; } } } ////////////////////////////////////////////////////////////// ///////////////////// End DMX Support //////////////////////// ////////////////////////////////////////////////////////////// //Every Node set to selected color for (x=0; x<buffer.BufferWi; x++) { for (y=0; y<buffer.BufferHt; y++) { if (spatialcolour) { buffer.palette.GetSpatialColor(cidx, (float)x / (float)buffer.BufferWi, (float)y / (float)buffer.BufferHt, color); if (start == 100 && end == 100) { } else { HSVValue hsv = color.asHSV(); double d = adjust; d = start + (end - start) * d; d = d / 100.0; hsv.value = hsv.value * d; color = hsv; } if (transparency) { color.alpha = 255 - transparency; } } buffer.SetPixel(x,y,color); } } if (shimmer || cycles != 1.0) { std::lock_guard<std::recursive_mutex> lock(eff->GetBackgroundDisplayList().lock); eff->GetBackgroundDisplayList().resize((buffer.curEffEndPer - buffer.curEffStartPer + 1) * 6); buffer.CopyPixelsToDisplayListX(eff, 0, 0, 0); } else if (buffer.needToInit) { std::lock_guard<std::recursive_mutex> lock(eff->GetBackgroundDisplayList().lock); eff->GetBackgroundDisplayList().resize(6); if (start == 100 && end == 100) { buffer.palette.GetColor(0, color); buffer.SetDisplayListHRect(eff, 0, 0.0, 0.0, 1.0, 1.0, color, color); } else { HSVValue hsv; buffer.palette.GetHSV(cidx,hsv); hsv.value = hsv.value * start / 100.0; color = hsv; buffer.palette.GetHSV(cidx,hsv); hsv.value = hsv.value * end / 100.0; buffer.SetDisplayListHRect(eff, 0, 0.0, 0.0, 1.0, 1.0, color, xlColor(hsv)); } buffer.needToInit = false; } }
void PinwheelEffect::Render(Effect *effect, const SettingsMap &SettingsMap, RenderBuffer &buffer) { float oset = buffer.GetEffectTimeIntervalPosition(); int pinwheel_arms = SettingsMap.GetInt("SLIDER_Pinwheel_Arms", 3); int pinwheel_twist = GetValueCurveInt("Pinwheel_Twist", 0, SettingsMap, oset); int pinwheel_thickness = GetValueCurveInt("Pinwheel_Thickness", 0, SettingsMap, oset); bool pinwheel_rotation = SettingsMap.GetBool("CHECKBOX_Pinwheel_Rotation"); const std::string &pinwheel_3d = SettingsMap["CHOICE_Pinwheel_3D"]; int xc_adj = GetValueCurveInt("PinwheelXC", 0, SettingsMap, oset); int yc_adj = GetValueCurveInt("PinwheelYC", 0, SettingsMap, oset); int pinwheel_armsize = GetValueCurveInt("Pinwheel_ArmSize", 100, SettingsMap, oset); int pspeed = GetValueCurveInt("Pinwheel_Speed", 10, SettingsMap, oset); const std::string &pinwheel_style = SettingsMap["CHOICE_Pinwheel_Style"]; int xc; float tmax; HSVValue hsv, hsv1; double pos = (buffer.curPeriod - buffer.curEffStartPer) * pspeed * buffer.frameTimeInMs / 50; int degrees_per_arm = 1; if (pinwheel_arms > 0) degrees_per_arm = 360 / pinwheel_arms; float armsize = (pinwheel_armsize / 100.0); if (pinwheel_style == "New Render Method") { std::vector<size_t> colorarray; colorarray.resize(pinwheel_arms); for (int i = 0; i < pinwheel_arms; i++) { colorarray[i] = i%buffer.GetColorCount(); } xc = (int)(ceil(std::hypot(buffer.BufferWi, buffer.BufferHt) / 2)); xc_adj = xc_adj*buffer.BufferWi / 200; yc_adj = yc_adj*buffer.BufferHt / 200; int max_radius = xc * armsize; if (pinwheel_thickness == 0) pinwheel_thickness = 1; tmax = (pinwheel_thickness / 100.0)*degrees_per_arm; // Force single visible line in case width is narrower than visible float pi_180 = M_PI/180; for(int a=0; a<pinwheel_arms; a++) { int ColorIdx = a%pinwheel_arms; xlColor color; buffer.palette.GetHSV(colorarray[ColorIdx], hsv); color = xlColor(hsv); int angle = (a*degrees_per_arm); if (pinwheel_rotation == 1) // do we have CW rotation { angle = (270 - angle) + pos; } else { angle = angle - 90 - pos; } int x,y, degrees_twist; for (float r=0; r<=max_radius; r+=0.5) { degrees_twist = (r/max_radius) * pinwheel_twist; int t2 = (int)angle%degrees_per_arm; double round = (float)t2 / (float)tmax; x = floor((int)(r * buffer.cos((angle + degrees_twist) * pi_180)) + xc_adj + buffer.BufferWi / 2); y = floor((int)(r * buffer.sin((angle + degrees_twist) * pi_180)) + yc_adj + buffer.BufferHt / 2); if (buffer.palette.IsSpatial(colorarray[ColorIdx])) { buffer.palette.GetSpatialColor(colorarray[ColorIdx], xc_adj + buffer.BufferWi / 2, yc_adj + buffer.BufferHt / 2, x, y, round, max_radius, color); } buffer.SetPixel(x,y,color); } } // Draw actual pinwheel arms for (int x = 0; x < buffer.BufferWi; x++) { int x1 = x - xc_adj - (buffer.BufferWi / 2); for (int y = 0; y < buffer.BufferHt; y++) { int y1 = y - yc_adj - (buffer.BufferHt / 2); double r = std::hypot(x1, y1); if (r <= max_radius) { double degrees_twist = (r / max_radius)*pinwheel_twist; double theta = (std::atan2(x1, y1) * 180 / 3.14159) + degrees_twist; if (pinwheel_rotation == 1) // do we have CW rotation { theta = pos + theta + (tmax/2); } else { theta = pos - theta + (tmax/2); } theta = theta + 540.0; int t2 = (int)theta%degrees_per_arm; if (t2 <= tmax) { double round = (float)t2 / (float)tmax; t2 = std::abs(t2 - (tmax/2)) * 2; xlColor color; int ColorIdx2 = ((int)((theta/degrees_per_arm)))%pinwheel_arms; if (buffer.palette.IsSpatial(colorarray[ColorIdx2])) { buffer.palette.GetSpatialColor(colorarray[ColorIdx2], xc_adj + buffer.BufferWi / 2, yc_adj + buffer.BufferHt / 2, x, y, round, max_radius, color); hsv = color.asHSV(); } else { buffer.palette.GetHSV(colorarray[ColorIdx2], hsv); } hsv1=hsv; color = xlColor(hsv1); if(pinwheel_3d=="3D") { if (buffer.allowAlpha) { color.alpha = 255.0 * ((tmax - t2) / tmax); } else { hsv1.value = hsv.value * ((tmax - t2) / tmax); color = hsv1; } } else if (pinwheel_3d == "3D Inverted") { if (buffer.allowAlpha) { color.alpha = 255.0 * ((t2) / tmax); } else { hsv1.value = hsv.value * ((t2) / tmax); color = hsv1; } } buffer.SetPixel(x, y, color); } } } } } else { // Old Render Method int a,xc,ColorIdx,base_degrees; float t,tmax; float radius; HSVValue hsv,hsv0,hsv1; size_t colorcnt=buffer.GetColorCount(); xc= (int)(std::max(buffer.BufferWi, buffer.BufferHt)/2); radius = xc/100.0; for(a=1; a<=pinwheel_arms; a++) { ColorIdx=a%colorcnt; buffer.palette.GetHSV(ColorIdx, hsv); // Now go and get the hsv value for this ColorIdx if(pinwheel_rotation==1) // do we have CW rotation { base_degrees = (a-1)*degrees_per_arm + pos; // yes } else { base_degrees = (a-1)*degrees_per_arm - pos; // no, we are CCW } Draw_arm(buffer, base_degrees, xc*armsize, pinwheel_twist,hsv,xc_adj,yc_adj); if(pinwheel_thickness>0) { tmax= (pinwheel_thickness/100.0)*degrees_per_arm/2.0; hsv1=hsv; xlColor color(hsv1); for (t=1; t<=tmax; t++) { if(pinwheel_3d=="3D") { if (buffer.allowAlpha) { color.alpha = 255.0 * ((tmax-t)/tmax); } else { hsv1.value = hsv.value * ((tmax-t)/tmax); color = hsv1; } } else if(pinwheel_3d=="3D Inverted") { if (buffer.allowAlpha) { color.alpha = 255.0 * ((t)/tmax); } else { hsv1.value = hsv.value * ((t)/tmax); color = hsv1; } } Draw_arm(buffer, base_degrees-t, xc*armsize, pinwheel_twist,color,xc_adj,yc_adj); Draw_arm(buffer, base_degrees+t, xc*armsize, pinwheel_twist,color,xc_adj,yc_adj); } } } } }
void MorphEffect::Render(Effect *effect, const SettingsMap &SettingsMap, RenderBuffer &buffer) { double eff_pos = buffer.GetEffectTimeIntervalPosition(); int start_x1 = GetValueCurveInt("Morph_Start_X1", 0, SettingsMap, eff_pos); int start_y1 = GetValueCurveInt("Morph_Start_Y1", 0, SettingsMap, eff_pos); int start_x2 = GetValueCurveInt("Morph_Start_X2", 0, SettingsMap, eff_pos); int start_y2 = GetValueCurveInt("Morph_Start_Y2", 0, SettingsMap, eff_pos); int end_x1 = GetValueCurveInt("Morph_End_X1", 0, SettingsMap, eff_pos); int end_y1 = GetValueCurveInt("Morph_End_Y1", 0, SettingsMap, eff_pos); int end_x2 = GetValueCurveInt("Morph_End_X2", 0, SettingsMap, eff_pos); int end_y2 = GetValueCurveInt("Morph_End_Y2", 0, SettingsMap, eff_pos); int start_length = GetValueCurveInt("MorphStartLength", 0, SettingsMap, eff_pos); int end_length = GetValueCurveInt("MorphEndLength", 0, SettingsMap, eff_pos); int duration = GetValueCurveInt("MorphDuration", 0, SettingsMap, eff_pos); int acceleration = GetValueCurveInt("MorphAccel", 0, SettingsMap, eff_pos); int repeat_count = GetValueCurveInt("Morph_Repeat_Count", 0, SettingsMap, eff_pos); int repeat_skip = GetValueCurveInt("Morph_Repeat_Skip", 0, SettingsMap, eff_pos); int stagger = GetValueCurveInt("Morph_Stagger", 0, SettingsMap, eff_pos); bool start_linked = SettingsMap.GetBool("CHECKBOX_Morph_Start_Link"); bool end_linked = SettingsMap.GetBool("CHECKBOX_Morph_End_Link"); bool showEntireHeadAtStart = SettingsMap.GetBool("CHECKBOX_ShowHeadAtStart"); double step_size = 0.1; int hcols = 0, hcole = 1; int tcols = 2, tcole = 3; int num_tail_colors = 2; switch (buffer.palette.Size()) { case 1: //one color selected, use it for all hcols = hcole = tcols = tcole = 0; break; case 2: //two colors, head/tail hcols = hcole = 0; tcols = tcole = 1; break; case 3: //three colors, head /tail start/end hcols = hcole = 0; tcols = 1; tcole = 2; break; default: num_tail_colors = buffer.palette.Size() - 2; break; } int x1a = calcPosition(start_x1, buffer.BufferWi); int y1a = calcPosition(start_y1, buffer.BufferHt); int x2a = calcPosition(end_x1, buffer.BufferWi); int y2a = calcPosition(end_y1, buffer.BufferHt); int x1b, x2b, y1b, y2b; if( start_linked ) { x1b = x1a; y1b = y1a; } else { x1b = calcPosition(start_x2, buffer.BufferWi); y1b = calcPosition(start_y2, buffer.BufferHt); } if( end_linked ) { x2b = x2a; y2b = y2a; } else { x2b = calcPosition(end_x2, buffer.BufferWi); y2b = calcPosition(end_y2, buffer.BufferHt); } xlColor head_color, tail_color, test_color; // compute direction int delta_xa = x2a - x1a; int delta_xb = x2b - x1b; int delta_ya = y2a - y1a; int delta_yb = y2b - y1b; int direction = delta_xa + delta_xb + delta_ya + delta_yb; int repeat_x = 0; int repeat_y = 0; double effect_pct = 1.0; double stagger_pct = 0.0; if( repeat_count > 0 ) { if( (std::abs((float)delta_xa) + std::abs((float)delta_xb)) < (std::abs((float)delta_ya) + std::abs((float)delta_yb)) ) { repeat_x = repeat_skip; } else { repeat_y = repeat_skip; } double stagger_val = (double)(std::abs((double)stagger))/200.0; effect_pct = 1.0 / (1 + stagger_val * repeat_count); stagger_pct = effect_pct * stagger_val; } std::vector<int> v_ax; std::vector<int> v_ay; std::vector<int> v_bx; std::vector<int> v_by; StoreLine(x1a, y1a, x2a, y2a, &v_ax, &v_ay); // store side a StoreLine(x1b, y1b, x2b, y2b, &v_bx, &v_by); // store side b int size_a = v_ax.size(); int size_b = v_bx.size(); std::vector<int> *v_lngx; // pointer to longest vector x std::vector<int> *v_lngy; // pointer to longest vector y std::vector<int> *v_shtx; // pointer to shorter vector x std::vector<int> *v_shty; // pointer to shorter vector y if( size_a > size_b ) { v_lngx = &v_ax; v_lngy = &v_ay; v_shtx = &v_bx; v_shty = &v_by; } else { v_lngx = &v_bx; v_lngy = &v_by; v_shtx = &v_ax; v_shty = &v_ay; } double pos_a, pos_b; double total_tail_length, alpha_pct; double total_length = v_lngx->size(); // total length of longest vector double head_duration = duration/100.0; // time the head is in the frame double head_end_of_head_pos = total_length + 1; double tail_end_of_head_pos = total_length + 1; double head_end_of_tail_pos = -1; double tail_end_of_tail_pos = -1; for( int repeat = 0; repeat <= repeat_count; repeat++ ) { double eff_pos_adj = buffer.calcAccel(eff_pos, acceleration); double eff_start_pct = (stagger >= 0) ? stagger_pct*repeat : stagger_pct*(repeat_count-repeat); double eff_end_pct = eff_start_pct + effect_pct; eff_pos_adj = (eff_pos_adj - eff_start_pct) / (eff_end_pct - eff_start_pct); if( eff_pos_adj < 0.0 ) { head_end_of_head_pos = -1; tail_end_of_head_pos = -1; head_end_of_tail_pos = -1; tail_end_of_tail_pos = -1; total_tail_length = 1.0; if( showEntireHeadAtStart ) { head_end_of_head_pos = start_length; } } else { if( head_duration > 0.0 ) { double head_loc_pct = eff_pos_adj / head_duration; head_end_of_head_pos = total_length * head_loc_pct; double current_total_head_length = end_length * head_loc_pct + start_length * (1.0 - head_loc_pct); // adjusted head length excluding clipping head_end_of_head_pos += current_total_head_length * head_loc_pct * head_duration; total_tail_length = total_length * ( 1 / head_duration - 1.0); if( showEntireHeadAtStart ) { head_end_of_head_pos += current_total_head_length * (1.0 - eff_pos_adj); } tail_end_of_head_pos = head_end_of_head_pos - current_total_head_length; head_end_of_tail_pos = tail_end_of_head_pos - step_size; tail_end_of_tail_pos = head_end_of_tail_pos - total_tail_length; buffer.Get2ColorBlend(hcols, hcole, std::min( head_loc_pct, 1.0), head_color); } else { total_tail_length = total_length; head_end_of_tail_pos = total_length * 2 * eff_pos_adj; tail_end_of_tail_pos = head_end_of_tail_pos - total_tail_length; } } // draw the tail for( double i = std::min(head_end_of_tail_pos, total_length-1); i >= tail_end_of_tail_pos && i >= 0.0; i -= step_size ) { double pct = ((total_length == 0) ? 0.0 : i / total_length); pos_a = i; pos_b = v_shtx->size() * pct; double tail_color_pct = (i-tail_end_of_tail_pos) / total_tail_length; if( num_tail_colors > 2 ) { double color_index = ((double)num_tail_colors - 1.0) * (1.0 - tail_color_pct); tail_color_pct = color_index - (double)((int)color_index); tcols = (int)color_index + 2; tcole = tcols + 1; if( tcole == num_tail_colors+1 ) { alpha_pct = (1.0 - tail_color_pct); } else { alpha_pct = 1.0; } buffer.Get2ColorBlend(tcols, tcole, tail_color_pct, tail_color); } else { if( tail_color_pct > 0.5 ) { alpha_pct = 1.0; } else { alpha_pct = tail_color_pct / 0.5; } buffer.Get2ColorBlend(tcole, tcols, tail_color_pct, tail_color); } if( buffer.allowAlpha ) { tail_color.alpha = 255 * alpha_pct; } buffer.DrawThickLine( (*v_lngx)[pos_a]+(repeat_x*repeat), (*v_lngy)[pos_a]+(repeat_y*repeat), (*v_shtx)[pos_b]+(repeat_x*repeat), (*v_shty)[pos_b]+(repeat_y*repeat), tail_color, direction >= 0); } // draw the head for( double i = std::max(tail_end_of_head_pos, 0.0); i <= head_end_of_head_pos && i < total_length; i += step_size ) { double pct = ((total_length == 0) ? 0.0 : i / total_length); pos_a = i; pos_b = v_shtx->size() * pct; buffer.DrawThickLine( (*v_lngx)[pos_a]+(repeat_x*repeat), (*v_lngy)[pos_a]+(repeat_y*repeat), (*v_shtx)[pos_b]+(repeat_x*repeat), (*v_shty)[pos_b]+(repeat_y*repeat), head_color, direction >= 0); } } }