Opinion regarding included code

  • Thread starter woven
  • Start date
  • Tags
    Code
In summary, the conversation is seeking opinions on the included code from two different programming languages, Processing and C# WPF. The code manipulates a system of symbolism using addition and subtraction within the base 256. The conversation also mentions the possibility of incorporating different forms of interaction, such as gestures or mouse input.
  • #1
woven
1
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
  • #2


what is your question?
 

1. What is the purpose of including code in an opinion?

The purpose of including code in an opinion is to provide evidence or support for the argument being made. It can also help to clarify complex concepts or demonstrate a specific technique or method.

2. How should code be formatted when included in an opinion?

Code should be formatted in a clear and organized manner, using proper indentation, comments, and syntax highlighting if available. It should also be accompanied by an explanation or description of the code's purpose.

3. Is it necessary to include code in an opinion?

No, it is not always necessary to include code in an opinion. It should only be included if it adds value and enhances the argument being made. In some cases, a written explanation or diagram may be more effective in conveying the information.

4. Can code be copyrighted when included in an opinion?

Yes, code can be copyrighted when included in an opinion. It is important to properly cite and give credit to the original source of the code, and to follow any license restrictions that may apply.

5. Are there any potential drawbacks to including code in an opinion?

One potential drawback to including code in an opinion is that it may be difficult for non-technical readers to understand. It is important to provide clear explanations and avoid overly complex or technical code when possible. Additionally, if the code is not properly cited or used without permission, it can lead to copyright infringement issues.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
938
  • Programming and Computer Science
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Programming and Computer Science
Replies
30
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
994
  • Programming and Computer Science
Replies
7
Views
2K
  • Programming and Computer Science
Replies
23
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
18
Views
1K
Back
Top