Page 1 of 1
Modulo?
Posted: Mon Sep 10, 2012 12:08 pm
by darkhog
How do I get modulo, i.e. x mod y in Pascal or x%y in C? Tried both in expression and got only InvalidExpr.
Posted: Mon Sep 10, 2012 12:30 pm
by Kjell
Hi darkhog,
There is no modulo operator in ZGameEditor at the moment ( no idea why ). You can define it as a function yourself though .. simply copy-paste the following into the App.OnLoaded node of your project.
Code: Select all
ZZDC<?xml version="1.0" encoding="iso-8859-1" ?>
<ZLibrary Comment="Standard">
<Source>
<![CDATA[//
float mod(float a, float n)
{
return a - n * floor(a / n);
}]]>
</Source>
</ZLibrary>
K
Posted: Mon Sep 10, 2012 12:43 pm
by darkhog
Your code doesn't work. This BitmapExpression should fill every second column leaving anything else black, but instead it only fills first column:
if (mod(this.X,2)==0){
this.Pixel.R=((abs(sin(this.X-3))*5)-abs(atan2(this.Y+3,this.X*6)*5))*cos(this.Pixel.B);
this.Pixel.G=((abs(cos(this.X-3))*5)-abs(sin(this.Y-3))*5)*cos(this.Pixel.R);
this.Pixel.B=cos(this.Pixel.G)*cos(this.X*sin(this.Y));
}
Posted: Mon Sep 10, 2012 1:09 pm
by Kjell
Hi darkhog,
The X and Y properties of the
BitmapExpression component are floating point variables in the 0-1 range* So you need to calculate the pixel coordinates yourself if you want to use those ( i know .. it's counter-intuitive ).
Code: Select all
float X, Y;
X = this.X * 64; // 64 is the horizontal resolution of the bitmap
Y = this.Y * 64; // 64 is the vertical resolution of the bitmap
if(mod(X,2) == 0)
{
// Your algorithm :-)
}
*Actually, 1-1/resolution instead of 1 to be precise.
K
Posted: Mon Sep 10, 2012 1:40 pm
by darkhog
Thanks! Works great!
Posted: Mon Sep 10, 2012 7:06 pm
by Rado1
BTW % operator or built-in mod function would help anyway.