Modulo?

All topics about ZGameEditor goes here.

Moderator: Moderators

Post Reply
darkhog
Posts: 58
Joined: Sun Sep 09, 2012 7:59 pm

Modulo?

Post 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.
User avatar
Kjell
Posts: 1883
Joined: Sat Feb 23, 2008 11:15 pm

Post 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
darkhog
Posts: 58
Joined: Sun Sep 09, 2012 7:59 pm

Post 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));
}
User avatar
Kjell
Posts: 1883
Joined: Sat Feb 23, 2008 11:15 pm

Post 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
darkhog
Posts: 58
Joined: Sun Sep 09, 2012 7:59 pm

Post by darkhog »

Thanks! Works great!
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post by Rado1 »

BTW % operator or built-in mod function would help anyway.
Post Reply