johns
New Member
Posts: 4

Post by johns on Jan 9, 2021 20:43:16 GMT
I feel like im missing something with both the gradient and ring code. I traced through it a few times and for the rings at least it always evaluates to 0, which means it will always return A. Gradient code public override Colour LocalPatternAt(Point3D p)
{
Colour distance = B  A;
double fraction = p.X  Math.Floor(p.X);
return A + distance * fraction;
} Rings code public override Colour LocalPatternAt(Point3D p)
{
if(Math.Floor(Math.Sqrt((p.X * p.X) + (p.Z * p.Z))) % 2 == 0)
{
return A;
}
return B;
} Transform code public Colour PatternAt(Shape shape, Point3D p)
{
Point3D objP = shape.Transform.Inverse() * p;
Point3D patP = Transform.Inverse() * objP;
return LocalPatternAt(patP);
} Attachments:gradient.bmp (25.38 KB)
rings.bmp (21.34 KB)



Post by jdunlap on Jan 25, 2021 16:45:37 GMT
There is no significant difference between my gradient or transformation code and yours, but I did do the rings differently:
protected override Vec4 DerivedColorAt(Vec4 p)
{
int mod = (int)Math.Floor(Math.Sqrt(p.X * p.X + p.Z * p.Z)) % 2;
if (mod == 0)
return Color1;
else
return Color2;
}
It's been a bit since I implemented this, but as I recall, I also had an issue similar to yours until I used the explicit cast like I do. My ring pattern now works as intended. In my experience C# has an issue with using the % operator on floats and doubles.

