Jump to content

[SOLVED] A Modulus among Us


tigomark

Recommended Posts

Hello,

 

 

I am having trouble adjusting a modulus that I have created

 

for ($i=1; $i<=11; $i++){
$field = 'zone'.($i).'_id';

$this->zoneColors[$i] = $row[$field] % 11 ;

 

When I build my switch

 

function showShapeColor($color){
strtolower($color);
switch($color){
case 1:
return "#ff0000";
break;
case 2:
return "#0000ff";
break;
case 3:
return "#00ff00";
break;
case 4:
return "#FF6600";
break;
case 5:
return "#CC00CC";
break;
case 6:
return "#996600";
break;
case 7:
return "#FFCC00";
break;
case 8:
return "#5a6d24";
break;
case 9:
return "#CC9999";
break;
case 10:
return "#CDDF60";
break;
case 11:
return "#44e2f1";
break;
case 12:
return "#4feff1";
break;
default:
return "#ffffff";	
break;	
}

}

 

Occasionally I will have overlapping values ie

 

int(5) may be attached to more than one record thus giving 2 rows the same color. I need to build a way to check for this so that if that happens one of the 5's will be  #f5f5f5 and the other will be the regular color. Kind of lost on how.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/88600-solved-a-modulus-among-us/
Share on other sites

I figured it out

 

for ($j = 1; $j <= 11; $j++){
   	 if(($entry->zoneColors[$j] == $entry->zoneColors[$j + 1]) && ($entry->zoneColors[$j] != 0)){
   	 	$entry->zoneColors[$j] = 12;
	}
   	}

 

I just needed to compare the array types in the view and then append to the unused 12th color in that instance.

 

Thanks to all who looked at this

You can make that function a LOT easier to manage like this:

 

<?php

function showShapeColor($color){
strtolower($color);
$colorsAry = (
    '0' => "#ffffff", //Default
    '1' => "#ff0000",
    '2' => "#0000ff",
    '3' => "#00ff00",
    '4' => "#FF6600",
    '5' => "#CC00CC",
    '6' => "#996600",
    '7' => "#FFCC00",
    '8' => "#5a6d24",
    '9' => "#CC9999",
    '10' => "#CDDF60",
    '11' => "#4feff1",
    '12' => "#ff0000"
);

//Set to default if not valid
if (!in_array($color, $colorsAry) {
    $color = 0;
} else

return $colorsAry[$color];
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.