Menu
Home
Create new Paste
Log in
Code
Theme: cobalt
Theme: eclipse
Theme: elegant
Theme: monokai
Theme: neat
Theme: night
Theme: rubyblue
import std.stdio; static if (!is(typeof(writeln))) alias writefln writeln; struct Color { public: static const Color Black = Color(0, 0, 0); static const Color White = Color(255, 255, 255); static const Color Red = Color(255, 0, 0); static const Color Green = Color(0, 255, 0); static const Color Blue = Color(0, 0, 255); static const Color Yellow = Color(0, 255, 255); static const Color Magenta = Color(255, 0, 255); static const Color Gray = Color(0.7, 0.7, 0.7); enum Colors : Color { Black = Color(0, 0, 0) } //etc. /*static this() { Black = Color(0, 0, 0); White = Color(255, 255, 255); Red = Color(255, 0, 0); Green = Color(0, 255, 0); Blue = Color(0, 0, 255); Yellow = Color(0, 255, 255); Magenta = Color(255, 0, 255); Gray = Color(0.7, 0.7, 0.7); }*/ public: ubyte red, green, blue, alpha; this(ubyte red, ubyte green, ubyte blue, ubyte alpha = 0) { this.red = red; this.green = green; this.blue = blue; this.alpha = alpha; } this(float red, float green, float blue, float alpha = 0.0) { this.red = cast(ubyte)(ubyte.max * red); this.green = cast(ubyte)(ubyte.max * green); this.blue = cast(ubyte)(ubyte.max * blue); this.alpha = cast(ubyte)(ubyte.max * alpha); } ~this() { writeln("DTor"); } bool opEquals(ref const Color col) const pure nothrow { return this.red == col.red && this.green == col.green && this.blue == col.blue && this.alpha == col.alpha; } // TODO: opHash? float[4] convertGL() const pure nothrow { return [this.red / 255.0, this.green / 255.0, this.blue / 255.0, this.alpha / 255.0]; } } void main() { Color(); writeln("Hello world!"); }
Result:
Success
/
Return code: 0
/
Compilation time:
0.317
seconds
/
Run time:
0.001
seconds
Disassembly
Application output:
DTor
Hello world!
Username
Message
Add comment
Paste info
Author:
Guest
Views:
78
Private:
no
Expires:
Never
Uploaded:
08.12.12 14:08
Parent:
#2792b974
Votes
:
0
Tweet
Compilation
Compiler:
DMD 2.x Gi
Pointer size:
m64
Actions
Download
Fork
Raw
×
Confirm
Are you sure you want to delete this paste?
There's no way back!
×
Confirm
Reason