OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Alfred E. Neuman macro

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets
View previous topic :: View next topic  
Author Message
donaciano
General User
General User


Joined: 31 Jan 2005
Posts: 27
Location: Vancouver, WA

PostPosted: Tue Aug 30, 2011 2:43 pm    Post subject: Alfred E. Neuman macro Reply with quote

This is a port of the MAD magazine BASIC program originally printed in 1985. Code and history here. It's manually sized for a LETTER page in portrait and I haven't bothered to make it more flexible. So there's a few "magic numbers" for the scaling and centering.

Hey post updates below if you want.

It won't match the original colors, I just used black and white. Also added a wait 20 so you can watch it being drawn. The original took up to 20 minutes on some computers!!! (Seriously?? Can anyone with a Commodore verify that?)

Have an empty Draw document open and run the following code.

Enjoy!
-Don.
Code:

REM  *****  BASIC  ***

' X center is calculated correctly and centered for all page sizes.  Needs auto width
' Y needs work both for centering and width
Sub Main
Dim Doc As Object
Dim Page As Object
Dim LineShape As Object
Dim Point As New com.sun.star.awt.Point
Dim Center As new com.sun.star.awt.Point
Dim Size As New com.sun.star.awt.Size
Doc = ThisComponent
Page = Doc.DrawPages(0)
Center.x = Page.Width / 2' - Page.BorderLeft
Center.y = 0'Page.Height  / 10
 
SCALE = 80

'Dim MyArray() as integer
DIM theData() as integer
' Original MAD Magazine integer coordinates
theData = array(-27,-11,-23,-6,-28,-13,-22,-6,-20,-5,-12,-5,-27,-14,-26,-13,-38,-29,-42,-28,-40,-28,-50,-16,-8,13,0,13,-29,4,-29,9,-50,-17,-41,-28,-49,-17,-50,-8,-8,12,0,12,-28,5,-28,13,-50,-15,-49,-10,40,-26,42,-17,-4,9,-21,14,5,48,2,44,-53,-39,-45,-48,-55,-23,-55,-28,-61,-23,-58,-22,-42,-39,-43,-39,36,-52,36,-55,-37,-48,-32,-56,-32,-56,-26,-60,9,-74,33,-55,6,-12,12,-11,14,-8,24,-11,6,-13,10,-11,20,-9,10,-8,-23,-15,-24,-19,-26,-18,-22,-15,-25,-18,-22,-19,-23,-18,-21,-16,-49,2,-43,10,38,-11,43,-15,7,14,7,9,-9,13,-6,8,-5,-33,-4,-33,-6,-36,-6,-36,-5,-32,-5,-32,-7,-29,-7,-29,-39,-32,-38,-41,-62,-25,-54,-39,-50,-29,-50,-35,-54,-33,-57,-24,-38,-34,-39,-39,-51,-19,-60,-22,-57,-25,-50,-24,-48,-25,-46,-38,-42,-24,-42,-19,41,-26,43,-14,-3,7,-19,14,8,48,4,42,27,-38,31,-47,-29,-42,-16,-37,-11,-51,10,-48,26,-38,24,-47,-4,-73,14,-71,-3,-74,5,-74,5,-73,12,-72,8,-72,35,-57,-2,-48,5,-54,-15,-36,-20,-42,17,-34,32,-45,-6,-53,6,-48,40,-51,38,-43,39,-45,38,-50,38,-46,37,-53,37,-47,37,-46,15,-25,18,-24,23,-18,23,-20,12,-19,19,-18,8,-50,20,-49,-12,-53,-3,-62,-5,-49,14,-49,4,-62,16,-53,-41,-19,-41,-27,44,-14,43,-20,-22,13,-22,14,8,46,2,42,-40,-23,-39,-28,42,-26,50,-19,-23,14,-24,5,3,41,2,48,-51,-42,-39,-49,-47,-26,-49,-36,-53,-18,-59,-21,-45,-28,-53,-23,-40,-19,-37,-7,50,-18,50,-13,-25,5,-26,14,1,41,9,40,-22,-9,-19,-6,-21,-9,-18,-6,-21,-6,-11,-9,-19,-8,-16,-8,-57,-26,-57,-28,-37,-41,-37,-37,-59,-31,-50,-40,-39,-36,-36,-40,-5,-28,-6,-30,-6,-28,-7,-30,6,-28,5,-30,6,-29,6,-31,6,-37,9,-36,-12,-38,-2,-39,-6,-33,-2,-35,-13,-35,-8,-39,-20,-18,-17,-17,-14,-18,-15,-17,-17,-18,-16,-18,-20,-17,-14,-17,-39,-17,-35,-6,51,-14,48,-12,-24,8,-23,13,1,40,12,39,-36,-6,-36,-1,41,-14,40,-9,-23,8,-24,11,14,39,19,40,-26,34,-32,37,-32,37,-29,32,-29,32,-30,36,-29,32,-39,34,-35,-5,-35,-1,40,-13,41,-12,-26,7,-27,14,21,39,11,38,-61,-29,-56,-37,-47,-35,-42,-36,-49,-39,-45,-42,-61,-24,-59,-35,60,-24,55,-20,60,-23,61,-32,61,-29,61,-24,60,-29,59,-33,17,-53,5,-62,6,-48,17,-50,8,-48,2,-54,-28,-41,-18,-48,-14,-52,-4,-62,-5,-51,9,-51,-27,-43,-28,-47,-5,-62,8,-59,-46,14,-42,18,-45,25,-45,15,-42,18,-42,11,-43,11,-51,0,15,-19,18,-16,14,-16,18,-19,7,-18,8,-16,8,-17,11,-16,39,-42,38,-37,39,-40,40,-32,41,-33,40,-39,39,-34,39,-36,42,-40,43,-42,44,-42,45,-32,46,-36,45,-41,42,-38,43,-41,48,-11,47,7,41,-14,40,-9,15,37,15,36,17,36,19,36,-49,-28,-48,-37,-61,-32,-62,-27,-55,-35,-43,-49,-46,-34,-42,-35,-14,-65,-6,-71,14,-68,32,-57,18,-65,20,-63,14,-70,23,-65,31,-41,32,-43,3,-42,4,-43,-22,-43,-23,-42,-9,-52,-9,-52,30,-40,29,-45,14,-50,21,-48,-27,-46,-25,-46,-26,-47,-27,-47,-10,-10,-11,-15,-9,-11,-10,-15,-10,-13,-8,-13,-11,-11,-8,-12,21,-38,29,-44,-7,-48,-3,-48,-27,-45,-21,-47,-12,-55,-6,-61,48,6,49,-11,39,-10,41,-5,18,35,22,35,19,34,23,34,51,-3,45,8,40,-5,38,-11,23,35,43,17,45,17,27,33,46,-40,46,-36,43,-38,43,-39,46,-30,52,-33,47,-30,52,-32,57,-32,57,-27,44,-25,49,-21,7,-13,9,-8,10,-8,8,-12,23,-9,12,-7,11,-9,24,-10,57,-25,53,-24,52,-25,56,-24,56,-32,55,-26,56,-27,56,-29,52,-24,57,-26,-13,-13,-26,-17,-12,-16,-10,-18,-15,-14,-11,-18,-21,-14,-17,-14,18,-20,21,-17,12,-16,16,-19,8,-20,10,-19,13,-23,19,-23,-22,-22,-13,-21,-16,-22,-21,-23,-21,-21,-19,-23,-20,-21,-18,-21,47,4,49,-3,41,-4,37,2,46,16,41,16,41,16,47,9,37,4,41,-2,-49,-9,-48,-4,43,11,45,9,-2,11,1,11,-47,-4,-48,-9,-48,-3,-49,-1,2,11,8,8,4,11,9,9,46,-32,48,-28,49,-38,49,-35,50,-37,51,-25,51,-37,52,-30,-56,-23,-57,-29,-60,-24,-60,-33,-54,-23,-46,-29,-46,-40,-44,-42,-44,-34,-45,-38,-44,-37,-42,-37,-44,-38,-42,-38,-48,-46,-42,-49,21,-16,10,-18,22,-17,19,-25,20,-24,22,-19,10,-23,18,-25,-41,33,-35,34,-41,32,-38,32,-38,31,-42,31,-42,32,-45,30,-3,-36,-12,-37,7,-35,7,-35,-3,-37,-8,-36,-8,-38,-4,-38,8,-18,9,-16,-35,-45,-29,-58,-36,-46,-35,-53,-38,-48,-26,-57,-35,-48,-30,-58,-34,-52,-25,-59,-32,-55,-25,-60,-34,-49,-14,-68,-36,-51,-22,-61,-49,-3,-46,5,10,9,4,15,3,15,6,10,6,11,6,14,47,-22,52,-21,48,-21,56,-20,55,-21,48,-21,56,-20,59,-22,24,-64,32,-60,30,-59,34,-57,33,-59,35,-52,35,-56,36,-49,61,-32,42,-51,43,-51,51,-41,50,-41,45,-46,58,-37,54,-41,-39,30,-45,23,-38,30,-46,21,-46,24,-47,11,-46,12,-42,27,7,-29,6,-31,13,-35,13,-35,4,-37,8,-35,5,-36,8,-37,-16,-49,-8,-50,9,-53,9,-49,20,-37,29,-39,-17,-39,-24,-41,21,-36,32,-44,-2,-62,5,-61,9,-58,16,-53,-26,-44,-22,-46,-51,1,-43,12,7,14,15,13,13,11,17,8,20,10,27,4,-42,11,-49,2,8,13,19,12,19,11,10,12,22,9,27,5,-24,-56,-22,-59,-23,-58,-4,-74,-23,-56,-15,-67,-21,-57,-8,-72,-7,-73,-12,-69,-12,-68,-4,-71,-21,-58,-13,-68,-10,-71,8,-74,12,-32,14,-35,13,-32,12,-37,14,-34,13,-37,11,-37,14,-36,-17,-6,-10,-8,-13,-9,-10,-6,-10,-7,-11,-6,-12,-6,-15,-6,17,-35,21,-39,7,-62,14,-56,14,-51,-17,-48,4,-43,4,-47,-11,-12,-12,-14,-12,-13,-9,-15,-20,-16,-15,-16,-17,-16,-15,-16,-11,-22,-12,-24,-9,-22,-12,-23,-9,-20,-11,-24,-8,-20,-9,-23,-34,-2,-33,6,25,7,29,7,30,8,30,6,31,8,35,9,-33,3,-33,-1,33,8,36,8,36,7,36,2,35,4,35,7,-32,6,-31,11,-30,11,-29,4,3,48,-3,41,-5,41,2,48,-5,-59,-6,-62,12,-52,21,-47,-2,-54,-2,-53,-4,-60,3,-62,-44,-47,-41,-49,-54,-24,-56,-30,-36,-43,-37,-48,-47,-37,-49,-32,-40,-48,-45,-46,-38,-47,-35,-44,-58,-36,-51,-40,-58,-35,-48,-45,24,-42,32,-42,-3,-61,-3,-61,-54,-19,-50,-18,-5,-72,9,-72,10,-22,10,-22,19,-22,19,-22,13,-16,13,-16,9,-19,10,-20,-25,-42,-21,-41,2,-53,4,-54,29,-40,31,-46,26,-43,22,-48,6,-10,18,-6,14,-6,21,-7,22,-8,6,-11,1,-38,-14,-36,-13,-37,-11,-32,-14,-35,-12,-33,55,-37,41,-51,46,-48,61,-33,41,-49,37,-48,-10,-21,-10,-24,-28,-14,-22,-7,-3,43,-26,35,-26,35,-5,41,-9,39,-20,36,-26,34,-26,37,-6,-58,1,-60,-24,-43,-21,-42,3,-45,3,-46,4,-52,4,-53,72,73,72,63,71,74,70,78,71,62,70,58,69,57,65,53,70,78,65,83,64,83,58,86,64,53,55,48,56,49,43,49,47,48,55,48,58,86,46,86,42,84,46,85,44,50,39,52,42,50,39,51,41,85,40,85,39,86,33,86,38,51,33,48,35,79,35,58,34,79,34,58,34,57,32,56,34,80,32,79,32,85,30,83,31,83,31,80,30,82,30,79,31,55,29,55,33,49,23,49,32,48,25,48,24,50,22,50,28,55,17,78,18,79,20,79,20,80,20,84,21,51,18,48,19,50,17,48,16,48,14,48,17,49,14,49,19,85,11,86,13,48,12,53,12,48,11,53,11,54,15,57,15,58,14,59,14,59,-1,59,14,58,-2,58,10,85,7,83,6,84,1,86,0,86,-5,85,-6,84,-6,80,-7,83,-7,79,-5,79,-3,79,-2,78,-13,56,-14,56,-3,78,-2,59,-4,57,-4,56,-1,54,0,55,1,55,1,54,1,50,0,50,-1,48,-2,48,-7,48,-2,49,-6,49,-6,48,-9,51,-7,48,-10,50,-11,49,-17,49,-12,48,-16,48,-17,48,-21,51,-18,48,-22,50,-15,55,-16,55,-17,56,-22,78,-21,79,-19,79,-19,80,-19,84,-23,49,-30,49,-24,48,-30,48,-31,48,-31,55,-32,54,-32,49,-30,55,-28,55,-20,85,-25,86,-26,85,-29,83,-28,55,-32,70,-28,55,-31,71,-28,83,-33,86,-34,86,-37,86,-32,70,-41,49,-38,85,-40,84,-40,83,-40,81,-41,83,-41,79,-40,80,-37,78,-37,78,-41,65,-42,65,-38,78,-43,64,-48,78,-47,79,-45,79,-45,80,-45,84,-46,85,-51,86,-42,49,-47,49,-42,48,-48,48,-48,48,-56,70,-48,49,-56,71,-56,71,-60,56,-52,85,-54,84,-55,83,-59,85,-60,86,-64,86,-59,55,-58,54,-57,54,-55,55,-55,54,-55,50,-56,50,-57,48,-57,49,-61,49,-58,48,-60,48,-61,48,-64,51,-62,48,-65,50,-65,85,-67,84,-67,83,-67,79,-68,83,-68,79,-66,79,-64,79,-63,78,-68,56,-69,55,-64,78,-66,49,-72,49,-68,48,-73,48,-69,55,-73,55,-73,55,-73,48,-74,49,-74,54,61,71,61,65,60,73,60,63,59,73,59,72,60,65,58,60,59,61,54,56,59,74,55,78,59,75,54,80,54,80,48,80,46,79,55,79,54,56,48,56,47,57,46,57,47,78,46,78,45,78,45,58,7,76,11,66,10,66,6,76,9,66,1,66,0,66,6,75,999,0,0,0)

for i = 0 to UBound(TheData) step 4
firstnum = i
X = theData(firstnum)
Y = theData(firstnum+1)
X1 = theData(firstnum+2)
Y1 = theData(firstnum+3)
If X = 999 then  ' left this in so as to leave the data unchanged
  TextTest(Center)
  exit sub
end if

' The coordinates from Mad Magazine are > -100 and < 100 centered around 0 subtracting them from 199 gives a range of 100 - 300
' Get rid of this magic number.  Let's change these to 0-100 or something and use percentages to fill the page at all sizes
FX = X*SCALE
FY = (199-Y)*SCALE
LX = X1*SCALE
LY = (199-Y1)*SCALE

LineShape = Doc.createInstance("com.sun.star.drawing.LineShape")
Size.Width = LX-FX
Size.Height = LY-FY
LineShape.Size = Size
Point.x = FX+Center.x
Point.y = FY+Center.y
LineShape.Position = Point
Page.add(LineShape)
wait 20
next i

End Sub

Sub TextTest(Center)
Dim Doc As Object
Dim Page As Object
Dim RectangleShape As Object


' Lets put this in the footer area instead of in the main draw page. Then we don't have to worry about overlap?
Dim Point As New com.sun.star.awt.Point
Dim Size As New com.sun.star.awt.Size
Point.x = 1000' Center.x'1000
Point.y = 1000'Center.y'1000
'Point = Center
Size.Width = 10000
Size.Height = 10000
Doc = ThisComponent
Page = Doc.DrawPages(0)
RectangleShape = Doc.createInstance("com.sun.star.drawing.RectangleShape")
RectangleShape.Size = Size
RectangleShape.Position = Point
RectangleShape.FillStyle = com.sun.star.drawing.FillStyle.NONE
RectangleShape.LineStyle = com.sun.star.drawing.LineStyle.NONE

Page.add(RectangleShape)
RectangleShape.CharFontName = "Arial"
RectangleShape.String = "COPYRIGHT 1985 E.C. PUBLICATIONS"   ' May only take place after Page.add!
RectangleShape.CharWeight = com.sun.star.awt.FontWeight.BOLD
RectangleShape.CharHeight = 28
RectangleShape.TextVerticalAdjust = com.sun.star.drawing.TextVerticalAdjust.TOP
RectangleShape.TextHorizontalAdjust = com.sun.star.drawing.TextHorizontalAdjust.LEFT
RectangleShape.TextLeftDistance = 300
RectangleShape.TextRightDistance = 300
RectangleShape.TextUpperDistance = 300
RectangleShape.TextLowerDistance = 300

end sub
Back to top
View user's profile Send private message
probe1
Moderator
Moderator


Joined: 18 Aug 2004
Posts: 2560
Location: Chonburi Thailand Asia

PostPosted: Wed Aug 31, 2011 12:39 am    Post subject: Reply with quote

Nice one, thanks
_________________
Cheers
Winfried
My Macros
DateTime2 extension: insert date, time or timestamp, formatted to your needs
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group