Skip to content

Commit

Permalink
heat map
Browse files Browse the repository at this point in the history
  • Loading branch information
8bithunter committed Jun 1, 2024
1 parent b956fda commit e6a3440
Show file tree
Hide file tree
Showing 10 changed files with 350 additions and 33 deletions.
1 change: 1 addition & 0 deletions Assembly-CSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<Analyzer Include="D:\2022.3.15f1\Editor\Data\Tools\Unity.SourceGenerators\Unity.Properties.SourceGenerator.dll" />
</ItemGroup>
<ItemGroup>
<Compile Include="Assets\Scripts\HeatMap.cs" />
<Compile Include="Assets\Scripts\Setter.cs" />
<Compile Include="Assets\Scripts\CursorFollow.cs" />
<Compile Include="Assets\Scripts\Funcs.cs" />
Expand Down
19 changes: 18 additions & 1 deletion Assets/Scenes/SampleScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -2991,6 +2991,7 @@ GameObject:
- component: {fileID: 1107804551}
- component: {fileID: 1107804552}
- component: {fileID: 1107804553}
- component: {fileID: 1107804554}
m_Layer: 0
m_Name: Code
m_TagString: Untagged
Expand Down Expand Up @@ -3123,6 +3124,22 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
starti: {fileID: 1217521755}
--- !u!114 &1107804554
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1107804547}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0d6573d12e8341b4a9ee00de5ca78290, type: 3}
m_Name:
m_EditorClassIdentifier:
doHeatMap: 1
squareSprite: {fileID: 7482667652216324306, guid: 38e6c4fbce2370248a09c380fba96b1f, type: 3}
opacity: 0.3
squareSize: 0.1
--- !u!1 &1217521754
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -3616,7 +3633,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0, g: 0, b: 0.21176471, a: 1}
m_Color: {r: 0, g: 0.21176471, b: 0.03984624, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Funcs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static Complex function(Complex unscaledz)
{
Complex z = unscaledz * Scaler.scale;

Complex output = Complex.Pow(z, 2);
Complex output = Complex.Sin(z);

return (output / Scaler.scale);
}
Expand Down
88 changes: 88 additions & 0 deletions Assets/Scripts/HeatMap.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Numerics;
using Vector3 = UnityEngine.Vector3;
using System;
using Unity.VisualScripting;

public class HeatMap : MonoBehaviour
{
public bool doHeatMap = true;

public Sprite squareSprite;
public float opacity = 0.3f;
public float squareSize = 1f;
private int screenLength = 9;
private int screenHeight = 5;

double lowReal = double.MaxValue;
double HighReal = double.MinValue;
double lowImag = double.MaxValue;
double HighImag = double.MinValue;
double HighMag = double.MinValue;

void Start()
{
CreateHeatMap();
}
public void CreateHeatMap()
{
if (doHeatMap)
{
for (int x = -(int)Math.Round(screenLength / squareSize); x <= (int)Math.Round(screenLength / squareSize); x++)
{
for (int y = -(int)Math.Round(screenHeight / squareSize); y <= (int)Math.Round(screenHeight / squareSize); y++)
{
GameObject spriteObject = new GameObject("Tile_" + x + "_" + y);

SpriteRenderer spriteRenderer = spriteObject.AddComponent<SpriteRenderer>();

spriteRenderer.sprite = squareSprite;

Vector3 position = new Vector3(x * squareSize, y * squareSize, 0);

spriteObject.transform.position = position;

spriteObject.transform.localScale = new Vector3(squareSize, squareSize, 1f);

Complex functionOutput = Funcs.function(new Complex(x, y));

//if (x > -4 / squareSize && x < 4 / squareSize && y > -4 / squareSize && y < 4 / squareSize)

if (functionOutput.Real < lowReal) lowReal = functionOutput.Real;
if (functionOutput.Real > HighReal) HighReal = functionOutput.Real;
if (functionOutput.Imaginary < lowImag) lowImag = functionOutput.Imaginary;
if (functionOutput.Imaginary > HighImag) HighImag = functionOutput.Imaginary;
if (Complex.Abs(functionOutput) > HighMag) HighMag = Complex.Abs(functionOutput);

Complex value = functionOutput;

Color color = ComplexToColor(value);

spriteRenderer.color = color;
}
}
}
}
Color ComplexToColor(Complex value)
{
float magnitude = (float) Complex.Abs(value);

float preLerpOpacity = Mathf.InverseLerp(0, (float)HighMag, magnitude);
//opacity = Mathf.Lerp(0f, 0.2f, preLerpOpacity);

float normalizedReal = Mathf.InverseLerp((float)lowReal, (float)HighReal, (float)value.Real);
if (value.Real > HighReal) normalizedReal = 1;
if (value.Real < lowReal) normalizedReal = 0;
float normalizedImaginary = Mathf.InverseLerp((float)lowImag, (float)HighImag, (float)value.Imaginary);
if (value.Imaginary > HighImag) normalizedImaginary = 1;
if (value.Imaginary < lowImag) normalizedImaginary = 0;

float red = Mathf.Lerp(0f, 1f, normalizedReal);
float green = 0;
float blue = Mathf.Lerp(0f, 1f, normalizedImaginary);

return new Color(red, green, blue, opacity);
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/HeatMap.cs.meta

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

6 changes: 6 additions & 0 deletions Assets/Scripts/Scaler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ public class Scaler : MonoBehaviour
private float orginalscale1;
private float orginalscale2;

private HeatMap heatmap;

void Start()
{
orginalscale1 = Unitcircle1.localScale.x;
orginalscale2 = Unitcircle2.localScale.x;

heatmap = GetComponent<HeatMap>();
}

void Update()
Expand All @@ -29,10 +33,12 @@ void Update()
if ((Input.GetKeyDown(KeyCode.Equals) && (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))))
{
BoundedScale(scale * 0.5);
heatmap.CreateHeatMap();
}
else if ((Input.GetKeyDown(KeyCode.Minus) && (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))))
{
BoundedScale(scale * 2);
heatmap.CreateHeatMap();
}

Unitcircle2.localScale = new Vector3(orginalscale2 / (float)scale + (float)(orginalscale2 - orginalscale1 + 11), orginalscale2 / (float)scale + (float)(orginalscale2 - orginalscale1 + 11), orginalscale2 / (float)scale + (float)(orginalscale1 - orginalscale2 + 11));
Expand Down
Binary file added Assets/Sprites/HeatSquare.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
195 changes: 195 additions & 0 deletions Assets/Sprites/HeatSquare.png.meta

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

1 change: 0 additions & 1 deletion Logs/shadercompiler-UnityShaderCompiler.exe0.log
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Base path: 'D:/2022.3.15f1/Editor/Data', plugins path 'D:/2022.3.15f1/Editor/Data/PlaybackEngines'
Cmd: initializeCompiler

Cmd: shutdown
Loading

0 comments on commit e6a3440

Please sign in to comment.