Results 1 to 29 of 29

Thread: DEMO: GDI+...Advanced pens and colors

Threaded View

  1. #1

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    DEMO: GDI+...Advanced pens and colors

    Feast your eyes...

    (usual drill, setup a form with a button and paste this code in)

    VB Code:
    1. imports system.drawing.drawing2d
    2. '........
    3.  
    4. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    5.  
    6.         Dim g As Graphics = Me.CreateGraphics
    7.  
    8.         'shape of the pen stroke
    9.         Dim curve() As Point = New Point(6) _
    10.           { _
    11.           New Point(10, 10), _
    12.           New Point(20, 60), _
    13.           New Point(90, 240), _
    14.           New Point(280, 210), _
    15.           New Point(60, 60), _
    16.           New Point(30, 180), _
    17.           New Point(300, 300) _
    18.           }
    19.  
    20.         'define a fancy color gradient
    21.         Dim ink As PathGradientBrush = New PathGradientBrush(curve)
    22.  
    23.         '###########
    24.         'temporary object for setting up the color gradient
    25.         Dim blender As ColorBlend = New ColorBlend(curve.Length)
    26.         blender.Colors = New Color(6) {Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Blue, Color.Indigo, Color.Violet}
    27.         blender.Positions = New Single(6) {}
    28.         For i As Integer = 0 To 6
    29.             blender.Positions(i) = i * (1.0F / 6.0F)          'equally space each colour along the path outline
    30.         Next i
    31.         ink.InterpolationColors = blender
    32.         '###########
    33.  
    34.         Dim CoolPen As Pen = New Pen(ink, 20)         'create a customisable pen object
    35.         CoolPen.CompoundArray() = New Single() {0, 0.2, 0.4, 0.5, 0.75, 1}        'the 3 striped pen instead of a single "nib"
    36.  
    37.         g.DrawBeziers(CoolPen, curve)      'go!
    38.  
    39.     End Sub
    Last edited by wossname; Jun 15th, 2005 at 09:15 AM.
    I don't live here any more.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width