{"id":38918562,"url":"https://github.com/demouth/ebiten-chipmunk","last_synced_at":"2026-01-17T15:30:41.163Z","repository":{"id":252715492,"uuid":"840546392","full_name":"demouth/ebiten-chipmunk","owner":"demouth","description":"ebiten-chipmunk is an implementation of the cp.Drawer interface of jakecoffman/cp/v2 using Ebitengine.","archived":false,"fork":false,"pushed_at":"2024-09-20T00:13:26.000Z","size":342,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-09-20T06:48:20.995Z","etag":null,"topics":["chipmunk2d","ebitengine","physics"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/demouth.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-10T01:15:24.000Z","updated_at":"2024-09-20T00:06:17.000Z","dependencies_parsed_at":"2024-09-12T11:51:56.932Z","dependency_job_id":null,"html_url":"https://github.com/demouth/ebiten-chipmunk","commit_stats":null,"previous_names":["demouth/ebiten-chipmunk","demouth/ebitencp"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/demouth/ebiten-chipmunk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/demouth%2Febiten-chipmunk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/demouth%2Febiten-chipmunk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/demouth%2Febiten-chipmunk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/demouth%2Febiten-chipmunk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/demouth","download_url":"https://codeload.github.com/demouth/ebiten-chipmunk/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/demouth%2Febiten-chipmunk/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28511496,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T13:38:16.342Z","status":"ssl_error","status_checked_at":"2026-01-17T13:37:44.060Z","response_time":85,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chipmunk2d","ebitengine","physics"],"created_at":"2026-01-17T15:30:41.031Z","updated_at":"2026-01-17T15:30:41.130Z","avatar_url":"https://github.com/demouth.png","language":"Go","readme":"# ebiten-chipmunk\n\n**ebiten-chipmunk** is an implementation of the `cp.Drawer` interface from [jakecoffman/cp/v2](https://github.com/jakecoffman/cp). This implementation utilizes [hajimehoshi/ebiten/v2](https://github.com/hajimehoshi/ebiten), making it possible to run across multiple platforms.\n\n![demo](images/demo.gif)\n\n## Usage\n\nWithin your `Draw()` method, invoke the `cp.DrawSpace()` function, passing in both a `*cp.Space` and a `*ebitencp.Drawer` as parameters.\n\n```go\ntype Game struct {\n\tspace  *cp.Space\n\tdrawer *ebitencp.Drawer\n}\nfunc main() {\n    // ...\n\tgame := \u0026Game{}\n\tgame.space = space\n\tgame.drawer = ebitencp.NewDrawer(screenWidth, screenHeight)\n    // ...\n}\nfunc (g *Game) Draw(screen *ebiten.Image) {\n\t// Drawing with Ebitengine/v2\n\tcp.DrawSpace(g.space, g.drawer.WithScreen(screen))\n}\n```\n\nIf you want to enable dragging, call the `HandleMouseEvent()` function within the `Update` method, passing the `*cp.Space` object. This will allow objects to be dragged using a mouse or touch device.\n\n```go\nfunc (g *Game) Update() error {\n\t// Handling dragging\n\tg.drawer.HandleMouseEvent(g.space)\n\tg.space.Step(1 / 60.0)\n\treturn nil\n}\n```\n\nBelow is a simple example that demonstrates the implementation in action.\n\n```go\npackage main\n\nimport (\n\t_ \"image/png\"\n\t\"log\"\n\n\t\"github.com/demouth/ebitencp\"\n\t\"github.com/hajimehoshi/ebiten/v2\"\n\n\t\"github.com/jakecoffman/cp/v2\"\n)\n\nconst (\n\tscreenWidth   = 640\n\tscreenHeight  = 480\n\thScreenWidth  = screenWidth / 2\n\thScreenHeight = screenHeight / 2\n)\n\ntype Game struct {\n\tspace  *cp.Space\n\tdrawer *ebitencp.Drawer\n}\n\nfunc (g *Game) Update() error {\n\t// Handling dragging\n\tg.drawer.HandleMouseEvent(g.space)\n\tg.space.Step(1 / 60.0)\n\treturn nil\n}\n\nfunc (g *Game) Draw(screen *ebiten.Image) {\n\t// Drawing with Ebitengine/v2\n\tg.drawer.Screen = screen\n\tcp.DrawSpace(g.space, g.drawer)\n}\n\nfunc (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {\n\treturn screenWidth, screenHeight\n}\n\nfunc main() {\n\t// Initialising Chipmunk\n\tspace := cp.NewSpace()\n\tspace.SleepTimeThreshold = 0.5\n\tspace.SetGravity(cp.Vector{X: 0, Y: -100})\n\twalls := []cp.Vector{\n\t\t{X: -hScreenWidth, Y: -hScreenHeight}, {X: -hScreenWidth, Y: hScreenHeight},\n\t\t{X: hScreenWidth, Y: -hScreenHeight}, {X: hScreenWidth, Y: hScreenHeight},\n\t\t{X: -hScreenWidth, Y: -hScreenHeight}, {X: hScreenWidth, Y: -hScreenHeight},\n\t\t{X: -hScreenWidth, Y: hScreenHeight}, {X: hScreenWidth, Y: hScreenHeight},\n\t\t{X: -100, Y: -100}, {X: 100, Y: -80},\n\t}\n\tfor i := 0; i \u003c len(walls)-1; i += 2 {\n\t\tshape := space.AddShape(cp.NewSegment(space.StaticBody, walls[i], walls[i+1], 0))\n\t\tshape.SetElasticity(0.5)\n\t\tshape.SetFriction(0.5)\n\t}\n\taddBall(space, 0, 0, 50)\n\taddBall(space, 0, 100, 20)\n\n\t// Initialising Ebitengine/v2\n\tgame := \u0026Game{}\n\tgame.space = space\n\tgame.drawer = ebitencp.NewDrawer(screenWidth, screenHeight)\n\tebiten.SetWindowSize(screenWidth, screenHeight)\n\tebiten.SetWindowTitle(\"ebiten-chipmunk - ball\")\n\tif err := ebiten.RunGame(game); err != nil {\n\t\tlog.Fatal(err)\n\t}\n}\n\nfunc addBall(space *cp.Space, x, y, radius float64) {\n\tmass := radius * radius / 100.0\n\tbody := space.AddBody(cp.NewBody(mass, cp.MomentForCircle(mass, 0, radius, cp.Vector{})))\n\tbody.SetPosition(cp.Vector{X: x, Y: y})\n\tshape := space.AddShape(cp.NewCircle(body, radius, cp.Vector{}))\n\tshape.SetElasticity(0.5)\n\tshape.SetFriction(0.5)\n}\n```\n\nAdditional examples can be found in the [examples/](examples/) directory. These examples can help you adapt the implementation to your own projects.\n\n## Using Ebitengine\n\nYou can correct the coordinate system by setting FlipYAxis to true.\n\nExample:\n\n```diff go\n  func main() {\n\t// ...\n  \tgame.drawer = ebitencp.NewDrawer(screenWidth, screenHeight)\n+ \tgame.drawer.FlipYAxis = true\n+\t// Set the camera offset to the center of the screen\n+\tdrawer.GeoM.Translate(-screenWidth/2, -screenHeight/2)\n\t// ...\n  }\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdemouth%2Febiten-chipmunk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdemouth%2Febiten-chipmunk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdemouth%2Febiten-chipmunk/lists"}