+
Skip to content

feat: Add username and date range text to model #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var (
buildingWidth float64
buildingLength float64
interval string
font string
openscadPath string
showVersion bool
showVersionRaw bool
Expand All @@ -47,14 +48,15 @@ func init() {
flag.StringVarP(&outputFile, "output", "o", "skyline.scad", "Output file (.scad and .stl are supported, but stl requires 'openscad')")
flag.IntVarP(&startYear, "start", "b", 0, "Start year")
flag.IntVarP(&endYear, "end", "e", 0, "End year")
flag.StringVarP(&aspectRatio, "aspect-ratio", "a", "16:9", "Aspect ratio of the skyline")
flag.StringVarP(&aspectRatio, "aspect-ratio", "a", "16:4", "Aspect ratio of the skyline")
flag.Float64VarP(&baseAngle, "base-angle", "A", 22.5, "Slope of the base walls in degrees")
flag.Float64VarP(&baseHeight, "base-height", "h", 5.0, "Height of the base (mm)")
flag.Float64VarP(&baseMargin, "base-margin", "g", 1.0, "Distance from the buildings to the base walls (mm)")
flag.Float64VarP(&maxBuildingHeight, "max-building-height", "m", 20.0, "Max building height (mm)")
flag.Float64VarP(&buildingWidth, "building-width", "w", 2.0, "Building width (mm)")
flag.Float64VarP(&buildingLength, "building-length", "l", 2.0, "Building length (mm)")
flag.StringVarP(&interval, "interval", "i", "week", "Interval to use for contributions (day, week)")
flag.StringVarP(&font, "font", "F", "Liberation Sans:style=Bold", "Font to use for text")
flag.StringVarP(&openscadPath, "openscad", "O", "openscad", "Path to the OpenSCAD executable")
flag.BoolVarP(&showVersion, "version", "V", false, "Show version")
flag.BoolVar(&showVersionRaw, "version-raw", false, "Show version (raw)")
Expand Down Expand Up @@ -127,7 +129,7 @@ func main() {
fmt.Printf("Total contributions: %d between %v and %v\n", contribs.TotalContributions, contribs.FirstDate, contribs.LastDate)

fmt.Printf("Generating OpenSCAD ...\n")
sg := skyline.NewSkylineGenerator(*contribs, aspectRatioInts, maxBuildingHeight, buildingWidth, buildingLength)
sg := skyline.NewSkylineGenerator(*contribs, aspectRatioInts, maxBuildingHeight, buildingWidth, buildingLength, font)
sl := sg.Generate(interval)
sl.BaseAngle = baseAngle
sl.BaseHeight = baseHeight
Expand Down
36 changes: 35 additions & 1 deletion pkg/skyline/cad.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type SkylineGenerator struct {
maxHeight float64
buildingWidth float64
buildingLength float64
font string
}

type Building struct {
Expand Down Expand Up @@ -60,6 +61,9 @@ type Skyline struct {
BaseMargin float64
BaseHeight float64
BaseAngle float64
Font string
TextLeft string
TextRight string
}

// NewSkylineGenerator creates a new SkylineGenerator
Expand All @@ -68,13 +72,14 @@ type Skyline struct {
// maxHeight: the maximum height of the buildings in mm
// buildingWidth: the width of the buildings in mm
// buildingLength: the length of the buildings in mm
func NewSkylineGenerator(Contributions Contributions, aspectRatio [2]int, maxHeight, buildingWidth, buildingLength float64) *SkylineGenerator {
func NewSkylineGenerator(Contributions Contributions, aspectRatio [2]int, maxHeight, buildingWidth, buildingLength float64, font string) *SkylineGenerator {
sg := &SkylineGenerator{
contributions: Contributions,
aspectRatio: float64(aspectRatio[0]) / float64(aspectRatio[1]),
maxHeight: maxHeight,
buildingWidth: buildingWidth,
buildingLength: buildingLength,
font: font,
}

return sg
Expand Down Expand Up @@ -110,6 +115,9 @@ func (sg *SkylineGenerator) Generate(interval string) *Skyline {
BaseMargin: defaultBaseMargin,
BaseHeight: defaultBaseHeight,
BaseAngle: defaultBaseAngle,
Font: sg.font,
TextLeft: "@" + sg.contributions.Username,
TextRight: sg.contributions.YearRangeText(),
}

return skyline
Expand Down Expand Up @@ -212,6 +220,24 @@ var (

color(baseColor)
polyhedron(points, faces);

if (textEnable) {
textOffset = baseOffset+baseMargin;
textSize = baseHeight-baseMargin;

rotate([90-baseAngle, 0 ,0])
translate([textOffset, 1, 0])
color("red")
linear_extrude(textHeight)
text(textLeft, size=textSize, halign="left", valign="baseline", font=textFont)
;

rotate([90-baseAngle, 0 ,0])
translate([bottomWidth-textOffset, 1, 0])
color("red")
linear_extrude(textHeight)
text(textRight, size=textSize, halign="right", valign="baseline", font=textFont);
}
}`

buildingModule = `module building(x, y, contributions) {
Expand Down Expand Up @@ -243,6 +269,14 @@ func (sl *Skyline) ToOpenSCAD(filename string) (time.Duration, error) {
fmt.Fprintf(out, "baseOffset = baseHeight * tan(baseAngle);\n")
fmt.Fprintf(out, `baseColor = "cyan";`+"\n")

fmt.Fprintf(out, "\n// Base Text\n")
fmt.Fprintf(out, "textEnable = true;\n")
fmt.Fprintf(out, "textFont = %q;\n", sl.Font)
fmt.Fprintf(out, "textLeft = %q;\n", sl.TextLeft)
fmt.Fprintf(out, "textRight = %q;\n", sl.TextRight)
fmt.Fprintf(out, `textColor = "red";`+"\n")
fmt.Fprintf(out, "textHeight = 0.4;\n")

fmt.Fprintf(out, "\n// Building Parameters\n")
fmt.Fprintf(out, "buildingWidth = %f;\n", sl.BuildingWidth)
fmt.Fprintf(out, "buildingLength = %f;\n", sl.BuildingLength)
Expand Down
15 changes: 14 additions & 1 deletion pkg/skyline/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,24 @@ func (sc StatsCollection) Max() int {
}

type Contributions struct {
Username string `json:"username"`
TotalContributions int `json:"total_contributions"`
FirstDate string `json:"first_date"`
LastDate string `json:"last_date"`
ByDate map[string]int `json:"by_date"`
}

func (c *Contributions) YearRangeText() string {
startYear := c.FirstDate[:4]
endYear := c.LastDate[:4]

if startYear == endYear {
return startYear
}

return fmt.Sprintf("%s-%s", startYear, endYear)
}

func (c *Contributions) PerDay() StatsCollection {
dayKeys := make([]string, 0, len(c.ByDate))
for key := range c.ByDate {
Expand Down Expand Up @@ -170,7 +182,8 @@ type DateTime struct{ time.Time }
func (gcf *GitHubContributionsFetcher) FetchContributions(startYear, endYear int) (*Contributions, error) {

contrib := &Contributions{
ByDate: make(map[string]int),
Username: gcf.username,
ByDate: make(map[string]int),
}

var firstDate time.Time
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载