Skip to content

Instantly share code, notes, and snippets.

View Chadtech's full-sized avatar

Chadtech Chadtech

  • SuperFocus.ai
  • Pennsylvania
View GitHub Profile
main = document.getElementById 'main'
app = Elm.embed Elm.Main, main
backEnd = (msg) ->
# ...
{submitEmail, updateEmail} = app.ports
email = "ye"
fs = require 'fs'
express = require 'express'
app = express()
http = require 'http'
{join} = require 'path'
bodyParser = require 'body-parser'
app.use bodyParser.json()
PORT = Number process.env.PORT or 2998
req = require 'request'
cheerio = require 'cheerio'
_ = require 'lodash'
tweeter = process.argv[2]
req 'https://www.twitter.com/' + tweeter, (error, res, html) ->
if (not error) and (res.statusCode is 200)
twitterDotCom = cheerio.load html
tweets = twitterDotCom '.tweet-text'
start = (fps_) ->
fps = 1000 / fps_
prev = Date.now()
startTime = prev
step()
step = ->
window.requestAnimationFrame step
draw()
now = Date.now()
replaceColumn : Int -> Sector -> List Sector -> List Sector
replaceColumn i s r =
append
(take i r)
(s ::
(default
(repeat (100 - i) (Sector []))
(tail (drop i r))))
replaceRow : Int -> List Sector -> List (List Sector) -> List (List Sector)

Im making a video game about a space ship flying in space. In most video games, developers have to work on whats called 'collision detection'. The things in your game are just floating surfaces, and to make them appear solid you need code that detects when these floating surfaces touch or overlap. This way, the game can have true objects that dont simply pass through each other.

Another thing about video game development, is that time isnt really continous. Games progress along a frame rate, or a quick succession of states, just like a video being a sequence of still pictures.

There is a difficulty associated with detecting collisions among objects that exist in discrete (non-continuous) time. I cant simply ask if two objects touch at any given time, but I also have to ask, would they have touched in between the discrete moments in time. To illustrate this, consider a video game about a person shooting a gun at another person. If you just asked 'is the bullet touching the target?', the answer would likely b

In one of my more recent projects, I made a native Elm module, which means I had to follow the Elm programming language all the way to its compiled JavaScript form. It was fun! And I learned a few things about Elm. One bit I thought Id share here is how Elm transpiles its List and Array data types to JavaScript.

In JavaScript, there is only the Array type and not the List type, and the Array type is pretty flexible. In Elm, the Array type isnt so flexible; Elm Arrays are typed (so all there elements have to be the same type), and its a little more difficult to get and set array values. The List type in Elm is even more basic. Elm lists dont really have indices like Arrays; you cant get or set indices in Elm Lists. The closest thing to getting and setting elements from Elm Lists, is appending or removing the first element of an Elm list. So for example, its very easy to convert the Elm list [ 1, 2, 3 ] into [ 0, 1, 2, 3 ] or [ 2, 3 ], but difficult to convert [ 1, 2, 3 ] into [ 1, 3 ] or [ 1, 4, 3 ].

Elm Li

bresenhamLine : Coordinate -> Coordinate -> List Coordinate
bresenhamLine (x0, y0) (x1, y1) =
let
dx = (toFloat << abs) (x1 - x0)
sx = if x0 < x1 then 1 else -1
dy = (toFloat << abs) (y1 - y0)
sy = if y0 < y1 then 1 else -1
error = if dx > dy then dx else -dy
in
type BrensemhamStatics = Statics (Int, Int) (Float, Float) Coordinate
bresenhamLine : Coordinate -> Coordinate -> List Coordinate
bresenhamLine (x0, y0) (x1, y1) =
let
dx = (toFloat << abs) (x1 - x0)
sx = if x0 < x1 then 1 else -1
dy = (toFloat << abs) (y1 - y0)
sy = if y0 < y1 then 1 else -1
import Html exposing (p, text, div, canvas, Html)
import Html.Attributes exposing (id, style)
import Html.Events exposing (..)
import List exposing (repeat, concat)
import Array exposing (Array, fromList)
import Color exposing (rgb, Color)
import Debug exposing (log)
main =