Skip to content

Instantly share code, notes, and snippets.

@gingerbeardman
Created August 7, 2020 23:23
Show Gist options
  • Save gingerbeardman/a0a0b967c480ab973d40aaf5e78fd47f to your computer and use it in GitHub Desktop.
Save gingerbeardman/a0a0b967c480ab973d40aaf5e78fd47f to your computer and use it in GitHub Desktop.
// animate X,X,32
// sprite
$vpr = [45,0,180-$t*360];
$vpt = [0,0,100];
$vpd = 9000; // non-retina
s = 30;
h = s/2;
d = s*2;
w = h*4.5;
body = "#777"; // 999
dark = "#333"; // 555
trim = "#fff";
black = "#000";
white = "#fff";
rr = 0;
rl = 0;
translate([-h,-d,0])
car();
//beams();
points=[
[6,63],
[14,10],
[30,0],
[30,-18],
[17,-27],
[17,-64],
[0,-64],
[-17,-64],
[-17,-27],
[-30,-18],
[-30,0],
[-14,10],
[-6,63],
];
module formula() {
difference() {
// body
color(body)
translate([0, 0, 5])
linear_extrude(height = 25, convexity = 2) {
polygon(points);
}
// body angle
color(body)
translate([0, 0, 40])
rotate([-5.5,0,0])
cube([70,140,30], center = true);
// rear angle
color(body)
translate([0, -76, 15])
rotate([10,0,0])
cube([70,30,30], center = true);
}
// nose
color(black)
translate([0, 61.1, 12])
rotate([90,0,0])
cube([13.2,14.5,4], center = true);
// spoiler
color(black)
translate([0, -60, 30])
rotate([0,0,0])
cube([33.99,7,0.5], center = true);
// foil
*color(body)
translate([0, -40, 20])
rotate([7,0,0])
cube([20,38,20], center = true);
// exhausts
hull() {
color(white)
translate([-9, -60, 17])
rotate([90,0,0])
cylinder(5,4,4);
color(white)
translate([9, -60, 17])
rotate([90,0,0])
cylinder(5,4,4);
}
// windscreen
color(black)
translate([0, -9.5, 25])
sphere(12, $fn = 64);
}
module car() {
// body
rotate([0,-4*rr+4*rl,0])
translate([h,d,2])
formula();
// axle front
color(black)
rotate([0,90,0])
translate([-15,105,-10])
cylinder(50,3,3);
// axle rear
color(black)
rotate([0,90,0])
translate([-15,15,-10])
cylinder(50,3,3);
// rear wheels
translate([s*0.84, h, h])
wheel();
translate([-s*0.84, h, h])
wheel();
// front wheels
if (rl == 1) {
translate([s*0.84, s*3.5, h])
translate([4,-7,0])
rotate([0,0,30])
wheel();
}
if (rr == 1) {
translate([s*0.84, s*3.5, h])
translate([4,9,0])
rotate([0,0,-35])
wheel();
}
if (!rr && !rl) {
translate([s*0.84, s*3.5, h])
wheel();
}
if (rl == 1) {
translate([-s*0.84, s*3.5, h])
translate([0,-8,0])
rotate([0,0,35])
wheel();
}
if (rr == 1) {
translate([-s*0.84, s*3.5, h])
translate([0,7,0])
rotate([0,0,-30])
wheel();
}
if (!rr && !rl) {
translate([-s*0.84, s*3.5, h])
wheel();
}
}
module wheel() {
difference() {
// tyre
translate([s/3,0,0])
color("#000")
rotate([0,90,0])
cylinder(s/3,h*1.25,h*1.25);
// tyre hole
color("#FFF")
translate([h/2,0,0])
rotate([0,90,0])
cylinder(h,s/3,s/3);
}
// hub cap
color("#FFF")
translate([h*0.75,0,0])
rotate([0,90,0])
cylinder(h/2,s/3,s/3);
}
module shadow() {
translate([-h*1.2,-h*1.25,-3.5])
color("#000")
square([d*1.1,d*2.6],0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment