How do I echo the results of this trigonometry code?
I can’t even tell if this is trigonometry or some other form of mathematics. Shouldn’t it always echo something if the calculations are correct?
There are variables for an image. Is that what I am missing? When I upload it to my website no results or images are posted. Is it possibly my PHP version? I am using blue host.
col_ellipse sounds like a shape to me maybe it isn’t an echo it is some other function to display the results.
This is the link I found the code at if this helps:
https://code.tutsplus.com/tutorials/mathematical-functions-in-php–cms-31972
<?php
$image = imagecreatetruecolor(800, 600);
$bg = imagecolorallocate($image, 255, 255, 255);
imagefill($image, 0, 0, $bg);
$radius = 80;
for($i = 0; $i < 12; $i++) {
$col_ellipse = imagecolorallocate($image, rand(0, 200), rand(0, 200), rand(0, 200));
imagefilledellipse($image, 175 + 125*cos(deg2rad($i*30)), 175 + 125*sin(deg2rad($i*30)),
3*$radius/4, 3*$radius/4, $col_ellipse);
imageellipse($image, 175 + 125*cos(deg2rad($i*30)), 175 + 125*sin(deg2rad($i*30)),
3.5*$radius/4, 3.5*$radius/4, $col_ellipse);
$col_ellipse = imagecolorallocate($image, rand(0, 200), rand(0, 200), rand(0, 200));
imagefilledellipse($image, 575 + 150*cos(deg2rad($i*30)), 375 + 150*sin(deg2rad($i*30)),
3*$radius/4, 3*$radius/4, $col_ellipse);
imageellipse($image, 575 + 150*cos(deg2rad($i*30)), 375 + 150*sin(deg2rad($i*30)),
3.5*$radius/4, 3.5*$radius/4, $col_ellipse);
}
$col_ellipse = imagecolorallocate($image, 255, 255, 255);
imagefilledellipse($image, 175, 175, 275, 275, $col_ellipse);
?>
2
Answers
Add these two lines:
and you’ll see the image. I’ve done this at http://timr.4roberts.us/x.php so you can see the results.
Tim Roberts‘s answer is correct but for best practice, we should add imagedestroy method as well to remove freed any memory associated with an image.