Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System.IO.Ports;
- using System.Threading;
- public class TriangleColours : MonoBehaviour
- {
- public static SerialPort sp = new SerialPort("COM7", 9600);
- public SpriteRenderer[] Panels;
- private Color32[] colours = { new Color32(255, 0, 0, 255), new Color32(50, 0, 0, 255) };
- public int BaseColour;
- public int FirstColour;
- public float FirstRed;
- public float SecondRed;
- public float FirstGreen;
- public float SecondGreen;
- public float FirstBlue;
- public float SecondBlue;
- public float RedDifference;
- public float GreenDifference;
- public float BlueDifference;
- public float steps;
- public float CurrentRed;
- public float waitTime;
- public float timer;
- public int DoOnce;
- public int Setup;
- public float ASBR; //AddSubtractByRed
- void Start()
- {
- OpenConnection();
- }
- void Update()
- {
- //Debug.Log(DoOnce);
- if (DoOnce == 0)
- {
- if (Setup == 0)
- {
- timer = 100;
- steps = 1000;
- BaseColour = Random.Range(0, 1);
- FirstColour = Random.Range(0, 2);
- while (FirstColour == BaseColour)
- {
- FirstColour = Random.Range(0, 2);
- }
- Debug.Log(BaseColour);
- Debug.Log(FirstColour);
- for (int i = 0; i < 9; i++)
- {
- Panels[i].color = colours[BaseColour];
- }
- FirstRed = (float)colours[BaseColour].r;
- SecondRed = (float)colours[FirstColour].r;
- FirstGreen = (float)colours[BaseColour].g;
- SecondGreen = (float)colours[FirstColour].g;
- FirstBlue = (float)colours[BaseColour].b;
- SecondBlue = (float)colours[FirstColour].b;
- RedDifference = FirstRed - SecondRed;
- GreenDifference = FirstGreen - SecondGreen;
- BlueDifference = FirstBlue - SecondBlue;
- CurrentRed = FirstRed;
- ASBR = (RedDifference / steps);
- Debug.Log(CurrentRed);
- Debug.Log(SecondRed);
- Debug.Log(ASBR);
- Setup = 1;
- }
- //Debug.Log(timer);
- timer++;
- if (timer % 100 == 0)
- {
- //Debug.Log("Ran");
- while (CurrentRed != SecondRed)
- {
- CurrentRed = CurrentRed - (ASBR);
- Debug.Log(CurrentRed);
- //for (int i = 0; i < 9; i++)
- //{
- // Panels[i].color = new Color32((byte)CurrentRed, 0, 0, 255);
- // //Debug.Log(CurrentRed);
- //}
- }
- }
- //DoOnce = 1;
- }
- }
- public void OpenConnection()
- {
- if(sp != null)
- {
- if(sp.IsOpen)
- {
- sp.Close();
- Debug.Log("Closing, As It Was Already Open");
- }
- else
- {
- sp.Open();
- Debug.Log("Port Has Been Opened");
- }
- }
- else
- {
- if(sp.IsOpen)
- {
- Debug.Log("Port Is Already Open");
- }
- else
- {
- Debug.Log("Port == null");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement