Opinion regarding included code

  • Thread starter Thread starter woven
  • Start date Start date
  • Tags Tags
    Code
AI Thread Summary
The discussion revolves around a code implementation that utilizes addition and subtraction in base 256 to manipulate a symbolic system through graphical representation. The code includes a Processing sketch and a C# WPF application, both defining an `Ordinate` class for managing color magnitudes and rendering graphics. Users are encouraged to modify the code for enhanced interaction, suggesting the addition of gesture or mouse controls for improved user experience. The simplicity of the implementation is highlighted, emphasizing its potential for complex visual outputs. Overall, the conversation invites further exploration and adaptation of the provided code for various applications.
woven
Messages
1
Reaction score
0
Seeking opinion regarding included code.

//Processing - Processing.org
Code:
int _size = 256;
int _mx, _my;
Ordinate _x, _y, _one;

void setup()
{
  size(this._size, this._size, P2D);
  _x = new Ordinate(this._size);
  _y = new Ordinate(this._size);
  _one = Ordinate.One(this._size);
}

void draw()
{
  Ordinate o = Ordinate.Add(_x, _y);  
  for(int a = 0, x = 0, y = 0; a < o._magnitude.length; a += 3)
  {
    int col = 255 << 24 | o._magnitude[a] << 16 | o._magnitude[a + 1] << 8 | o._magnitude[a + 2];
    
    stroke(col);
    point(x, y);
    x = x + 1 == _size ? 0 : x + 1;
    y = x == 0 ? y + 1 : y;
  }
}

void keyPressed()
{
  if(key == 'w')
  {
    _x = Ordinate.Add(_x, _one);
  }
  else if(key == 's')
  {
     _x = Ordinate.Sub(_x, _one);
  }
  else if(key == 'a')
  {
     _y = Ordinate.Add(_y, _one);
  }
  else if(key == 'd')
  {
     _y = Ordinate.Sub(_y, _one);
  }
}

void mousePressed()
{
  _mx = mouseX;
  _my = mouseY;
}

void mouseReleased()
{
  int dx = mouseX;
  int dy = mouseY;
  int dragLength = (_mx - dx) * (_mx - dx) + (_my - dy) * (_my - dy);  
}

static class Ordinate
{
  public int _size;
  public byte[] _magnitude;
  
  private Ordinate()
  {
    this._size = 0;
    this._magnitude = null;
  }
  
  public Ordinate(int Size)
  {
    this._size = Size;
    this._magnitude = new byte[this._size * this._size * 3];
  }
  
  public static Ordinate One(int Size) { 
    Ordinate o = new Ordinate(Size); 
    o._magnitude[o._magnitude.length - 1] = 1; 
    return o;
  }

  public static Ordinate Add(Ordinate Ord1, Ordinate Ord2)
  {
    Ordinate o = new Ordinate(Ord1._size);
    for (int a = Ord1._magnitude.length - 1, carry = 0; a > -1; a--)
    {
      int v = Ord1._magnitude[a] + Ord2._magnitude[a] + carry;
      carry = v / 256;
      o._magnitude[a] = (byte)(v - carry * 256);
    }
    return o;
  }

  public static Ordinate Sub(Ordinate Ord1, Ordinate Ord2)
  {
    Ordinate o = new Ordinate(Ord1._size);
    for (int a = Ord1._magnitude.length - 1, borrow = 0; a > -1; a--)
    {
      if (Ord1._magnitude[a] >= (Ord2._magnitude[a] + borrow))
      {
        o._magnitude[a] = (byte)(Ord1._magnitude[a] - Ord2._magnitude[a] - borrow);
        borrow = 0;
      }
      else
      {
        o._magnitude[a] = (byte)((Ord1._magnitude[a] + 256) - Ord2._magnitude[a] - borrow);
        borrow = 1;
      }
    }
    return o;
  }
}

//c# wpf
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Ordinate
{
    public partial class MainWindow : Window
    {
        Ord _x, _y;

        internal class Ord
        {
            private int _size;
            private byte[] _magnitude;
            public byte[] Magnitude { get { return _magnitude; } set { _magnitude = value; } }

            public static Ord One(int Size) { Ord o = new Ord(Size); o._magnitude[o._magnitude.Length - 1] = 1; return o; }

            public Ord(int Size)
            {
                this._size = Size;
                this._magnitude = new byte[this._size * this._size * 3];
            }

            public static Ord operator +(Ord Ord1, Ord Ord2)
            {
                if (Ord1._magnitude.Length != Ord2._magnitude.Length)
                    throw new ArgumentException("Operands must have equal dimensions");

                Ord o = new Ord(Ord1._size);

                for (int a = Ord1._magnitude.Length - 1, carry = 0; a > -1; a--)
                {
                    int v = Ord1._magnitude[a] + Ord2._magnitude[a] + carry;
                    carry = v / 256;
                    o._magnitude[a] = (byte)(v - carry * 256);
                }

                return o;
            }

            public static Ord operator -(Ord Ord1, Ord Ord2)
            {
                if (Ord1._magnitude.Length != Ord2._magnitude.Length)
                    throw new ArgumentException("Operands must have equal dimensions");

                Ord o = new Ord(Ord1._size);

                for (int a = Ord1._magnitude.Length - 1, borrow = 0; a > -1; a--)
                {
                    if (Ord1._magnitude[a] >= (Ord2._magnitude[a] + borrow))
                    {
                        o._magnitude[a] = (byte)(Ord1._magnitude[a] - Ord2._magnitude[a] - borrow);
                        borrow = 0;
                    }
                    else
                    {
                        o._magnitude[a] = (byte)((Ord1._magnitude[a] + 256) - Ord2._magnitude[a] - borrow);
                        borrow = 1;
                    }
                }

                return o;
            }

            internal static BitmapSource Render(Ord Ord1, Ord Ord2)
            {
                if (Ord1._magnitude.Length != Ord2._magnitude.Length)
                    throw new ArgumentException("Operands must have equal dimensions");

                WriteableBitmap buffer = new WriteableBitmap(Ord1._size, Ord1._size, 96, 96, PixelFormats.Rgb24, null);
                buffer.Lock();
                buffer.WritePixels(new Int32Rect(0, 0, Ord1._size, Ord1._size), (Ord1 - Ord2)._magnitude, Ord1._size * 3, 0);
                buffer.Unlock();
                return buffer;
            }
        }

        public MainWindow()
        {
            InitializeComponent();
        }        

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            _x = new Ord(256);
            _y = new Ord(256);
            renderBuffer.BeginInit();
            renderBuffer.Source = Ord.Render(_x, _y);
            renderBuffer.EndInit();
        }
    }
}

It seems fairly evident that as we created the system of symbolism we should be able to manipulate it at will and yet it seems a subject little spoken of. This code is simply using addition and subtraction within the base 256, a very basic implementation yet able to convey so much.

EDIT: I leave it to you to rework the code to suit whatever form of interaction you see fit, i have implemented a simple keypress system within the processing code, the extension of which should be easy for most. One might incorporate a system of gestures or mouse interaction to enable speedy transitions.
 
Last edited:
Mathematics news on Phys.org


what is your question?
 
Suppose ,instead of the usual x,y coordinate system with an I basis vector along the x -axis and a corresponding j basis vector along the y-axis we instead have a different pair of basis vectors ,call them e and f along their respective axes. I have seen that this is an important subject in maths My question is what physical applications does such a model apply to? I am asking here because I have devoted quite a lot of time in the past to understanding convectors and the dual...
Insights auto threads is broken atm, so I'm manually creating these for new Insight articles. In Dirac’s Principles of Quantum Mechanics published in 1930 he introduced a “convenient notation” he referred to as a “delta function” which he treated as a continuum analog to the discrete Kronecker delta. The Kronecker delta is simply the indexed components of the identity operator in matrix algebra Source: https://www.physicsforums.com/insights/what-exactly-is-diracs-delta-function/ by...

Similar threads

Replies
5
Views
3K
Replies
7
Views
3K
Replies
0
Views
367
Replies
1
Views
2K
Replies
1
Views
2K
Replies
7
Views
2K
Replies
1
Views
1K
Back
Top