ETH Zuerich - Startseite
Professur für CAAD

 


caad d-arch


Caad Teaching
 

 
Bachelor of Architecture: CAAD II ss07

 
Master of Advanced Studies
in Architecture, CAAD


 
DWF-Processing
Programmieren statt Zeichnen


 
Graustufen - Ein Atlas
Schweizer Wohngebäude als XML Daten


 
DWF- Denken in Systemen:
In Collaboration with the Technical University Vienna


 
Seminarwoche:
BlowUp


 
Archiv

 
Caad Projects
 

 
Theory
 
Design
 
Building
 
Practice

 
Related pages
 

 
Swiss Federal Institute of Technology Zurich
 
Institute of Building Technology
 
Faculty of Architecture

 
Other pages

 










hbt d-arch

MAS ETH ARCH/CAAD - 2005/06 - STUDENT PAGES
Master of Advanced Studies in Architecture, Specialization in Computer Aided Architectural Design | 065-0005/6
Supervision: Prof. Dr. Ludger Hovestadt, Philipp Schaerer
Chair of CAAD, ETH Zurich





Mondrian Code

Procedure sMondrian;

VAR
   startZ : REAL;
   subtrVol, streetSolid, divSolid  : HANDLE;
   ArrayPosH:DYNARRAY [] OF REAL;
   ArrayPosV:DYNARRAY [] OF REAL;
   
   myColorIndex, returnVal  : INTEGER;   

   selectedSites:DYNARRAY [] OF POINT;

   i,k:INTEGER;
   rectHeight,rectWidth:REAL;
   r,g,b:LONGINT;
   streetsHor, streetsVer :INTEGER;
   x,y,p,p1,p2,p3:INTEGER;
   stPtX,stPtY,stPtX1,stPtY1 : REAL;
   randomIndex : INTEGER;
   horsites,versites : INTEGER;
   str : STRING;
   h:INTEGER;
   forcedNumbOfSites, numbOfSites : INTEGER;
   tempPt : POINT;
   isOccupied : BOOLEAN;
   rV,gV,bV : LONGINT;
   pointY1,pointX2,pointY2: REAL;
   
   FUNCTION EqualPoint(pt1,pt2 : POINT):BOOLEAN;
   VAR
      bol : BOOLEAN;   
   BEGIN;
      bol := EqualPt(pt1.x,pt1.y,pt2.x,pt2.y);
      EqualPoint:= bol ;
   END;


{******* building *******}
   PROCEDURE drawBuilding(pointX1,pointY1,pointX2,pointY2: REAL; colorIndex : INTEGER; extrudedSite : HANDLE );

   VAR

      blockWidthX, blockHeightY : REAL;
      rV, gV, bV : LONGINT;
      colorIndex1, ReturnINT  : INTEGER;
      newSolid : HANDLE;
      UserObjectPick : HANDLE;

    BEGIN
      blockWidthX := Abs(pointX2-pointX1);
      blockHeightY := Abs(pointY2-pointY1);
      
      REPEAT
         p3:= Trunc(random*4);
         CASE p3 OF
            0: colorIndex1 := 35;
            1: colorIndex1 := 245;
            2: colorIndex1 := 16;
            3: colorIndex1 := 5;
         END;
      UNTIL (colorIndex1 <> colorIndex);
         
      ColorIndexToRGB(colorIndex1,rV,gV,bV);

         FillBack(rV,gV,bV);
      PenFore(rV,gV,bV);
      BeginXtrd(0,90);
         rect(pointX1+1/3*blockWidthX,pointY1+1/3*blockHeightY,pointX1+ 2/3 *blockWidthX,pointY1+2/3*blockHeightY); 
      EndXtrd; 

      ReturnINT := SubtractSolid(extrudedSite,LNewObj,newSolid);  
      
   END;


{******* site *******}
   PROCEDURE drawSite(pointX1,pointY1,pointX2,pointY2: REAL; colorIndex : INTEGER);
   VAR

      blockWidthX, blockHeightY : REAL;
      rV,gV,bV : LONGINT;

   BEGIN
      ColorIndexToRGB(colorIndex,rV,gV,bV);

      blockWidthX := Abs(pointX2-pointX1);
      blockHeightY := Abs(pointY2-pointY1);

      FillBack(rV,gV,bV);
      PenFore(rV,gV,bV);
      p2:= Trunc(random*4);
      CASE p2 OF
            
         0: Begin
            BeginXtrd(0,90);
               rect(pointX1+ 1/3 * blockWidthX,pointY1,pointX1+ 2/3 *blockWidthX,pointY2);   
            EndXtrd; 
               drawBuilding(pointX1+ 1/4 * blockWidthX,pointY1,pointX1+ 3/4 *blockWidthX,pointY2,colorIndex, LNewObj);
            END;
            
         1: Begin
            BeginXtrd(0,90);
                     rect(pointX1,pointY1 + 1/3 * blockHeightY,pointX2,pointY1 + 2/3 * blockHeightY);
            EndXtrd; 
             drawBuilding(pointX1,pointY1 + 1/4 * blockHeightY,pointX2,pointY1 + 3/4 * blockHeightY,colorIndex,LNewObj);
            END;

         2:    Begin
            BeginXtrd(0,90);
               rect(pointX1,pointY1 + 1/3 * blockHeightY,pointX2,pointY2);
            EndXtrd; 
             drawBuilding(pointX1,pointY1 + 1/3 * blockHeightY,pointX2,pointY2,colorIndex, LNewObj);
            END;

         3: Begin
            BeginXtrd(0,90);
            rect(pointX1,pointY1,pointX1 + 2/3*blockWidthX,pointY2);
            EndXtrd; 
            drawBuilding(pointX1,pointY1,pointX1 + 2/3*blockWidthX,pointY2,colorIndex, LNewObj);
            END;
      END;
   END;

   
BEGIN
   
   numbOfSites := 15;
   ALLOCATE selectedSites[1..numbOfSites];

   streetsHor := 5;
   streetsVer := 5;

   ALLOCATE ArrayPosH[1..streetsHor];
   ALLOCATE ArrayPosV[1..streetsVer];
   
(******* canvas *******)   
   rectHeight:=RealDialog('rectHeightCanvas','90');
   rectWidth:=RealDialog('rectWidthCanvas','3');

(******* yellow streets *******)
   FOR i:=1 TO streetsHor DO BEGIN
      ArrayPosH[i]:= rectHeight/streetsHor * Random +(i-1)*rectHeight/streetsHor  ;
   END;


   FOR i:=1 TO streetsVer DO BEGIN
      ArrayPosV[i]:= rectHeight/streetsVer * Random +(i-1)*rectHeight/streetsVer  ;
   END;

   For k:=1 TO 5 DO BEGIN
      MoveTo(ArrayPosV[k],0);
      ColorIndexToRGB(5,r,g,b);
      FillBack(r,g,b);
      ColorIndexToRGB(5,r,g,b);
      PenFore(r,g,b);
      str := concat('streetVer', k);

      BeginXtrd(0,90);
         rect(ArrayPosV[k]-1/2*rectWidth,0,ArrayPosV[k]+1/2*rectWidth,rectHeight);
      EndXtrd; 
      SetName(lNewObj,str);
   END;

   For k:=1 TO 5 DO BEGIN
      MoveTo(0,ArrayPosH[k]);
      ColorIndexToRGB(5,r,g,b);
      FillBack(r,g,b);
      ColorIndexToRGB(5,r,g,b);
      PenFore(r,g,b);
      str := concat('streetHor', k);
      
      BeginXtrd(0,90);
         rect(0,ArrayPosH[k]-1/2*rectWidth,rectHeight,ArrayPosH[k]+1/2*rectWidth);
      EndXtrd;
      SetName(lNewObj,str);
   END;
   
(******* cars *******)
   For i:=1 TO 4 DO BEGIN
      For k:=1 TO 5 DO BEGIN   
         p:= Trunc(random*3);
         CASE p OF 
            0: ColorIndexToRGB(245,r,g,b);
            1: ColorIndexToRGB(16,r,g,b);
            2: ColorIndexToRGB(35,r,g,b);
         END;
         FillBack(r,g,b);
         PenFore(r,g,b);
         stPtX := ArrayPosV[k]-1/2*rectWidth;
         stPtY := random * (rectHeight-rectWidth);
          
         BeginXtrd(0 ,90);
            rect(stPtX-1,stPtY-1,stPtX+rectWidth+1,stPtY+rectWidth+1);
         EndXtrd;
         subtrVol := LNewObj;
         DSelectAll; 
         str := concat('streetVer',k);
         SelectObj(N=str);
         streetSolid := FSActLayer;
         SetName(streetSolid ,'');
         returnVal := SubtractSolid(streetSolid ,subtrVol,divSolid);
         SetName(divSolid,str);
         startZ := random*90-10;
         BeginXtrd(startZ ,startZ + 10);
            rect(stPtX-1,stPtY-1,stPtX+rectWidth+1,stPtY+rectWidth+1);
         EndXtrd;
         END;
      END;
      For i:=1 TO 4 DO BEGIN
         For k:=1 TO 5 DO BEGIN   
            p:= Trunc(random*3);
            CASE p OF 
               0: ColorIndexToRGB(245,r,g,b);
               1: ColorIndexToRGB(16,r,g,b);
               2: ColorIndexToRGB(35,r,g,b);
            END;
            FillBack(r,g,b);
            PenFore(r,g,b);
            stPtX := ArrayPosH[k]-1/2*rectWidth;
            stPtY := random * (rectHeight-rectWidth);

            BeginXtrd(0,90);
               rect(stPtY-1,stPtX-1,stPtY+rectWidth+1,stPtX+rectWidth+1);
            EndXtrd;
            subtrVol := LNewObj;
            DSelectAll; 
            str := concat('streetHor',k);
            SelectObj(N=str);
            streetSolid := FSActLayer;
            SetName(streetSolid ,'');
            returnVal := SubtractSolid(streetSolid ,subtrVol,divSolid);
            SetName(divSolid,str);
            startZ := random*90-10;
            BeginXtrd(startZ ,startZ + 10);
               rect(stPtY-1,stPtX-1,stPtY+rectWidth+1,stPtX+rectWidth+1);
            EndXtrd;

         END;
      END;

(******* sites *******)
      forcedNumbOfSites :=   numbOfSites;
  
      For h:=1 TO forcedNumbOfSites DO BEGIN

   {*** setting the colours***}
         p1:= Trunc(random*4);

     CASE p1 OF
               0: myColorIndex := 35;
               1: myColorIndex := 245;
               2: myColorIndex := 16;
               3: myColorIndex := 5;
         END;
         ColorIndexToRGB(myColorIndex ,r,g,b);

   {*** stop setting the colours**}


         horsites := Trunc(random*streetsHor) +1;
         versites := Trunc(random*streetsVer) +1;

         tempPt.x := horsites;
         tempPt.y := versites;

         isOccupied := false;
         str:='';
         For i:=2 TO numbOfSites DO BEGIN
            IF EqualPoint(tempPt,selectedSites[i]) THEN BEGIN
               isOccupied:= true;
               forcedNumbOfSites:= forcedNumbOfSites +1;
               str := 'belegt';
            END;
         END;
            message(str);

         IF isOccupied = false THEN BEGIN
            selectedSites[h].x := horsites;
            selectedSites[h].y := versites;
      
            stPtX := ArrayPosV[versites]-1/2*rectWidth;
            stPtY := ArrayPosH[horsites]-1/2*rectWidth;
         
            IF versites = 1 THEN BEGIN
               stPtX1 := 0;
            END
            ELSE BEGIN
               stPtX1 := ArrayPosV[versites -1]+1/2*rectWidth;
            END;
         
            IF horsites = 1 THEN BEGIN
               stPtY1 := 0;
            END
            ELSE BEGIN
               stPtY1 := ArrayPosH[horsites -1]+1/2*rectWidth;
            END;
            drawSite(stPtX1,stPtY1,stPtX,stPtY,myColorIndex );
         END;
      END;   
   ColorIndexToRGB(255,r,g,b);
   PenFore(r,g,b);
   ColorIndexToRGB(0,r,g,b);
   FillPat(0);
   rect(0,0,rectHeight,rectHeight);   
   FillPat(1);
END;
Run(sMondrian);

-- Main.NDSSladjanaMarkovic - 16 Dec 2005

Revision r1.1 - 16 Dec 2005 - 14:59 - NDSSladjanaMarkovic
Parents: WebHome > NDSSladjanaMarkovic > Assignment
Copyright © 1999-2003 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.

This website has been archived and is no longer maintained.