#USE "course.lib" PROC fraktal.ascii(CHAN OF BYTE keyboard, screen, err) -- Dimension der Felder VAL INT DIM IS 1000: -- Anzahl der Arbeiter VAL INT WORKERS IS 8: -- Anzahl der Pixel, die ein Worker an den "Admin" -- zurückmeldet VAL INT PKTSIZE IS 5: -- Gleitkommaversion von DIM VAL REAL32 dimension IS REAL32 ROUND DIM: -- Zahl der Iterationen pro Pixel VAL INT maxIt IS 500: INT row: REAL32 minx, maxx, miny, maxy, dx, dy, stepx, stepy : SEQ -- set borders minx := -2.1 maxx := 1.5 miny := -1.1 maxy := 1.1 dx := (maxx - minx) dy := (maxy - miny) stepx := (dx / dimension) stepy := (dy / dimension) -- dummy initialisierung row := -1 --INT row : [WORKERS]CHAN OF INT fromworker : [WORKERS]CHAN OF [3*PKTSIZE]INT topainter : [WORKERS]CHAN OF INT toworker : PAR SEQ row := 0 SEQ i = 0 FOR WORKERS SEQ toworker[i] ! row row := row + 1 WHILE row < DIM INT tmprow: SEQ ALT j = 0 FOR WORKERS fromworker[j] ? tmprow toworker[j] ! row row := row + 1 SEQ i = 0 FOR WORKERS INT tmprow : ALT j = 0 FOR WORKERS fromworker[j] ? tmprow toworker[j] ! (-1) -- XXX SEQ PAR i = 0 FOR WORKERS INT actrow : REAL32 actrowD : REAL32 colD : SEQ toworker[i] ? actrow WHILE actrow > (-1) -- XXX BOOL weiter : REAL32 x, y, tmp, re, im : INT z : [DIM]INT tmprow : INT pktcont : SEQ pktcont := 0 SEQ col = 0 FOR DIM SEQ [3*PKTSIZE]INT pixel : SEQ actrowD := REAL32 ROUND actrow colD := REAL32 ROUND col re := (minx + ( actrowD * stepx)) im := (miny + ( colD * stepy)) -- !!!!!!!!!!!!!!!!!!! --berechne Fraktal-Kram x := 0.0 y := 0.0 z := 0 weiter := TRUE tmp := ((re * re) + ( im * im)) WHILE weiter AND ( tmp < 4.0) SEQ z := z + 1 tmp := x x := (((x * x) - ( y * y)) + re) y := (((2.0 * tmp) * y) + im) tmp := ((x * x) + ( y * y)) IF z = maxIt weiter := FALSE TRUE SKIP tmprow[col] := z pixel[(pktcont*3)+0] := actrow pixel[(pktcont*3)+1] := col pixel[(pktcont*3)+2] := z pktcont := pktcont + 1 IF pktcont = PKTSIZE SEQ pktcont := 0 topainter[i] ! pixel TRUE SKIP fromworker[i] ! actrow toworker[i] ? actrow INT pixcnt : [DIM][DIM]INT picture : SEQ pixcnt := DIM * DIM WHILE pixcnt > 0 SEQ [3*PKTSIZE]INT pixel : ALT i = 0 FOR WORKERS topainter[i] ? pixel SEQ k = 0 FOR PKTSIZE picture[pixel[(k*3)+1]][pixel[(k*3)]] := pixel[(k*3)+2] pixcnt := pixcnt - PKTSIZE -- ausgeben des Fraktal in .PPM-Format out.string("P3*n", 0, screen) out.int(DIM, 0, screen) out.string(" ", 0, screen) out.int(DIM, 0, screen) out.string("*n", 0, screen) out.string("255*n", 0, screen) SEQ i = 0 FOR DIM SEQ SEQ j = 0 FOR DIM SEQ -- R = G = B out.int(picture[i][j], 0, screen) out.string(" ", 0, screen) out.int(picture[i][j], 0, screen) out.string(" ", 0, screen) out.int(picture[i][j], 0, screen) out.string(" ", 0, screen) out.string("*n", 0, screen) :