Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion Lux/lux_files/CA_choices.json
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,30 @@
"default_value": 0.0,
"step": 1.0
},
{
"name": "invert_target_toggle",
"type": "random_toggle",
"p": { "functions": [ "autoplay_intensity", "autoplay_probability" ] },
"enabled": { "functions": [ "autoplay_switch" ] }
},
{
"name": "invert_target_switch",
"type": "switch_fn",
"label": "Invert Target",
"description": "Invert the colors of the target image.",
"default_value": false,
"value": { "functions": [ "invert_target_toggle" ] }
},
{
"name": "target_color_angle_slider",
"type": "slider_float",
"label": "Target Color Angle",
"description": "Angle to rotate the target color (degrees).",
"min": -180.0,
"max": 180.0,
"default_value": 0.0,
"step": 1.0
},
{
"name": "warp_menu_generator",
"type": "generator_int",
Expand Down Expand Up @@ -506,6 +530,8 @@
"bright_range": { "functions": [ "bright_block_slider" ] },
"targeted": { "functions": [ "target_switch" ] },
"target_name": {"functions": [ "targ_image_menu" ] },
"invert_target": { "functions": [ "invert_target_switch" ] },
"target_color_angle": { "functions": [ "target_color_angle_slider" ] },
"warp_name": "Target Warp",
"rule":
{
Expand All @@ -519,6 +545,8 @@
"edge_block": { "functions": [ "edge_block_switch" ] },
"targeted": { "functions": [ "target_switch" ] },
"target_name": {"functions": [ "targ_image_menu" ] },
"invert_target": { "functions": [ "invert_target_switch" ] },
"target_color_angle": { "functions": [ "target_color_angle_slider" ] },
"warp_name": "Target Warp",
"rule":
{
Expand All @@ -536,6 +564,8 @@
"edge_block": { "functions": [ "edge_block_switch" ] },
"targeted": { "functions": [ "target_switch" ] },
"target_name": {"functions": [ "targ_image_menu" ] },
"invert_target": { "functions": [ "invert_target_switch" ] },
"target_color_angle": { "functions": [ "target_color_angle_slider" ] },
"warp_name": "Target Warp",
"rule":
{
Expand All @@ -552,6 +582,8 @@
"edge_block": { "functions": [ "edge_block_switch" ] },
"targeted": { "functions": [ "target_switch" ] },
"target_name": {"functions": [ "targ_image_menu" ] },
"invert_target": { "functions": [ "invert_target_switch" ] },
"target_color_angle": { "functions": [ "target_color_angle_slider" ] },
"warp_name": "Target Warp",
"rule":
{
Expand All @@ -568,6 +600,8 @@
"bright_range": { "functions": [ "bright_block_slider" ] },
"targeted": { "functions": [ "target_switch" ] },
"target_name": {"functions": [ "targ_image_menu" ] },
"invert_target": { "functions": [ "invert_target_switch" ] },
"target_color_angle": { "functions": [ "target_color_angle_slider" ] },
"warp_name": "Target Warp",
"rule":
{
Expand Down Expand Up @@ -604,6 +638,8 @@
"bright_range": { "functions": [ "bright_block_slider" ] },
"targeted": { "functions": [ "target_switch" ] },
"target_name": {"functions": [ "targ_image_menu" ] },
"invert_target": { "functions": [ "invert_target_switch" ] },
"target_color_angle": { "functions": [ "target_color_angle_slider" ] },
"warp_name": "Target Warp",
"rule":
{
Expand All @@ -622,6 +658,8 @@
"bright_range": { "functions": [ "bright_block_slider" ] },
"targeted": { "functions": [ "target_switch" ] },
"target_name": {"functions": [ "targ_image_menu" ] },
"invert_target": { "functions": [ "invert_target_switch" ] },
"target_color_angle": { "functions": [ "target_color_angle_slider" ] },
"warp_name": "Target Warp",
"rule":
{
Expand All @@ -642,6 +680,8 @@
"bright_range": { "functions": [ "bright_block_slider" ] },
"targeted": { "functions": [ "target_switch" ] },
"target_name": {"functions": [ "targ_image_menu" ] },
"invert_target": { "functions": [ "invert_target_switch" ] },
"target_color_angle": { "functions": [ "target_color_angle_slider" ] },
"warp_name": "Target Warp",
"rule":
{
Expand All @@ -662,6 +702,8 @@
"bright_range": { "functions": [ "bright_block_slider" ] },
"targeted": { "functions": [ "target_switch" ] },
"target_name": {"functions": [ "targ_image_menu" ] },
"invert_target": { "functions": [ "invert_target_switch" ] },
"target_color_angle": { "functions": [ "target_color_angle_slider" ] },
"warp_name": "Target Warp",
"rule":
{
Expand Down Expand Up @@ -756,7 +798,7 @@
},
{
"name": "targ_image_group",
"widgets": [ "targ_image_menu", "warp_menu" ]
"widgets": [ "targ_image_menu", "invert_target_switch", "target_color_angle_slider", "warp_menu" ]
},
{
"name": "flip_group",
Expand Down
14 changes: 14 additions & 0 deletions Lux/lux_react/src/lux.js

Large diffs are not rendered by default.

19 changes: 16 additions & 3 deletions Lux/src/life.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,17 @@ template< class T > void CA< T >::run_rule() {
// future - implement multiresolution rule on mip-map
// Uses toroidal boundary conditions
template< class T > void CA< T >::operator() ( any_buffer_pair_ptr& buf, element_context& context ) {

if( ca_frame == 0 ) {
ca_frame++;
return;
}
p( context ); targeted( context );
bright_block( context ); bright_range( context );
edge_block( context ); alpha_block( context );
invert_target( context ); target_color_angle( context );
target_name( context ); warp_name( context );
//std::cout << "CA: bright_block " << *bright_block << " bright_min " << (*bright_range).min << " bright_max " << (*bright_range).max << std::endl;
// convert target color angle to byte rotation (0-255) shifted to hue byte
unsigned int target_byte_rotation = static_cast<unsigned int>(static_cast<int>( std::floor( *target_color_angle / 360.0f * 256.0f + 0.5f ) ) % 256) << 16;
hood = rule.init( context );
if ( std::holds_alternative< std::shared_ptr< buffer_pair< T > > >( buf ) ) {
auto buf_ptr = std::get< std::shared_ptr< buffer_pair< T > > >( buf );
Expand Down Expand Up @@ -224,7 +225,10 @@ template< class T > void CA< T >::operator() ( any_buffer_pair_ptr& buf, element
ty = y * tdm1.y / dm1.y;
if( use_wf ) { tar_it = tar + *( wf + ty * tar_dim.x + tx ); }
else { tar_it = tar + ty * tar_dim.x + tx; }
if( manhattan( *tar_it, result[0] ) < manhattan( *tar_it, MM ) ) *out_it = result[0];
ucolor t = *tar_it;
if( *invert_target ) invert( t );
if( target_byte_rotation != 0 ) t = hsv_to_rgb( rotate_hue( rgb_to_hsv( t ), target_byte_rotation ) );
if( manhattan( t, result[0] ) < manhattan( t, MM ) ) *out_it = result[0];
else *out_it = MM;
}
else *out_it = result[0]; // set output
Expand Down Expand Up @@ -331,6 +335,15 @@ template< class T > void CA< T >::operator() ( any_buffer_pair_ptr& buf, element

run_rule(); // apply rule
if( use_target ) {
if( *invert_target ) {
invert( TUL ); invert( TUR ); invert( TLL ); invert( TLR );
}
if( target_byte_rotation != 0 ) {
TUL = hsv_to_rgb( rotate_hue( rgb_to_hsv( TUL ), target_byte_rotation ) );
TUR = hsv_to_rgb( rotate_hue( rgb_to_hsv( TUR ), target_byte_rotation ) );
TLL = hsv_to_rgb( rotate_hue( rgb_to_hsv( TLL ), target_byte_rotation ) );
TLR = hsv_to_rgb( rotate_hue( rgb_to_hsv( TLR ), target_byte_rotation ) );
}
if( manhattan( RUL, TUL ) + manhattan( RUR, TUR ) + manhattan( RLR, TLR ) + manhattan( RLL, TLL ) <
manhattan( MUL, TUL ) + manhattan( MUR, TUR ) + manhattan( MLR, TLR ) + manhattan( MLL, TLL ) )
{ *out_ul = RUL; *out_ur = RUR; *out_ll = RLL; *out_lr = RLR; }
Expand Down
2 changes: 2 additions & 0 deletions Lux/src/life.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ template< class T > struct CA {
std::vector< T > neighbors, result, targ; // vector of neighbors - size depends on neighborhood
// Future - use for image targeting
harness< bool > targeted; // if true, rule will run if it gets closer to target image
harness< bool > invert_target; // if true, invert the target color
harness< float > target_color_angle; // color rotation angle (degrees) for color comparison
harness< string > target_name, warp_name;
//any_buffer_pair_ptr target; // target image
//
Expand Down
1 change: 1 addition & 0 deletions Lux/src/scene_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,7 @@ void scene_reader::read_effect( const json& j ) {
EFF( CA_ucolor )
if( j.contains( "rule" ) ) read_rule( j[ "rule" ], e );
HARNESSE( target_name ) HARNESSE( warp_name ) HARNESSE( targeted )
HARNESSE( invert_target ) HARNESSE( target_color_angle );
HARNESSE( p ) HARNESSE( edge_block ) HARNESSE( alpha_block )
HARNESSE( bright_block ) HARNESSE( bright_range )
END_EFF()
Expand Down