Skip to content

Commit

Permalink
Add ouchi color
Browse files Browse the repository at this point in the history
  • Loading branch information
syKevinPeng committed Apr 30, 2024
1 parent d72c14e commit 6d44d73
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 13 deletions.
5 changes: 3 additions & 2 deletions Assets/Scripts/IllusionCanvasController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ public class IllusionCanvasController : MonoBehaviour
private GameObject Slider;
private GameObject UpButton;
private GameObject DownButton;
public float stepSize = 0.1f;

// Start is called before the first frame update
void GetIncreaseButtonPressed()
{
if (OVRInput.Get(OVRInput.Button.Two, RController))
{
// increase the ratio of the pattern. Call IncreasePatternRatio() in ouchi.cs
RawImage.GetComponent<IllusionPatternLoader>().IncreasePatternRatio(0.1f);
RawImage.GetComponent<IllusionPatternLoader>().IncreasePatternRatio(stepSize);
UpButton.GetComponent<UnityEngine.UI.Button>().image.sprite = Resources.Load<Sprite>("Image/uparrow_blue");
AdjustSliderWithValue(GetCurrentRatio());

Expand All @@ -38,7 +39,7 @@ void GetDecreaseButtonPressed()
if (OVRInput.Get(OVRInput.Button.One, RController))
{
// decrease the ratio of the pattern. Call DecreasePatternRatio() in ouchi.cs
RawImage.GetComponent<IllusionPatternLoader>().DecreasePatternRatio(0.1f);
RawImage.GetComponent<IllusionPatternLoader>().DecreasePatternRatio(stepSize);
DownButton.GetComponent<UnityEngine.UI.Button>().image.sprite = Resources.Load<Sprite>("Image/downarrow_blue");
AdjustSliderWithValue(GetCurrentRatio());

Expand Down
8 changes: 5 additions & 3 deletions Assets/Scripts/IllusionPatternLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ void Start()
{
RawImage = GameObject.Find("RawImage");

abstractIllusionPattern ouchi = new ouchi();
abstractIllusionPattern ouchiLength = new ouchiLength();
abstractIllusionPattern ouchiColor = new ouchiColor();

allPatterns.Add(ouchi);
allPatterns.Add(ouchiLength);
allPatterns.Add(ouchiColor);

currentPattern = ouchi;
currentPattern = ouchiColor;
}

public void IncreasePatternRatio(float ratio)
Expand Down
8 changes: 8 additions & 0 deletions Assets/Scripts/illusions.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 additions & 0 deletions Assets/Scripts/illusions/ouchiColor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@

using System;
using UnityEngine;

public class ouchiColor : ouchiLength
{
private int foregroundColor = 1;
private int backgroundColor = 255;

public ouchiColor()
{
Debug.Log("========== Ouchi Color Start ==========");
texture = GeneratePattern();
}

public override Texture2D GeneratePattern()
{
Color fgColor = new Color(foregroundColor, foregroundColor, foregroundColor);
Color bgColor = new Color(backgroundColor, backgroundColor, backgroundColor);
texture = new Texture2D(width, height);
// define the background pattern
for (int h = 0; h < height; h++)
for (int w = 0; w < width; w++)
{
texture.SetPixel(w, h, (w / InitPatternWidth % 2 == h / InitPatternHeight % 2) ? fgColor : bgColor);
}
// define the center circular pattern
int centerX = width / 2;
int centerY = height / 2;
for (int h = 0; h < height; h++)
for (int w = 0; w < width; w++)
{
if (Mathf.Pow(w - centerX, 2) + Mathf.Pow(h - centerY, 2) < Mathf.Pow(radius, 2))
{
// texture.SetPixel(w, h, Color.red);
texture.SetPixel(h, w, ((w / InitPatternWidth) % 2 == (h / InitPatternHeight) % 2) ? fgColor : bgColor);
}
}

texture.filterMode = FilterMode.Point;
texture.Apply();
return texture;
}

public override float GetCurrentRatio()
{
return (float)backgroundColor / foregroundColor;
}

public override float GetInitRatio()
{
return 255.0f;
}

public override void IncreasePatternRatio(float step)
{
if (foregroundColor + step <= 255)
{
foregroundColor += (int)step;
backgroundColor -= (int)step;
}
texture = GeneratePattern();
}

public override void DecreasePatternRatio(float step)
{
if (backgroundColor - step >= 0)
{
backgroundColor += (int)step;
foregroundColor -= (int)step;
}
texture = GeneratePattern();
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/illusions/ouchiColor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
using UnityEngine;
using UnityEngine.UIElements;

public class ouchi : abstractIllusionPattern
public class ouchiLength : abstractIllusionPattern
{
// Start is called before the first frame update
private int width = 512;
private int height = 512;
private int InitPatternHeight = 8;
private int InitPatternWidth = 32;
private int radius = 150;
public int width = 512;
public int height = 512;
public int InitPatternHeight = 8;
public int InitPatternWidth = 32;
public int radius = 150;
private int CurrentPatternHeight;
private int CurrentPatternWidth;

//constructor
public ouchi()
public ouchiLength()
{
Debug.Log("========== Ouchi Start ==========");
texture = GeneratePattern(InitPatternHeight, InitPatternWidth);
Expand Down Expand Up @@ -81,7 +81,6 @@ public Texture2D GeneratePattern(int PatternHeight, int PatternWidth)

texture.filterMode = FilterMode.Point;
texture.Apply();
// RawImage.GetComponent<UnityEngine.UI.RawImage>().texture = texture;
return texture;

}
Expand Down
File renamed without changes.

0 comments on commit 6d44d73

Please sign in to comment.