public override void ClearToColor(color c) { Size2I size = Graphics.DeviceContext.SizeInPixels; Graphics.UseDefaultBrush(); Graphics.SetDefaultBrushColor(GetColorref(c)); Graphics.DeviceContext.Rectangle(0, 0, size.width, size.height); }
void setGradient(int x, int y, float w, float h, color c1, color c2, int axis) { float deltaR = red(c2) - red(c1); float deltaG = green(c2) - green(c1); float deltaB = blue(c2) - blue(c1); // choose axis if (axis == Y_AXIS) { for (int i = x; i <= (x + w); i++) { // row for (int j = y; j <= (y + h); j++) { color c = color((int)(red(c1) + (j - y) * (deltaR / h)), (int)(green(c1) + (j - y) * (deltaG / h)), (int)(blue(c1) + (j - y) * (deltaB / h))); set(i, j, c); } } } else if (axis == X_AXIS) { // column for (int i = y; i <= (y + h); i++) { // row for (int j = x; j <= (x + w); j++) { color c = color((int)(red(c1) + (j - x) * (deltaR / h)), (int)(green(c1) + (j - x) * (deltaG / h)), (int)(blue(c1) + (j - x) * (deltaB / h))); set(j, i, c); } } } }
// blue public float blue(color c) { return c.blue; }
// blendColor public color blendColor(color c1, color c2, BLENDMODE mode) { return new color(c1.red, c1.green, c1.blue); }
// alpha public float alpha(color c) { return c.alpha; }
public void stroke(color c) { byte red = (byte)Math.Round(lerp(0, 255, norm(c.red, 0, fColorRange.r))); byte green = (byte)Math.Round(lerp(0, 255, norm(c.green, 0, fColorRange.g))); byte blue = (byte)Math.Round(lerp(0, 255, norm(c.blue, 0, fColorRange.b))); byte alpha = (byte)Math.Round(lerp(0, 255, norm(c.alpha, 0, fColorRange.a))); color newColor = new color(red, green, blue, alpha); // Clamp the color to the color range strokeColor = newColor; useStroke = true; ResetPen(); }
public override void SetPixel(float x, float y, color c) { Graphics.BeginDraw(); Graphics.DrawLine(new Point2F(x, y), new Point2F(x, y), fStrokeBrush, strokeWidth); Graphics.EndDraw(); }
// image // imageMode // loadImage // noTint // requestImage // tint #endregion Loading & Displaying #region Pixels // blend // copy // filter // get // loadPixels // pixels // set public void set(int x, int y, color c) { Renderer.SetPixel(x, y, c); }
public void background(color c) { backgroundColor = c; Renderer.ClearToColor(c); ResetPen(); ResetBrush(); }
public void background(color c, int alpha) { color newColor = new color(c.red, c.green, c.blue, (byte)alpha); background(newColor); }
public PLang(PRenderer rndr) { colorMode(RGB, 255); // Stroke default fStrokeWeight = 1; fStrokeJoin = ROUND; fStrokeEndCap = SQUARE; strokeColor = new color(0, 0, 0, 255); useStroke = true; // Fill Default fFillColor = new color(255, 255, 255, 255); useFill = true; backgroundColor = new color(255, 255, 255, 255); fRectMode = CORNER; fEllipseMode = CENTER; fShapeMode = NOSHAPE; SetRenderer(rndr); }
public abstract void SetPixel(float x, float y, color c);
public abstract void ClearToColor(color c);
void createGradient(float x, float y, float radius, color c1, color c2) { float px = 0; float py = 0; float angle = 0; // calculate differences between color components float deltaR = red(c2) - red(c1); float deltaG = green(c2) - green(c1); float deltaB = blue(c2) - blue(c1); float gapFiller = 8; for (int i = 0; i < radius; i++) { for (float j = 0; j < 360; j += 1.0f / gapFiller) { px = x + cos(radians(angle)) * i; py = y + sin(radians(angle)) * i; angle += 1.0f / gapFiller; color c = color( ((int)red(c1) + (i) * (deltaR / radius)), ((int)green(c1) + (i) * (deltaG / radius)), ((int)blue(c1) + (i) * (deltaB / radius))); set((int)px, (int)py, c); } } // adds smooth edges // hack anti-aliasing noFill(); strokeWeight(3); ellipse(x, y, radius * 2, radius * 2); }
// green public float green(color c) { return c.green; }
public void fill(color c, int alpha) { color newColor = new color(c.red, c.green, c.blue, (byte)alpha); fill(c); }
// hue // lerpColor // red public float red(color c) { return c.red; }
public void fill(color c) { fFillColor = c; useFill = true; ResetBrush(); }
Colorref GetColorref(color c) { return Colorref.FromRGB(c.red, c.green, c.blue); }
public void stroke(color c, int alpha) { color newColor = new color(c.red, c.green, c.blue, (byte)alpha); stroke(newColor); }
public override void SetPixel(float x, float y, color c) { Graphics.DeviceContext.SetPixel((int)x, (int)y, GetColorref(c)); }
public override void ClearToColor(color c) { }