-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6be2b11
commit fd32680
Showing
9 changed files
with
320 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.28307.136 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RainCode", "RainCode\RainCode.csproj", "{E18E1932-C952-40BA-ACA7-0E0991710FE0}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{E18E1932-C952-40BA-ACA7-0E0991710FE0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{E18E1932-C952-40BA-ACA7-0E0991710FE0}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{E18E1932-C952-40BA-ACA7-0E0991710FE0}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{E18E1932-C952-40BA-ACA7-0E0991710FE0}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {36C74114-8B84-46FF-AAD5-CFBD0DE6F0F9} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> | ||
</startup> | ||
</configuration> |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Drawing; | ||
|
||
namespace RainCode | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
Program p = new Program(); | ||
p.Run(); | ||
Console.ReadKey(); | ||
} | ||
|
||
public void Reset() | ||
{ | ||
rpxs = 1; | ||
dpxs = 1; | ||
rxpos = 0; | ||
rypos = 0; | ||
dxpos = 0; | ||
dypos = 0; | ||
} | ||
|
||
public void Run() | ||
{ | ||
while (true) | ||
{ | ||
Reset(); | ||
Console.Title = "RainCode v1.0"; | ||
Console.WriteLine(@"__________ .__ _________ .___ "); | ||
Console.WriteLine(@"\______ _____ |__| ____ \_ ___ \ ____ __| _/____ "); | ||
Console.WriteLine(@" | _\__ \ | |/ \/ \ \/ / _ \ / __ _/ __ \ "); | ||
Console.WriteLine(@" | | \/ __ \| | | \ \___( <_> / /_/ \ ___/ "); | ||
Console.WriteLine(@" |____|_ (____ |__|___| /\______ /\____/\____ |\___ >"); | ||
Console.WriteLine(@" \/ \/ \/ \/ \/ \/ "); | ||
Console.WriteLine(" R a i n C o d e v 1 . 0 "); | ||
Console.WriteLine("===========================================================\n\n"); | ||
Console.WriteLine("Press 'M' to make raincode"); | ||
Console.WriteLine("Press 'R' to read raincode"); | ||
|
||
var Input = Console.ReadKey(); | ||
if (Input.Key == ConsoleKey.M) | ||
{ | ||
Console.Clear(); | ||
Console.WriteLine("Enter input file's path: "); | ||
string InputPath = Console.ReadLine(); | ||
Console.WriteLine("Enter destination path: "); | ||
string DestinationPath = Console.ReadLine(); | ||
try | ||
{ | ||
WriteImage(InputPath, DestinationPath); | ||
} | ||
catch (Exception ex) { Console.WriteLine("ERROR: " + ex.Message); } | ||
} | ||
if (Input.Key == ConsoleKey.R) | ||
{ | ||
Console.Clear(); | ||
Console.WriteLine("Enter input file's path: "); | ||
string InputPath = Console.ReadLine(); | ||
Console.WriteLine("Enter destination path: "); | ||
string DestinationPath = Console.ReadLine(); | ||
try | ||
{ | ||
byte[] Data = ReadImage(InputPath); | ||
System.IO.File.WriteAllBytes(DestinationPath, Data); | ||
Console.WriteLine("Done."); | ||
} | ||
catch (Exception ex) { Console.WriteLine("ERROR: " + ex.Message); } | ||
} | ||
Console.Clear(); | ||
} | ||
} | ||
|
||
public static void WriteImage(string DataPath, string DestImagePath) | ||
{ | ||
int[] Lookup = { 1, 2, 4, 8, 16, 32, 64, 128 }; | ||
string[] DataColors = new string[] { "#FF0000", "#FF6600", "#FFCC00", "#CCFF00", "#00FF00", "#00FFCC", "#0000FF", "#CC00FF" }; | ||
string[] PaddingColors = { "#FF0066", "#000000" }; | ||
byte[] Array = System.IO.File.ReadAllBytes(DataPath); | ||
List<Color> ColorList = new List<Color>(); | ||
|
||
foreach (var Char in Array) | ||
{ | ||
char[] CharList = Convert.ToString(System.Convert.ToInt32(Char), 2).PadLeft(8, '0').ToArray(); | ||
for (int i = 0; i < CharList.Length; i++) | ||
{ | ||
if (CharList[i] == '1') | ||
ColorList.Add((Color)new ColorConverter().ConvertFromString(DataColors.Reverse().ToArray()[i].ToUpper())); | ||
} | ||
ColorList.Add((Color)new ColorConverter().ConvertFromString(PaddingColors[0].ToUpper())); | ||
} | ||
ColorList.Add((Color)new ColorConverter().ConvertFromString(PaddingColors[1].ToUpper())); | ||
|
||
Image AltImage = new Bitmap((int)Math.Ceiling(Math.Sqrt(ColorList.Count)), (int)Math.Ceiling(Math.Sqrt(ColorList.Count))); | ||
Graphics graphics = Graphics.FromImage(AltImage); | ||
graphics.FillRectangle(new SolidBrush((Color)new ColorConverter().ConvertFromString(PaddingColors[0])), 0, 0, AltImage.Width, AltImage.Height); | ||
for (int i = 0; i < ColorList.Count; i++) | ||
{ | ||
Draw(new SolidBrush(ColorList[i]), ref graphics, AltImage.Size); | ||
} | ||
|
||
AltImage.Save(DestImagePath); | ||
} | ||
|
||
|
||
|
||
public static byte[] ReadImage(string ImagePath) | ||
{ | ||
Image Image = Image.FromFile(ImagePath); | ||
Bitmap b = new Bitmap(Image); | ||
int[] Lookup = { 1, 2, 4, 8, 16, 32, 64, 128 }; | ||
string[] DataColors = new string[] { "#FF0000", "#FF6600", "#FFCC00", "#CCFF00", "#00FF00", "#00FFCC", "#0000FF", "#CC00FF" }; | ||
string[] PaddingColors = { "#FF0066", "#000000" }; | ||
|
||
List<byte> Data = new List<byte>(); | ||
int Value = 0; | ||
|
||
for (int x = 0; x < (Image.Width * Image.Height) / rpxs; x++) | ||
{ | ||
string PixelData = Read(ref b, b.Size); | ||
if (PixelData != "#FFFFFF" && !string.IsNullOrWhiteSpace(PixelData)) | ||
{ | ||
if (!PaddingColors.Contains(PixelData)) | ||
{ | ||
Value += Lookup[DataColors.ToList().IndexOf(PixelData)]; | ||
} | ||
else | ||
{ | ||
Data.Add((byte)Value); | ||
Value = 0; | ||
} | ||
} | ||
} | ||
return Data.ToArray(); | ||
} | ||
|
||
public static int rpxs = 1; | ||
public static int rxpos = 0; | ||
public static int rypos = 0; | ||
|
||
public static string Read(ref Bitmap Bitmap, Size ImageSize) | ||
{ | ||
string Hex = ""; | ||
if (rypos != ImageSize.Height && rxpos != ImageSize.Width) | ||
{ | ||
Color cc = Bitmap.GetPixel(rxpos, rypos); | ||
Hex = HexConverter(cc); | ||
|
||
rxpos += rpxs; | ||
|
||
return Hex; | ||
} | ||
|
||
if (rxpos + (rpxs) > ImageSize.Width) | ||
{ | ||
rxpos = 0; | ||
rypos = rypos + rpxs; | ||
} | ||
|
||
return Hex; | ||
|
||
} | ||
public static int dpxs = 1; | ||
public static int dxpos = 0; | ||
public static int dypos = 0; | ||
public static Color LastDrawnColor = Color.FromArgb(0, 0, 0, 0); | ||
|
||
public static void Draw(SolidBrush Color, ref Graphics graphics, Size ImageSize) | ||
{ | ||
|
||
if (dxpos + (dpxs) > ImageSize.Width) | ||
{ | ||
dxpos = 0; | ||
dypos = dypos + dpxs; | ||
} | ||
if (Color.Color != LastDrawnColor || LastDrawnColor != System.Drawing.Color.FromArgb(0, 0, 0, 0)) | ||
graphics.FillRectangle(Color, new Rectangle(new Point(dxpos, dypos), new Size(dpxs, dpxs))); | ||
|
||
dxpos += dpxs; | ||
LastDrawnColor = Color.Color; | ||
} | ||
|
||
private static string HexConverter(System.Drawing.Color c) | ||
{ | ||
return "#" + c.R.ToString("X2") + c.G.ToString("X2") + c.B.ToString("X2"); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("RainCode")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("RainCode")] | ||
[assembly: AssemblyCopyright("Copyright © 2018")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("e18e1932-c952-40ba-aca7-0e0991710fe0")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{E18E1932-C952-40BA-ACA7-0E0991710FE0}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<RootNamespace>RainCode</RootNamespace> | ||
<AssemblyName>RainCode</AssemblyName> | ||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<Deterministic>true</Deterministic> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<ApplicationIcon>RainCode.ico</ApplicationIcon> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Drawing" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Content Include="RainCode.ico" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
Binary file not shown.