469,159 Members | 1,413 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,159 developers. It's quick & easy.

rotate drawing with matrix

Hi group,
I got the following piece of code which draws a square with stars round it,
now I want the stars to rotate round the square, I can do this with the
mx.rotate and a timer and an angle, but this rotates the whole drawing of
the stars but what I realy want is for the stars to rotate round it's center
point, is this possible? I hope I was clear enough in my explanation.

Thanks in advance

Peter

Imports System.Drawing.Drawing2D

Private pentje As New Pen(Color.White)
Private brush As New SolidBrush(Color.White)
Private hoek As Single
e.Graphics.FillRectangle(brush, 100, 100, 100, 100)

'Place inside form paint event
'Dim mx As New Matrix
'mx.Rotate(hoek, MatrixOrder.Append)
'mx.Translate(Me.ClientSize.Width / 2, Me.ClientSize.Height / 2,
MatrixOrder.Append)
'e.Graphics.Transform = mx

'grote ster
e.Graphics.DrawLine(pentje, 100, 100, 150, 0)
e.Graphics.DrawLine(pentje, 150, 0, 200, 100)
e.Graphics.DrawLine(pentje, 200, 100, 300, 150)
e.Graphics.DrawLine(pentje, 300, 150, 200, 200)
e.Graphics.DrawLine(pentje, 200, 200, 150, 300)
e.Graphics.DrawLine(pentje, 150, 300, 100, 200)
e.Graphics.DrawLine(pentje, 100, 200, 0, 150)
e.Graphics.DrawLine(pentje, 0, 150, 100, 100)
'kleine ster
e.Graphics.DrawLine(pentje, 100, 100, 150, 25)
e.Graphics.DrawLine(pentje, 150, 25, 200, 100)
e.Graphics.DrawLine(pentje, 200, 100, 275, 150)
e.Graphics.DrawLine(pentje, 275, 150, 200, 200)
e.Graphics.DrawLine(pentje, 200, 200, 150, 275)
e.Graphics.DrawLine(pentje, 150, 275, 100, 200)
e.Graphics.DrawLine(pentje, 100, 200, 25, 150)
e.Graphics.DrawLine(pentje, 25, 150, 100, 100)
'kleinere ster
e.Graphics.DrawLine(pentje, 100, 100, 150, 50)
e.Graphics.DrawLine(pentje, 150, 50, 200, 100)
e.Graphics.DrawLine(pentje, 200, 100, 250, 150)
e.Graphics.DrawLine(pentje, 250, 150, 200, 200)
e.Graphics.DrawLine(pentje, 200, 200, 150, 250)
e.Graphics.DrawLine(pentje, 150, 250, 100, 200)
e.Graphics.DrawLine(pentje, 100, 200, 50, 150)
e.Graphics.DrawLine(pentje, 50, 150, 100, 100)
'kleinste ster
e.Graphics.DrawLine(pentje, 100, 100, 150, 75)
e.Graphics.DrawLine(pentje, 150, 75, 200, 100)
e.Graphics.DrawLine(pentje, 200, 100, 225, 150)
e.Graphics.DrawLine(pentje, 225, 150, 200, 200)
e.Graphics.DrawLine(pentje, 200, 200, 150, 225)
e.Graphics.DrawLine(pentje, 150, 225, 100, 200)
e.Graphics.DrawLine(pentje, 100, 200, 75, 150)
e.Graphics.DrawLine(pentje, 75, 150, 100, 100)
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Timer1.Tick
hoek += 3
If hoek > 359 Then
hoek = 0
End If
Invalidate()
End Sub
Nov 21 '05 #1
2 2462

What you need it do is change the position of of where you draw the stars
each time you draw them. One way would be to setup the star as if you are
drawing at the origin. Then translate the Graphics object to the star's
rotate position. Next draw the star and then reset the Graphic object's
translation. Repeat this until all stars are drawn for that rotation part.

Robby
"Peter Proost" <pp*****@nospam.hotmail.com> wrote in message
news:OK**************@TK2MSFTNGP12.phx.gbl...
Hi group,
I got the following piece of code which draws a square with stars round
it,
now I want the stars to rotate round the square, I can do this with the
mx.rotate and a timer and an angle, but this rotates the whole drawing of
the stars but what I realy want is for the stars to rotate round it's
center
point, is this possible? I hope I was clear enough in my explanation.

Thanks in advance

Peter

Imports System.Drawing.Drawing2D

Private pentje As New Pen(Color.White)
Private brush As New SolidBrush(Color.White)
Private hoek As Single
e.Graphics.FillRectangle(brush, 100, 100, 100, 100)

'Place inside form paint event
'Dim mx As New Matrix
'mx.Rotate(hoek, MatrixOrder.Append)
'mx.Translate(Me.ClientSize.Width / 2, Me.ClientSize.Height / 2,
MatrixOrder.Append)
'e.Graphics.Transform = mx

'grote ster
e.Graphics.DrawLine(pentje, 100, 100, 150, 0)
e.Graphics.DrawLine(pentje, 150, 0, 200, 100)
e.Graphics.DrawLine(pentje, 200, 100, 300, 150)
e.Graphics.DrawLine(pentje, 300, 150, 200, 200)
e.Graphics.DrawLine(pentje, 200, 200, 150, 300)
e.Graphics.DrawLine(pentje, 150, 300, 100, 200)
e.Graphics.DrawLine(pentje, 100, 200, 0, 150)
e.Graphics.DrawLine(pentje, 0, 150, 100, 100)
'kleine ster
e.Graphics.DrawLine(pentje, 100, 100, 150, 25)
e.Graphics.DrawLine(pentje, 150, 25, 200, 100)
e.Graphics.DrawLine(pentje, 200, 100, 275, 150)
e.Graphics.DrawLine(pentje, 275, 150, 200, 200)
e.Graphics.DrawLine(pentje, 200, 200, 150, 275)
e.Graphics.DrawLine(pentje, 150, 275, 100, 200)
e.Graphics.DrawLine(pentje, 100, 200, 25, 150)
e.Graphics.DrawLine(pentje, 25, 150, 100, 100)
'kleinere ster
e.Graphics.DrawLine(pentje, 100, 100, 150, 50)
e.Graphics.DrawLine(pentje, 150, 50, 200, 100)
e.Graphics.DrawLine(pentje, 200, 100, 250, 150)
e.Graphics.DrawLine(pentje, 250, 150, 200, 200)
e.Graphics.DrawLine(pentje, 200, 200, 150, 250)
e.Graphics.DrawLine(pentje, 150, 250, 100, 200)
e.Graphics.DrawLine(pentje, 100, 200, 50, 150)
e.Graphics.DrawLine(pentje, 50, 150, 100, 100)
'kleinste ster
e.Graphics.DrawLine(pentje, 100, 100, 150, 75)
e.Graphics.DrawLine(pentje, 150, 75, 200, 100)
e.Graphics.DrawLine(pentje, 200, 100, 225, 150)
e.Graphics.DrawLine(pentje, 225, 150, 200, 200)
e.Graphics.DrawLine(pentje, 200, 200, 150, 225)
e.Graphics.DrawLine(pentje, 150, 225, 100, 200)
e.Graphics.DrawLine(pentje, 100, 200, 75, 150)
e.Graphics.DrawLine(pentje, 75, 150, 100, 100)
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As
System.EventArgs)
Handles Timer1.Tick
hoek += 3
If hoek > 359 Then
hoek = 0
End If
Invalidate()
End Sub

Nov 21 '05 #2
Have you got some sample code? Because I'm not 100% sure how to go about
this

Thanks in advance

"Robby" <ed****@not.my.email.com> wrote in message
news:u3**************@TK2MSFTNGP14.phx.gbl...

What you need it do is change the position of of where you draw the stars
each time you draw them. One way would be to setup the star as if you are
drawing at the origin. Then translate the Graphics object to the star's
rotate position. Next draw the star and then reset the Graphic object's
translation. Repeat this until all stars are drawn for that rotation part.
Robby
"Peter Proost" <pp*****@nospam.hotmail.com> wrote in message
news:OK**************@TK2MSFTNGP12.phx.gbl...
Hi group,
I got the following piece of code which draws a square with stars round
it,
now I want the stars to rotate round the square, I can do this with the
mx.rotate and a timer and an angle, but this rotates the whole drawing of the stars but what I realy want is for the stars to rotate round it's
center
point, is this possible? I hope I was clear enough in my explanation.

Thanks in advance

Peter

Imports System.Drawing.Drawing2D

Private pentje As New Pen(Color.White)
Private brush As New SolidBrush(Color.White)
Private hoek As Single
e.Graphics.FillRectangle(brush, 100, 100, 100, 100)

'Place inside form paint event
'Dim mx As New Matrix
'mx.Rotate(hoek, MatrixOrder.Append)
'mx.Translate(Me.ClientSize.Width / 2, Me.ClientSize.Height / 2,
MatrixOrder.Append)
'e.Graphics.Transform = mx

'grote ster
e.Graphics.DrawLine(pentje, 100, 100, 150, 0)
e.Graphics.DrawLine(pentje, 150, 0, 200, 100)
e.Graphics.DrawLine(pentje, 200, 100, 300, 150)
e.Graphics.DrawLine(pentje, 300, 150, 200, 200)
e.Graphics.DrawLine(pentje, 200, 200, 150, 300)
e.Graphics.DrawLine(pentje, 150, 300, 100, 200)
e.Graphics.DrawLine(pentje, 100, 200, 0, 150)
e.Graphics.DrawLine(pentje, 0, 150, 100, 100)
'kleine ster
e.Graphics.DrawLine(pentje, 100, 100, 150, 25)
e.Graphics.DrawLine(pentje, 150, 25, 200, 100)
e.Graphics.DrawLine(pentje, 200, 100, 275, 150)
e.Graphics.DrawLine(pentje, 275, 150, 200, 200)
e.Graphics.DrawLine(pentje, 200, 200, 150, 275)
e.Graphics.DrawLine(pentje, 150, 275, 100, 200)
e.Graphics.DrawLine(pentje, 100, 200, 25, 150)
e.Graphics.DrawLine(pentje, 25, 150, 100, 100)
'kleinere ster
e.Graphics.DrawLine(pentje, 100, 100, 150, 50)
e.Graphics.DrawLine(pentje, 150, 50, 200, 100)
e.Graphics.DrawLine(pentje, 200, 100, 250, 150)
e.Graphics.DrawLine(pentje, 250, 150, 200, 200)
e.Graphics.DrawLine(pentje, 200, 200, 150, 250)
e.Graphics.DrawLine(pentje, 150, 250, 100, 200)
e.Graphics.DrawLine(pentje, 100, 200, 50, 150)
e.Graphics.DrawLine(pentje, 50, 150, 100, 100)
'kleinste ster
e.Graphics.DrawLine(pentje, 100, 100, 150, 75)
e.Graphics.DrawLine(pentje, 150, 75, 200, 100)
e.Graphics.DrawLine(pentje, 200, 100, 225, 150)
e.Graphics.DrawLine(pentje, 225, 150, 200, 200)
e.Graphics.DrawLine(pentje, 200, 200, 150, 225)
e.Graphics.DrawLine(pentje, 150, 225, 100, 200)
e.Graphics.DrawLine(pentje, 100, 200, 75, 150)
e.Graphics.DrawLine(pentje, 75, 150, 100, 100)
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As
System.EventArgs)
Handles Timer1.Tick
hoek += 3
If hoek > 359 Then
hoek = 0
End If
Invalidate()
End Sub


Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by JustSomeGuy | last post: by
1 post views Thread by iwdu15 | last post: by
8 posts views Thread by lovecreatesbeauty | last post: by
8 posts views Thread by =?Utf-8?B?RGFu?= | last post: by
13 posts views Thread by =?Utf-8?B?dmlubw==?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.