How to create a new Morphic project with code - example 2
Last updated at 11:04 am UTC on 25 July 2022
Example 2
The same example as in example 1 but with a more complex content morph taken from A4 and A3 sheets in Morphic.
| a4 newProject |
a4Extent := 210@ 297 "millimeter".
a4ExtentPrintableArea := 190 @ 277 "millimeter".
scaleFactorForDisplay := 2.
a4ExtentForDisplay := a4Extent * scaleFactorForDisplay.
a4 := Morph new extent: a4ExtentForDisplay.
a4 color: Color lightBlue.
a4PrintableAreaExtentForDisplay := a4ExtentPrintableArea *scaleFactorForDisplay.
a4PrintableArea := Morph new extent: a4PrintableAreaExtentForDisplay.
a4PrintableArea color: Color white.
a4 addMorph: a4PrintableArea.
boxHeight := (a4PrintableArea height) /4.
boxWidth := (a4PrintableArea width) /3.
innerBoxWidth := boxHeight / (2 sqrt).
0 to: 3 do: [:row |
0 to: 2 do: [:col |
box:= Morph new extent: innerBoxWidth@boxHeight; color: Color random; borderWidth: 0.
centerPoint := ((col+0.5) * boxWidth)@((row+0.5) * boxHeight).
box center: centerPoint.
a4PrintableArea addMorph: box ]
].
a4PrintableArea center: a4 center.
a4 position: 20@50.
newProject := MorphicProject new.
newProject name: 'Layout 12 boxes - A4 sheet'.
newProject world addMorph: a4.
newProject showWorldMainDockingBar: false.
newProject world color: Color blue.
ProjectViewMorph openOn: newProject.