Adding more gates.

Since I took the task of making gates equivalent of E2 functions, a lot of gates have been made. And more will be made. If you have suggestions for gates, either send me PM or post a comment on this post. So far the list of gates include:


Angle:
Addition
Compose
Decompose
Direction (forward, left, up)
Division
Equal
Identity
Inequal
Multiplication
Negate
Normalize
Round
Shift Components Left
Shift Components Right
Subtraction
To String



Entity:
AimDirection
AimEntity
AimPosition
Angles
Angular Velocity
Apply Angular Force
Apply Force
Apply Offset Force
Class
Color
Direction (forward, right, up)
Entity ID
Equal
Health
Inequal
Inertia
Is In Vehicle
Is NPC
Is On Fire
Is On Ground
Is Player
Is Player Holding
Is Under Water
Is Valid
Is Vehicle
Is Weapon
Is World
Local to World
Mass
Mass Center
Mass Center (local)
Material
Model
Name
Owner
Position
Radius
Set Color
Set Mass
SteamID
Time Connected
Velocity
Velocity (local)
World to Local (angle)
World to Local (vector)



Ranger:

Distance
Entity
Hit
Hit Normal
Hit Position
Hit World
Trace



String:
Equal
Index
Inequal
Length
Lowercase
Substring
Substring from Left
Substring from Right
Uppercase



Vector:
Addition
Angles(degree)
Angles(radian)
Component Derivative
Component Integral
Compose
Cross Product
D-Latch
Decompose
Demultiplexer
Division
Dot Product
Equal
Greater Than
Greater Than or Equal To
Identity
Inequal
Is In World
Largest
Latch
Less Than
Less Than or Equal To
Magnitude
Multiplexer
Multiplication
Negate
Normalize
Positive
Random
Round
Shift Components Left
Shift Components Right
Smallest
Subtraction
To String

Back to School...

In two days, the school starts in Norway. I do actually look forward to it. I've gotten quite lazy this holiday. But this will also mean that I will probably not be as active on the forums the following weeks. I hope I can get myself to concentrate in the math/english classes. Even though everything we 'learn' is too easy. I do look forward to seeing my friends again, too. Even though they are not the same 'type' as me, we do have very much fun together. This brings me on, there is actually only two guys in my entire school that I know have been programming. Both of them are my friends... Anyhow, wish me luck :)

Snake using Expression 2

I saw the thread about Tetris on wiremod.com a couple of days ago, and I though "why not make several old hits using wiremod?". So here you are, my attempt to make Snake, enjoy the videos.

Video #1


Video #2



And some images:











Expression 2 source code:


@name Snake
@inputs Act Sc:wirelink Ws A S D Hp Hm Reset Sp Sm St Button
@outputs CL CD Nu NDir Mode In M V N Spd H W Size Stage Pos Dir Posn:array I EatenFood CurFPos LastPos GameO
@trigger all
interval(N)

if(first()|duped())
{
Dir = 1
GameO = 0
N = 500
Size = Sc:readCell(1048572)
H = Sc:readCell(1048572)
W = Sc:readCell(1048572)
Stage = 0
CurFPos = randint(1,H*W)
Pos=H*W/2
}
if(Reset)
{
Stage = 0
reset()
}
if(!Stage)
{
Size += Hp-Hm
N = 700
Sc:writeCell(1048572,32)
Sc:writeCell(1048573,32)
In += (Sm-Sp)*50
In = clamp(In,250,1000)
Spd = (In*-1+1050)
Posn = array()
EatenFood = 0
Mode = !Button
M = 1
Pos = 0
if(!first()&!duped()&!changed(Stage)){
if(St|changed(Act)&Act){Stage = 1 }
}
V = 14
if(changed(Stage)|first()|duped()){
Sc:writeCell(1048574,1)
Sc:writeCell(2+32*V,9000)
Sc:writeCell(3+32*V,9000)
Sc:writeCell(6+32*V,990000)
Sc:writeCell(10+32*V,990000)
Sc:writeCell(15+32*V,900000)
Sc:writeCell(20+32*V,752000)
Sc:writeCell(23+32*V,752000)
Sc:writeCell(26+32*V,9000)
Sc:writeCell(27+32*V,9000)
Sc:writeCell(28+32*V,9000)
Sc:writeCell(29+32*V,9000)
Sc:writeCell(1+32+32*V,9000)
Sc:writeCell(6+32+32*V,990000)
Sc:writeCell(7+32+32*V,990000)
Sc:writeCell(10+32+32*V,990000)
Sc:writeCell(14+32+32*V,900000)
Sc:writeCell(16+32+32*V,900000)
Sc:writeCell(20+32+32*V,752000)
Sc:writeCell(22+32+32*V,752000)
Sc:writeCell(26+32+32*V,9000)
Sc:writeCell(2+64+32*V,9000)
Sc:writeCell(6+64+32*V,990000)
Sc:writeCell(8+64+32*V,990000)
Sc:writeCell(10+64+32*V,990000)
Sc:writeCell(14+64+32*V,900000)
Sc:writeCell(15+64+32*V,900000)
Sc:writeCell(16+64+32*V,900000)
Sc:writeCell(20+64+32*V,752000)
Sc:writeCell(21+64+32*V,752000)
Sc:writeCell(26+64+32*V,9000)
Sc:writeCell(27+64+32*V,9000)
Sc:writeCell(3+96+32*V,9000)
Sc:writeCell(6+96+32*V,990000)
Sc:writeCell(9+96+32*V,990000)
Sc:writeCell(10+96+32*V,990000)
Sc:writeCell(13+96+32*V,900000)
Sc:writeCell(17+96+32*V,900000)
Sc:writeCell(20+96+32*V,752000)
Sc:writeCell(22+96+32*V,752000)
Sc:writeCell(26+96+32*V,9000)
Sc:writeCell(1+128+32*V,9000)
Sc:writeCell(2+128+32*V,9000)
Sc:writeCell(6+128+32*V,990000)
Sc:writeCell(10+128+32*V,990000)
Sc:writeCell(13+128+32*V,900000)
Sc:writeCell(17+128+32*V,900000)
Sc:writeCell(20+128+32*V,752000)
Sc:writeCell(23+128+32*V,752000)
Sc:writeCell(26+128+32*V,9000)
Sc:writeCell(27+128+32*V,9000)
Sc:writeCell(28+128+32*V,9000)
Sc:writeCell(29+128+32*V,9000)
}
}
if(Stage==1){
if(Ws & Dir != H & Dir != -H)
{
Dir = -H
}
elseif(S & Dir != -H & Dir != H)
{
Dir = H
}
elseif(A & Dir != 1 & Dir != -1)
{
Dir = -1
}
elseif(D & Dir != -1 & Dir != 1)
{
Dir = 1
}
if(changed(Stage)){
Sc:writeCell(1048572,Size)
Sc:writeCell(1048573,Size)
H = Sc:readCell(1048572)
W = Sc:readCell(1048572)
CurFPos = randint(1,H*W)
N = In
}
if(clk()){
if(Sc:readCell(Pos+Dir) == 200)
{
Stage = 2
}
Sc:writeCell(1048574,1)
if(!Mode){
if(!(Pos%H) & Dir == -1)
{
Pos+=H
}
if(!((Pos+1)%H) & Dir == 1)
{
Pos -= H
}
Pos += Dir
if(Pos>H*W)
{
Pos -= H*W
}
elseif(Pos < 0)
{
Pos += H*W
}
}
else
{
if(!(Pos%H) & Dir == -1)
{
Stage = 2
}
if(!((Pos+1)%H) & Dir == 1)
{
Stage = 2
}
Pos += Dir
if(Pos>H*W)
{
Stage = 2
}
elseif(Pos < 0)
{
Stage = 2
}
}
if(Pos == CurFPos)
{
EatenFood++
Posn:pushNumber(LastPos)
CurFPos = randint(1,H*W)
}
else
{

Posn:pushNumber(LastPos)
Posn:shift()
}
LastPos = Pos


I = 0
while(I {
I++
Sc:writeCell(Posn[I,number],200)
}
Sc:writeCell(CurFPos,990000)
Sc:writeCell(Pos,752000)

}
}
if(clk()&Stage == 2){
if(changed(Stage)){N = 10 NDir = 1}
Sc:writeCell(Nu,900000)
if(NDir == 1){Nu++}
elseif(NDir == H){Nu+=H}
elseif(NDir == -1){Nu--}
elseif(NDir == -H){Nu-=H}
if((Sc:readCell(NDir+Nu)==900000)|(!(Nu%H) & NDir == -1)|(!((Nu+1)%H) & NDir == 1)|(Nu>(H*W)-W & NDir == H)|(Nu {
if(CL){reset()}else{CD=1}
}
CL=0
if(CD)
{
if(NDir == 1){NDir = H}
elseif(NDir == H){NDir = -1}
elseif(NDir == -1){NDir = -H}
elseif(NDir == -H){NDir = 1}
CD = 0
CL=1
}
}

C# Expression Calculator

I have usually written all my programs in C++. Now, however, I decided to try out C#. I've heard a lot of great stuff about it. The first thing I tried out, was a windows forms expression calculator. The calculator first uses the Shunting-Yard algorithm to parse the inputted expression into Reverse Polish Notation, then use several stack methods to to calculate the final result. A snippet of the source code:

  Stack<string> output = new Stack<string>();
string refr = "";
double num1 = 0;
double num2 = 0;
public Form1()
{
InitializeComponent();
}
private void outpush(string val , bool more )
{
if(!more)
{
output.Push(val+" ");
}
else
{
output.Push(val);
}
}
private void button1_Click(object sender, EventArgs e)
{
Stack<char> oper = new Stack<char>();
char[] exp = richTextBox1.Text.Replace(" ","").ToCharArray();
refr = "";
for(int i = 0; i < exp.Count(); i++)
{
if(Char.IsNumber(exp[i]))
{
if(exp.Count()-1 > i && Char.IsNumber(exp[i+1]))
{
outpush(Convert.ToString(exp[i]), true);
}
else
{
outpush(Convert.ToString(exp[i]), false);
}
}
else switch(exp[i])
{
case '+':
if(oper.Count()>0)
{
if (oper.ToArray()[0] == '*' || oper.ToArray()[0] == '/' || oper.ToArray()[0] == '^')
{
outpush(Convert.ToString(oper.Pop()), false);
}
}
oper.Push(exp[i]);
break;

case '-':
if (oper.Count() > 0)
{
if (oper.ToArray()[0] == '*' || oper.ToArray()[0] == '/' || oper.ToArray()[0] == '^')
{
outpush(Convert.ToString(oper.Pop()), false);
}
}
oper.Push(exp[i]);
break;

case '-':
if (oper.Count() > 0)
{
if (oper.ToArray()[0] == '*' || oper.ToArray()[0] == '/' || oper.ToArray()[0] == '^')
{
outpush(Convert.ToString(oper.Pop()), false);
}
}
oper.Push(exp[i]);
break;

case '*':
if (oper.Count() > 0)
{
if (oper.ToArray()[0] == '*' || oper.ToArray()[0] == '/' || oper.ToArray()[0] == '^')
{
outpush(Convert.ToString(oper.Pop()), false);
}
}
oper.Push(exp[i]);
break;

case '/':
if (oper.Count() > 0)
{
if (oper.ToArray()[0] == '*' || oper.ToArray()[0] == '/' || oper.ToArray()[0] == '^')
{
outpush(Convert.ToString(oper.Pop()), false);
}
}
oper.Push(exp[i]);
break;

case '(':
oper.Push(exp[i]);
break;

case ')':
int count2 = oper.Count();
if (oper.Count() > 0)
{
while(oper.ToArray()[0] != '(')
{
outpush(Convert.ToString(oper.Pop()), false);
}
}
if (oper.Count() == 0) { goto errorlp; }
oper.Pop();
break;

case '^':
oper.Push(exp[i]);
break;

default:
break;
}
}
int count = oper.Count();
for(int i = 0; i < count; i++)
{
outpush(Convert.ToString(oper.Pop()), false);
}
int counto = output.Count();
for(int i = 0; i < counto; i++)
{
refr = output.Pop() + refr;
}

string[] input = refr.Split(' ');

Stack<double> numbers = new Stack<double>();
for(int i = 0; i < input.Count(); i++)
{
if(input[i] != ""){
if(Char.IsNumber(input[i],0))
{
numbers.Push(Convert.ToDouble(input[i]));
}
else switch(input[i])
{
case "+":
if (numbers.Count() < 2) { goto errornum; }
num1 = numbers.Pop();
num2 = numbers.Pop();
numbers.Push(num2 + num1);
break;

case "-":
if (numbers.Count() < 2) { goto errornum; }
num1 = numbers.Pop();
num2 = numbers.Pop();
numbers.Push(num2-num1);
break;

case "-":
if (numbers.Count() < 2) { goto errornum; }
num1 = numbers.Pop();
num2 = numbers.Pop();
numbers.Push(num2-num1);
break;

case "*":
if (numbers.Count() < 2) { goto errornum; }
num1 = numbers.Pop();
num2 = numbers.Pop();
numbers.Push(num2*num1);
break;

case "/":
if (numbers.Count() < 2) { goto errornum; }
num1 = numbers.Pop();
num2 = numbers.Pop();
numbers.Push(num2/num1);
break;


case "^":
if (numbers.Count() < 2) { goto errornum; }
num1 = numbers.Pop();
num2 = numbers.Pop();
numbers.Push(Math.Pow(num2,num1));
break;
}
}
}
if (numbers.Count() != 1) { goto errornum; }
richTextBox1.Text = Convert.ToString(numbers.Pop());

goto Ends;

errorlp:
richTextBox1.Text = "Error!\nMissing left parenthesis!";
goto Ends;

Errorrp:
richTextBox1.Text = "Error!\nMissing right parenthesis!";
goto Ends;

errornum:
richTextBox1.Text = "Error!\nNumber count does not equal operator count!";

Ends:
num1 = 0;



And here's an image of the calculator interface: