{ CAAD II SS07 Prof. Hovestadt VectorScript: Folding Object from Paper BaTeamAnnaLisa Anna von Knobloch Elisabeth Wiesenthal 'Stufen auf eine Pyramide' 26.05.2007 Die Dimensionen werden auf mm gesetzt. Der Nullpunkt auf die Mitte des Blattes gesetzt. Es wird 1 neuer Layer erzeugt (falls er nicht schon existiert). Der Name ist eine Konstante Es werden 3 Klassen erzeugt (falls sie nicht schon existieren): Schneiden, vorw‰rts falten, r¸ckw‰rts falten. Die Namen sind Konstanten. Die Farben werden von den Klassen ¸bernommen. Variant = 1 und Head = 2 werden empfohlen. Andere Werte kommen aus der Entwicklungsphase sind aber funktionf‰hig } PROCEDURE GenerateStairs; {globale Konstanten} CONST {fixe Parameter} BorderSafe = 5; {Mindestrand} {Layer, Klassen, Farben} ThatLayer = 'FoldCard'; ClassCut = 'Schneiden'; LCR = 2^16-1; LCG = 0; LCB = 0; ClassFoldFore = 'Vorw‰rtsFalten'; LFR = 0; LFG = 0; LFB = 2^16-1; ClassFoldBack = 'R¸ckw‰rtsFalten'; LBR = 0; LBG = (2^15-1); LBB = (2^16-1); {Fehlermeldungen} ErrorMsg1 = 'Abbruch! Einer der Parameter ist Null oder negativ.'; ErrorMsg2 = 'Abbruch! Die Parameter w¸rden zu Schnitten aušerhalb des Blattes f¸hren. Die Form ist zu breit:'; ErrorMsg3 = 'Abbruch! Die Parameter w¸rden zu Schnitten aušerhalb des Blattes f¸hren. Die Form ist unten zu lang:'; ErrorMsg4 = 'Abbruch! Die Parameter w¸rden zu Schnitten aušerhalb des Blattes f¸hren. Die Form ist oben zu lang:'; {globale Variablen} VAR {Parameter aus dem GUI} PaperWidth : REAL; {Breite des Papiers} PaperHeight : REAL; {Hˆhe des Papiers} StairLayers : INTEGER; {Anzahl der Treppen Elemente} StepsPerStair : INTEGER; {Anzahl der Stufen pro Treppe} StepDepth : REAL; {Tiefe der Stufen} StepHeight : REAL; {Hˆhe der Stufen} StepWidth : REAL; {Breite der Stufen} BreakWidth : REAL; {Breite eines Absatzes} Variant : INTEGER; {Variante 0 oder 1} Head : INTEGER; {Abschlussstufe der Pyramide zeichnen (0, 1 oder 2)} {interne Variablen} BottomPosition : REAL; {Abstand der unteren Kante von der Faltlinie = Blattmitte} TopPosition : REAL; {Abstand der oberen Kante von der Faltlinie = Blattmitte} HeadExist : INTEGER; {1 falls Head 1 oder 2 ist} HeadTwo : INTEGER; {1 falls Head 2 ist} MidOffset : REAL; {Anfangspunkt der Mittleren Knicklinie} {Laufvariablen} RunVar1 : INTEGER; RunVar2 : INTEGER; {Subprozeduren} PROCEDURE AssignParameters; {Alle Parameter den entsprechenden Variablen zuweisen um eine saubere Trennung zum GUI herzustellen und w‰hrend der Entwicklungsphase die Werte 'hardcoded' zu verwenden.} BEGIN PaperWidth := 210; PaperHeight := 297; StairLayers := 12; StepsPerStair := 5; StepDepth := 9; {intern die Schnittl‰nge. die Tiefe der Stufen ist also StepDepth - StepHeight} StepHeight := 1; StepWidth := 1; BreakWidth := 3; Variant := 1; Head := 2; {Head muss 0, 1 oder 2 sein!} IF ( ( Head <> 0 ) AND ( Head <> 1 ) ) THEN Head := 2; {HeadExist zuweisen} IF ( Head <> 0 ) THEN HeadExist := 1 ELSE HeadExist := 0; {HeadTwo zuweisen} IF ( Head = 2 ) THEN HeadTwo := 1 ELSE HeadTwo := 0; {BottomPosition & TopPosition errechnen} BottomPosition := (StairLayers + HeadExist) * StepDepth * -1; TopPosition := BottomPosition + (StairLayers + Head) * StepDepth + (StairLayers + HeadTwo) * StepHeight * ( StepsPerStair - 1 ); END; FUNCTION CheckForErrors : INTEGER; {Pr¸ft ob die Pyramide mit den angegebenen Parametern auf das Blatt passt oder Werte Null sind} BEGIN CheckForErrors := 0; {Pr¸fung ob einer der Parameter = 0 ist} IF ( ( PaperWidth <= 0 ) OR ( PaperHeight <= 0 ) OR ( StairLayers <= 0 ) OR ( StepsPerStair <= 0 ) OR ( StepDepth <= 0 ) OR ( StepHeight <= 0 ) OR ( StepWidth <= 0 ) OR ( BreakWidth <= 0 ) ) THEN BEGIN Message(ErrorMsg1); CheckForErrors := 1; END; {Pr¸fung der Breite} IF ( 2 * BorderSafe + ( 2 * StairLayers + 1 ) * BreakWidth + 2 * StairLayers * ( StepsPerStair - 1 ) * StepWidth > PaperWidth ) THEN BEGIN Message(ErrorMsg2, 2 * BorderSafe + ( 2 * StairLayers + 1 ) * BreakWidth + 2 * StairLayers * (StepsPerStair - 1) * StepWidth); CheckForErrors := 1; END; {Pr¸fung der L‰nge unten --> vor dem ausf¸hren dieser Subprozedur MUSS BottomPosition zugewiesen sein!} IF ( BottomPosition - BorderSafe < -PaperHeight / 2 ) THEN BEGIN Message(ErrorMsg3, -BottomPosition + BorderSafe); CheckForErrors := 1; END; {Pr¸fung der L‰nge oben --> vor dem ausf¸hren dieser Subprozedur MUSS TopPosition zugewiesen sein!} IF ( TopPosition + BorderSafe > PaperHeight / 2 ) THEN BEGIN Message(ErrorMsg4, TopPosition + BorderSafe); CheckForErrors := 1; END; END; PROCEDURE PrepareDocument; {Layers u.U. erstellen, Farbe definieren, Mašstab setzen, Nullpunkt setzen} BEGIN Layer(ThatLayer); SetScale(1); NameClass(ClassCut); SetClPenFore(ClassCut, LCR, LCG, LCB); NameClass(ClassFoldFore); SetClPenFore(ClassFoldFore, LFR, LFG, LFB); NameClass(ClassFoldBack); SetClPenFore(ClassFoldBack, LBR, LBG, LBB); SetOrigin (0,0); Units(4); END; PROCEDURE DrawStairElement(StartX, StartY: REAL); {zeichnet ein Treppenelement} VAR RunVarDSE : INTEGER; {Laufvariable Intern} HalfStair : REAL; {Halbe Treppenl‰nge - wird oft gebraucht} BEGIN HalfStair := (StepsPerStair - 1) * StepWidth + BreakWidth / 2; NameClass(ClassCut); FOR RunVarDSE := 0 TO StepsPerStair-1 DO BEGIN MoveTo (StartX + RunVarDSE * StepWidth - HalfStair, StartY+ RunVarDSE * StepHeight); LineTo (StartX + RunVarDSE * StepWidth - HalfStair, StartY+ RunVarDSE * StepHeight + StepDepth); MoveTo (StartX - RunVarDSE * StepWidth + HalfStair, StartY+ RunVarDSE * StepHeight); LineTo (StartX - RunVarDSE * StepWidth + HalfStair, StartY+ RunVarDSE * StepHeight + StepDepth); END; NameClass(ClassFoldBack); FOR RunVarDSE := 1 TO StepsPerStair-1 DO BEGIN MoveTo (StartX + (RunVarDSE-1) * StepWidth - HalfStair, StartY+ RunVarDSE * StepHeight); LineTo (StartX + RunVarDSE * StepWidth - HalfStair, StartY+ RunVarDSE * StepHeight); MoveTo (StartX - (RunVarDSE-1) * StepWidth + HalfStair, StartY+ RunVarDSE * StepHeight); LineTo (StartX - RunVarDSE * StepWidth + HalfStair, StartY+ RunVarDSE * StepHeight); END; MoveTo ( StartX - BreakWidth / 2, StartY + StepsPerStair * StepHeight ); LineTo ( StartX + BreakWidth / 2, StartY + StepsPerStair * StepHeight ); NameClass(ClassFoldFore); FOR RunVarDSE := 1 TO StepsPerStair-1 DO BEGIN MoveTo (StartX + (RunVarDSE-1) * StepWidth - HalfStair, StartY + ( RunVarDSE - 1 ) * StepHeight + StepDepth); LineTo (StartX + RunVarDSE * StepWidth - HalfStair, StartY + ( RunVarDSE - 1 ) * StepHeight + StepDepth); MoveTo (StartX - (RunVarDSE-1) * StepWidth + HalfStair, StartY + ( RunVarDSE - 1 ) * StepHeight + StepDepth); LineTo (StartX - RunVarDSE * StepWidth + HalfStair, StartY + ( RunVarDSE - 1 ) * StepHeight + StepDepth); END; END; {Hauptprozedur} BEGIN AssignParameters; IF ( CheckForErrors = 0 ) THEN BEGIN PrepareDocument; PenColorByClass; { Alle Treppen } FOR RunVar1 := StairLayers DOWNTO 1 DO BEGIN FOR RunVar2 := 0 TO (RunVar1 - 1) DO BEGIN DrawStairElement( ( -(RunVar1 - 1) + (2 * RunVar2 ) )* ( ( StepsPerStair - 1 ) * StepWidth + BreakWidth ), BottomPosition + (StairLayers - RunVar1) * ( StepDepth + StepHeight * ( StepsPerStair - 1 ) ) ); { Faltlinien innen } IF ( RunVar1 < StairLayers ) THEN BEGIN NameClass(ClassFoldFore); MoveTo ( ( -(RunVar1 - 1) + (2 * RunVar2 ) )* ( ( StepsPerStair - 1 ) * StepWidth + BreakWidth ) - BreakWidth / 2, BottomPosition + (StairLayers - RunVar1 - 1) * ( StepDepth + StepHeight * ( StepsPerStair - 1 ) ) + StepDepth - StepHeight); LineTo ( ( -(RunVar1 - 1) + (2 * RunVar2 ) )* ( ( StepsPerStair - 1 ) * StepWidth + BreakWidth ) + BreakWidth / 2, BottomPosition + (StairLayers - RunVar1 - 1) * ( StepDepth + StepHeight * ( StepsPerStair - 1 ) ) + StepDepth - StepHeight); END; { Aušenlinien zeichnen } IF ( ( HeadExist <> 0 ) OR ( RunVar1 <> 1 ) ) THEN BEGIN IF ( RunVar2 = 0 ) THEN BEGIN NameClass(ClassFoldFore); MoveTo ( ( -(RunVar1 - 1) + (2 * RunVar2 - 1) )* ( ( StepsPerStair - 1 ) * StepWidth + BreakWidth )+ BreakWidth / 2, BottomPosition + (StairLayers - RunVar1) * ( StepDepth + StepHeight * ( StepsPerStair - 1 ) ) + StepDepth - StepHeight ); LineTo ( ( -(RunVar1 - 1) + (2 * RunVar2 - 1) )* ( ( StepsPerStair - 1 ) * StepWidth + BreakWidth )- BreakWidth / 2, BottomPosition + (StairLayers - RunVar1) * ( StepDepth + StepHeight * ( StepsPerStair - 1 ) ) + StepDepth - StepHeight ); NameClass(ClassCut); LineTo ( ( -(RunVar1 - 1) + (2 * RunVar2 - 1) )* ( ( StepsPerStair - 1 ) * StepWidth + BreakWidth )- BreakWidth / 2, BottomPosition + (StairLayers - RunVar1 + 1) * ( StepDepth + StepHeight * ( StepsPerStair - 1 ) ) + HeadExist * StepDepth + Variant * HeadTwo * StepDepth + Variant * StepDepth * ( RunVar1 - 1) - StepHeight ); { F¸r die L‰nge der mittleren Faltlinie des Blattes } IF ( ( BottomPosition + (StairLayers - RunVar1) * ( StepDepth + StepHeight * ( StepsPerStair - 1 ) ) + StepDepth - StepHeight <= 0) AND ( BottomPosition + (StairLayers - RunVar1 + 1) * ( StepDepth + StepHeight * ( StepsPerStair - 1 ) ) + HeadExist * StepDepth + Variant * HeadTwo * StepDepth + Variant * StepDepth * ( RunVar1 - 1) - StepHeight >= 0) AND ( MidOffset = 0 ) ) THEN MidOffset := ( -(RunVar1 - 1) + (2 * RunVar2 - 1) )* ( ( StepsPerStair - 1 ) * StepWidth + BreakWidth )- BreakWidth / 2; IF ( Variant = 1 ) THEN NameClass(ClassFoldFore) ELSE NameClass(ClassCut); LineTo ( ( -(RunVar1 - 1) + (2 * RunVar2) )* ( ( StepsPerStair - 1 ) * StepWidth + BreakWidth )- BreakWidth / 2, BottomPosition + (StairLayers - RunVar1 + 1) * ( StepDepth + StepHeight * ( StepsPerStair - 1 ) ) + HeadExist * StepDepth + Variant * HeadTwo * StepDepth+ Variant * StepDepth * ( RunVar1 - 1) - StepHeight ); NameClass(ClassFoldBack); MoveTo ( ( -(RunVar1 - 1) + (2 * RunVar2 - 1) )* ( ( StepsPerStair - 1 ) * StepWidth + BreakWidth )- BreakWidth / 2, BottomPosition + (StairLayers - RunVar1 + 1) * ( StepDepth + StepHeight * ( StepsPerStair - 1 ) ) ); LineTo ( ( -(RunVar1 - 1) + (2 * RunVar2) )* ( ( StepsPerStair - 1 ) * StepWidth + BreakWidth )- BreakWidth / 2, BottomPosition + (StairLayers - RunVar1 + 1) * ( StepDepth + StepHeight * ( StepsPerStair - 1 ) ) ); END; IF ( RunVar2 = RunVar1 - 1) THEN BEGIN NameClass(ClassFoldFore); MoveTo ( ( -(RunVar1 - 1) + (2 * RunVar2 + 1) )* ( ( StepsPerStair - 1 ) * StepWidth + BreakWidth ) - BreakWidth / 2, BottomPosition + (StairLayers - RunVar1) * ( StepDepth + StepHeight * ( StepsPerStair - 1 ) ) + StepDepth - StepHeight ); LineTo ( ( -(RunVar1 - 1) + (2 * RunVar2 + 1) )* ( ( StepsPerStair - 1 ) * StepWidth + BreakWidth ) + BreakWidth / 2, BottomPosition + (StairLayers - RunVar1) * ( StepDepth + StepHeight * ( StepsPerStair - 1 ) ) + StepDepth - StepHeight ); NameClass(ClassCut); LineTo ( ( -(RunVar1 - 1) + (2 * RunVar2 + 1) )* ( ( StepsPerStair - 1 ) * StepWidth + BreakWidth ) + BreakWidth / 2, BottomPosition + (StairLayers - RunVar1 + 1) * ( StepDepth + StepHeight * ( StepsPerStair - 1 ) ) + HeadExist * StepDepth + Variant * HeadTwo * StepDepth + Variant * StepDepth * ( RunVar1 - 1) - StepHeight ); IF ( Variant = 1 ) THEN NameClass(ClassFoldFore) ELSE NameClass(ClassCut); LineTo ( ( - ( RunVar1 - 1) + (2 * RunVar2) )* ( ( StepsPerStair - 1 ) * StepWidth + BreakWidth ) + BreakWidth / 2, BottomPosition + (StairLayers - RunVar1 + 1) * ( StepDepth + StepHeight * ( StepsPerStair - 1 ) ) + HeadExist * StepDepth + Variant * HeadTwo * StepDepth + Variant * StepDepth * ( RunVar1 - 1) - StepHeight ); NameClass(ClassFoldBack); MoveTo ( ( -(RunVar1 - 1) + (2 * RunVar2 + 1) )* ( ( StepsPerStair - 1 ) * StepWidth + BreakWidth ) + BreakWidth / 2, BottomPosition + (StairLayers - RunVar1 + 1) * ( StepDepth + StepHeight * ( StepsPerStair - 1 ) ) ); LineTo ( ( -(RunVar1 - 1) + (2 * RunVar2) )* ( ( StepsPerStair - 1 ) * StepWidth + BreakWidth ) + BreakWidth / 2, BottomPosition + (StairLayers - RunVar1 + 1) * ( StepDepth + StepHeight * ( StepsPerStair - 1 ) ) ); END; END; END; END; { Faltlinien unten } NameClass(ClassFoldFore); FOR RunVar2 := 0 TO ( StairLayers - 1) DO BEGIN MoveTo ( ( ( 2 * RunVar2 - StairLayers ) * ( StepsPerStair - 1 ) * StepWidth ) + ( ( 2 * RunVar2 - StairLayers ) + 0.5) * BreakWidth, BottomPosition); LineTo ( ( ( 2 * ( RunVar2 + 1 ) - StairLayers ) * ( StepsPerStair - 1 ) * StepWidth ) + ( ( 2 * ( RunVar2 + 1 ) - StairLayers ) - 0.5) * BreakWidth, BottomPosition); END; { Abschluss / Head zeichnen } NameClass(ClassFoldFore); CASE Head OF 0: BEGIN MoveTo ( -BreakWidth / 2 , TopPosition ); LineTo ( +BreakWidth / 2 , TopPosition ); MoveTo ( -BreakWidth / 2 - (StepsPerStair - 1) * StepWidth, TopPosition - StepsPerStair * StepHeight); LineTo ( -BreakWidth * 1.5 - (StepsPerStair - 1) * StepWidth , TopPosition - StepsPerStair * StepHeight); MoveTo ( +BreakWidth / 2 + (StepsPerStair - 1) * StepWidth, TopPosition - StepsPerStair * StepHeight); LineTo ( +BreakWidth * 1.5 + (StepsPerStair - 1) * StepWidth , TopPosition - StepsPerStair * StepHeight); END; 1: BEGIN MoveTo ( -BreakWidth / 2 , TopPosition - StepHeight); LineTo ( +BreakWidth / 2 , TopPosition - StepHeight); END; 2: BEGIN MoveTo ( -BreakWidth / 2 , TopPosition - StepHeight); LineTo ( +BreakWidth / 2 , TopPosition - StepHeight); NameClass(ClassCut); LineTo ( +BreakWidth / 2 , TopPosition - StepDepth - StepsPerStair * StepHeight); NameClass(ClassFoldFore); LineTo ( -BreakWidth / 2 , TopPosition - StepDepth - StepsPerStair * StepHeight); NameClass(ClassCut); LineTo ( -BreakWidth / 2 , TopPosition - StepHeight); NameClass(ClassFoldBack); MoveTo ( +BreakWidth / 2 , TopPosition - StepDepth); LineTo ( -BreakWidth / 2 , TopPosition - StepDepth); END; END; { Mittlere Linie } NameClass(ClassFoldFore); MoveTo ( -PaperWidth / 2 , 0 ); LineTo ( MidOffset , 0 ); MoveTo ( PaperWidth / 2, 0 ); LineTo ( -MidOffset, 0 ); { SeiteRandZeichnen } NameClass(ClassCut); MoveTo ( -PaperWidth / 2, -PaperHeight / 2); LineTo ( PaperWidth / 2, -PaperHeight / 2); LineTo ( PaperWidth / 2, PaperHeight / 2); LineTo ( -PaperWidth / 2, PaperHeight / 2); LineTo ( -PaperWidth / 2, -PaperHeight / 2); END; END; RUN(GenerateStairs);